Mercury::Controller::PubSub - Pub/sub message pattern controller
version 0.016
# myapp.pl use Mojolicious::Lite; plugin 'Mercury'; websocket( '/pub/*topic' ) ->to( controller => 'PubSub', action => 'pub' ); websocket( '/sub/*topic' ) ->to( controller => 'PubSub', action => 'sub' );
This controller enables a pub/sub pattern on a pair of endpoints (publish and subscribe.
For more information on the pub/sub pattern, see Mercury::Pattern::PubSub.
$app->routes->websocket( '/pub/*topic' ) ->to( controller => 'PubSub', action => 'publish' );
Controller action to connect a websocket as a publisher. A publish client sends messages through the socket. The message will be sent to all of the connected subscribers.
This endpoint requires a topic in the stash.
topic
$app->routes->websocket( '/sub/*topic' ) ->to( controller => 'PubSub', action => 'subscribe' );
Controller action to connect a websocket as a subscriber. A subscriber will recieve every message sent by publishers.
Post a new message to the given topic without subscribing or establishing a WebSocket connection. This allows new messages to be pushed by any HTTP client.
Doug Bell <preaction@cpan.org>
This software is copyright (c) 2018 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.