| 1 | package Message::Passing::Output::Fluentd; | ||
| 2 | |||
| 3 | use Moo; | ||
| 4 | use namespace::autoclean; | ||
| 5 | use Try::Tiny; | ||
| 6 | use JSON::MaybeXS qw( decode_json ); | ||
| 7 | use Message::Passing::Exception::Decoding; | ||
| 8 | |||
| 9 | with qw( | ||
| 10 | Message::Passing::Fluentd::Role::HasAConnection | ||
| 11 | Message::Passing::Role::Output | ||
| 12 | ); | ||
| 13 | |||
| 14 | has tag => ( is => 'ro', default => sub { 'app_log' }); | ||
| 15 | |||
| 16 | sub consume { | ||
| 17 | my ($self, $msg) = @_; | ||
| 18 | $msg = try { | ||
| 19 | ref($msg) ? $msg : decode_json($msg) | ||
| 20 | } catch { | ||
| 21 | $self->error->consume(Message::Passing::Exception::Decoding->new( | ||
| 22 | exception => $_, | ||
| 23 | packed_data => $msg, | ||
| 24 | )); | ||
| 25 | return; # Explicit return undef | ||
| 26 | }; | ||
| 27 | $self->connection_manager->connection->post( | ||
| 28 | delete($msg->{'tag'}) || $self->tag, | ||
| 29 | $msg | ||
| 30 | ); | ||
| 31 | } | ||
| 32 | |||
| 33 | sub connected {} | ||
| 34 | |||
| 35 | 1; | ||
| 36 | |||
| 37 | __END__ |