The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.

NAME

Mercury - Main broker application class

VERSION

version 0.006

DESCRIPTION

This is the main broker application class. With this class, you can add a message broker inside your Mojolicious application.

It is not necessary to use Mojolicious in order to use Mercury. For how to use Mercury to broker messages for any application, see the main Mercury documentation. For how to start the broker application, see the mercury broker command documentation or run mercury help broker.

ROUTES

/bus/*topic

Establish a WebSocket message bus to send/recieve messages on the given topic. All clients connected to the topic will receive all messages published on the topic.

This is a shorter way of doing both /pub/*topic and /sub/*topic, without the hierarchal message passing.

One difference is that by default a sender will not receive a message that they sent. To enable this behavior, pass a true value as the echo query parameter when establishing the websocket.

  $ua->websocket('/bus/foo?echo=1' => sub { ... });

/sub/*topic

Establish a WebSocket to subscribe to the given topic. Messages published to the topic or any child topics will be sent to this subscriber.

/pub/*topic

Establish a WebSocket to publish to the given topic. Messages published to the topic will be sent to all subscribers to the topic or any parent topics.

/pull/*topic

Establish a WebSocket to pull messages from the given topic. Messages will be routed in a round-robin fashion from pushers.

/push/*topic

Establish a WebSocket to push messages to the given topic. Messages will be routed in a round-robin fashion to a single puller.

METHODS

add_bus_peer

    $c->add_bus_peer( $topic )

Add the current connection as a peer on the given bus topic. Connections can be joined to only one topic.

remove_bus_peer

Remove the current connection from the given bus topic. Must be called to clean up the state.

send_bus_message

    $c->send_bus_message( $topic, $message )

Send a message to all the peers on the given bus. Will not send to the current peer (they should know what they sent).

add_topic_subscriber

    $c->add_topic_subscriber( $topic );

Add the current connection as a subscriber to the given topic. Connections can be subscribed to only one topic, but they will receive all messages to child topics as well.

remove_topic_subscriber

    $c->remote_topic_subscriber( $topic );

Remove the current connection from the given topic. Must be called to clean up the state.

publish_topic_message

    $c->publish_topic_message( $topic, $message );

Publish a message on the given topic. The message will be sent once to any subscriber of this topic or any child topics.

AUTHOR

Doug Bell <preaction@cpan.org>

COPYRIGHT AND LICENSE

This software is copyright (c) 2015 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.