- SEE ALSO
- COPYRIGHT AND LICENSE
Mojolicious::Plugin::Mercury - Plugin for Mojolicious to add Mercury functionality
# myapp.pl use Mojolicious::Lite; plugin 'Mercury';
After adding the plugin, you can add basic messaging patterns by using the Mercury controllers, or you can mix and match your patterns using the Mercury::Pattern classes.
Controllers handle establishing the websocket connections and giving them to the right Pattern object, and the Pattern object handles passing messages between the connected sockets. Controllers can create multiple instances of a single Pattern to isolate messages to a single topic.
NOTE: You should read the DESCRIPTION section of the main Mercury broker documentation before reading further.
Controllers are Mojolicious::Controller subclasses with route handlers to establish websocket connections and add them to a Pattern. The built-in Controllers each handle one pattern, but you can add one socket to multiple Patterns to customize your message passing.
NOTE: Since Mercury does not yet have a way for brokers to share messages, you must run Mercury as a single process. You cannot run Mercury under Hypnotoad like other Mojolicious applications, nor
prefork or other multi-processing schemes. See https://github.com/preaction/Mercury/issues/35 to track the clustering feature.
The built-in controllers are:
Establish a Pub/Sub pattern on a topic. Pub/Sub allows publishers to publish messages that will be received by all subscribers, useful for event notifications.
Establish a Pub/Sub pattern on a topic in a heirarchy, with subscribers to parent topics receiving messages sent to child topics. More efficient when dealing with large numbers of topics.
Establish a Push/Pull pattern on a topic. Push/Pull allows publishers to publish messages that will be received by one and only one subscriber in a round-robin fashion, useful for job workers
Establish a message bus pattern on a topic. The message bus shares all messages sent by connected clients with all other clients, useful for chat and games, and sharing state changes between peers.
The Pattern objects handle transmission of messages on a single topic. Pattern objects take in Mojo::Transaction::WebSocket objects (gotten by the controller using
$c->tx inside a
The built-in patterns are:
A pub/sub pattern has each message sent by a publisher delivered to all connected subscribers. This pattern is useful for event notifications.
A push/pull pattern has each message sent by a pusher delivered to one and only one puller. This pattern is useful for job workers.
A bus pattern has each message sent by a client received by all other connected clients. This pattern is useful for chat, and is similar to combining the publish and subscribe sides of PubSub into a single connection.
my $pattern = $c->mercury->pattern( PushPull => $topic ); $c->mercury->pattern( PushPull => $topic => $pattern );
Accessor for the pattern repository. Pattern objects track a single topic and are registered by a namespace (likely the pattern type).
Register the plugin with the Mojolicious app. Called automatically by Mojolicious when you use
$app->plugin( 'Mercury' ).
Doug Bell <email@example.com>
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.