NAME

Mercury::Controller::PubSub - Pub/sub message pattern controller

VERSION

version 0.016

SYNOPSIS

# myapp.pl
use Mojolicious::Lite;
plugin 'Mercury';
websocket( '/pub/*topic' )
  ->to( controller => 'PubSub', action => 'pub' );
websocket( '/sub/*topic' )
  ->to( controller => 'PubSub', action => 'sub' );

DESCRIPTION

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.

METHODS

publish

$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.

subscribe

$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.

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

Mercury::Pattern::PubSub
Mercury::Controller::PubSub::Cascade
Mercury

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.