Files
perl-anyevent-nsq/lib/AnyEvent/NSQ/Writer.pm
Pedro Melo a9d7134082 Add publish() to Write
Signed-off-by: Pedro Melo <melo@simplicidade.org>
2014-07-20 22:13:50 +01:00

31 lines
555 B
Perl

package AnyEvent::NSQ::Writer;
# ABSTRACT: a NSQ.io asynchronous producer
# VERSION
# AUTHORITY
use strict;
use warnings;
use Carp 'croak';
use parent 'AnyEvent::NSQ::Client';
#### Producer API
## Publish a single message - callback is only called if we succedd
sub publish {
my ($self, $topic, $data, $cb) = @_;
my $conn = $self->_random_connected_conn;
croak "ERROR: there no active connections at this moment," unless $conn;
$cb = sub { $cb->($self, $topic, $data, @_) }
if $cb;
return $conn->publish($topic, $data, $cb);
}
1;