Mercury::Pattern::PushPull - Manage a push/pull pattern for a single topic
version 0.010
# Connect the pusher my $push_ua = Mojo::UserAgent->new; my $push_tx = $ua->websocket( '/push/foo' ); # Connect the puller socket my $pull_ua = Mojo::UserAgent->new; my $pull_tx = $ua->websocket( '/pull/foo' ); # Connect the two sockets using push/pull my $pattern = Mercury::Pattern::PushPull->new; $pattern->add_pusher( $push_tx ); $pattern->add_puller( $pull_tx ); # Send a message $pull_tx->on( message => sub { my ( $tx, $msg ) = @_; print $msg; # Hello, World! } ); $push_tx->send( 'Hello, World!' );
This pattern connects pushers, which send messages, to pullers, which recieve messages. Each message sent by a pusher will be received by a single puller. This pattern is useful for dealing out jobs to workers.
Connected websockets ready to receive messages.
Connected websockets who will be pushing messages.
The puller we will use to send the next message from a pusher.
$pat->add_puller( $tx );
Add a puller to this broker. Pullers are given messages in a round-robin, one at a time, by pushers.
$pat->add_pusher( $tx );
Add a pusher to this broker. Pushers send messages to be processed by pullers.
$pat->send_message( $msg );
Send the given message to the next puller in line.
$pat->remove_puller( $tx );
Remove a puller from the list. Called automatically when the puller socket is closed.
$pat->remove_pusher( $tx );
Remove a pusher from the list. Called automatically when the pusher socket is closed.
Doug Bell <preaction@cpan.org>
This software is copyright (c) 2016 by Doug Bell.
This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.
To install Mercury, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Mercury
CPAN shell
perl -MCPAN -e shell install Mercury
For more information on module installation, please visit the detailed CPAN module installation guide.