Better routing clean up. Now requires explicit message handling

This commit is contained in:
Bruno Tavares
2014-09-09 11:52:56 +01:00
parent 78c4ca959f
commit 24b1335000
3 changed files with 19 additions and 18 deletions

View File

@@ -18,9 +18,6 @@ usage("topic and channel are required parameters") unless $topic and $channel;
my $cv = AE::cv;
## return undef => mark_as_done_msg()
my $message_cb = $print ? sub { print "$_[1]{message}\n"; return } : sub {return};
my $t = my $p = 0;
my $r = AnyEvent::NSQ::Reader->new(
topic => $topic,
@@ -28,7 +25,7 @@ my $r = AnyEvent::NSQ::Reader->new(
nsqd_tcp_addresses => '127.0.0.1',
client_id => "${channel}_consumer/pid_$$",
message_cb => sub { $t++; $p++; $message_cb->(@_) },
message_cb => \&message_handler,
error_cb => sub { warn "$_[1]\n" if $verbose },
disconnect_cb => sub { warn "Disconnected after $t total messages... exiting...\n" if $verbose; $cv->send },
@@ -85,3 +82,14 @@ Usage: consumer.pl [--help|-h] [--print|-p] topic channel
exit(1);
}
sub message_handler {
use Data::Dumper;
my ($reader, $message) = @_;
if ($print) {
print $message->{message}."\n";
}
$reader->mark_as_done_msg($message);
}