NAME
Mercury::Controller::PubSub::Cascade - Pub/sub controller with a topic heirarchy and cascading
VERSION
version 0.016
SYNOPSIS
# myapp.pl
use Mojolicious::Lite;
plugin 'Mercury';
websocket( '/pub/*topic' )
->to( controller => 'PubSub::Cascade', action => 'pub' );
websocket( '/sub/*topic' )
->to( controller => 'PubSub::Cascade', action => 'sub' );
DESCRIPTION
This controller enables a pub/sub pattern on a pair of endpoints (publish and subscribe.
In this variant, topics are organized into a heirarchy. Subscribers can subscribe to higher branch of the tree to recieve messages from all the publishers on lower branches of the tree. So, a subscriber to /foo
will receive messages sent to /foo
, /foo/bar
, and /foo/bar/baz
.
For more information on the pub/sub pattern, see Mercury::Pattern::PubSub.
METHODS
publish
$app->routes->websocket( '/pub/*topic' )
->to( controller => 'PubSub::Cascade', 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 for the topic and all parent topics.
This endpoint requires a topic
in the stash.
subscribe
$app->routes->websocket( '/sub/*topic' )
->to( controller => 'PubSub::Cascade', action => 'subscribe' );
Controller action to connect a websocket as a subscriber. A subscriber will recieve every message sent by publishers to the current topic and any child topics.
This endpoint requires a topic
in the stash.
post
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.
SEE ALSO
AUTHOR
Doug Bell <preaction@cpan.org>
COPYRIGHT AND LICENSE
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.