[libmessage-passing-zeromq-perl] 53/78: Allow SUB sockets to subscribe to a subset of possible messages
Jonas Smedegaard
js at alioth.debian.org
Mon Sep 30 09:28:26 UTC 2013
This is an automated email from the git hooks/post-receive script.
js pushed a commit to branch master
in repository libmessage-passing-zeromq-perl.
commit 7b8257167fc402d15ab2f9ac17e66027a488f975
Author: Tomas Doran <bobtfish at bobtfish.net>
Date: Sun Jun 10 18:20:53 2012 +0100
Allow SUB sockets to subscribe to a subset of possible messages
---
Changes | 2 ++
Makefile.PL | 2 +-
lib/Message/Passing/Input/ZeroMQ.pm | 21 ++++++++++++++++++++-
3 files changed, 23 insertions(+), 2 deletions(-)
diff --git a/Changes b/Changes
index fbf80ac..84e1477 100644
--- a/Changes
+++ b/Changes
@@ -1,3 +1,5 @@
+ - Allow SUB sockets to subscribe to a subset of possible messages.
+
0.005
- Improve documentation.
diff --git a/Makefile.PL b/Makefile.PL
index afb829d..5a08155 100644
--- a/Makefile.PL
+++ b/Makefile.PL
@@ -19,7 +19,7 @@ requires 'AnyEvent';
requires 'ZeroMQ' => '0.21';
requires 'Try::Tiny';
requires 'Task::Weaken';
-requires 'Message::Passing' => '0.006';
+requires 'Message::Passing' => '0.008';
requires 'POSIX::AtFork' => '0.02';
requires 'Sub::Name';
diff --git a/lib/Message/Passing/Input/ZeroMQ.pm b/lib/Message/Passing/Input/ZeroMQ.pm
index df01350..e6c5561 100644
--- a/lib/Message/Passing/Input/ZeroMQ.pm
+++ b/lib/Message/Passing/Input/ZeroMQ.pm
@@ -4,6 +4,7 @@ use ZeroMQ qw/:all/;
use AnyEvent;
use Scalar::Util qw/ weaken /;
use Try::Tiny qw/ try catch /;
+use Message::Passing::Types qw/ ArrayOfStr /;
use namespace::autoclean;
with qw/
@@ -21,9 +22,20 @@ sub _socket_type { 'SUB' }
sub _build_socket_hwm { 100000 }
+has subscribe => (
+ isa => ArrayOfStr,
+ is => 'ro',
+ coerce => 1,
+ default => sub { [ '' ] }, # Subscribe to everything!
+);
+
after setsockopt => sub {
my ($self, $socket) = @_;
- $socket->setsockopt(ZMQ_SUBSCRIBE, '');
+ if ($self->socket_type eq 'SUB') {
+ foreach my $sub (@{ $self->subscribe }) {
+ $socket->setsockopt(ZMQ_SUBSCRIBE, $sub);
+ }
+ }
};
sub _try_rx {
@@ -90,6 +102,13 @@ an input with L<Message::Passing::DSL>.
See L<Message::Passing::ZeroMQ/CONNECTION ATTRIBUTES>
+=head2 subscribe
+
+If the input socket is a C<SUB> socket, then the C<ZMQ_SUBSCRIBE>
+socket option will be set once for each value in the subscribe attribute.
+
+Defaults to '', which means all messages are subscribed to.
+
=head1 SEE ALSO
=over
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-perl/packages/libmessage-passing-zeromq-perl.git
More information about the Pkg-perl-cvs-commits
mailing list