Mercury Message Broker

ws://

Mercury is a WebSocket message broker that enables some simple messaging patterns.

Bus
A message bus is a many-to-many, peer-to-peer message pattern. All peers connect to a topic and receive all messages published on that topic.
Pub/Sub
A pub/sub allows one or more publishers to send messages to one or more subscribers. Pub/sub topics are hierarchal, allowing subscribers to broaden or narrow the messages recieved.
Push/Pull
A push/pull allows one or more publishers to send messages that will be handled by exactly one subscriber in a rotation.

WebSockets are a powerful tool, enabling many features previously impossible, difficult, or ugly for web developers to implement. Where once only an HTTP request could get data from a server, now a persistent socket can allow the server to send updates without the client needing to specifically request it.

WebSockets do not need to be a communication channel purely between browser and server. The Mojolicious web framework has excellent support for WebSockets. Using that support, we can communicate between different server processes. This solves the problem with client-to-client communication in a parallelized web server where all clients may not be connected to the same server process. The server processes can use a central message broker to coordinate and pass messages from one client to another.

A message bus is a many-to-many message pattern. Requesting a WebSocket from the URL /bus/fry joins the peer-to-peer message bus topic fry. All peers joined to the same topic will receive all the messages published to that topic by other peers.

Open another browser window to see messages pass between windows.

Peer 1

Type in a topic and a message and press Enter to send to that topic.

/bus/

Peer 2

Type in a topic and a message and press Enter to send to that topic.

/bus/

Requesting a WebSocket from the URL /sub/leela creates a subscription to the topic "leela". Requesting a WebSocket from the URL /pub/leela allows sending messages to the "leela" topic, which are then received by all the subscribers.

Topics are heirarchical to allow for broad subscriptions without requring more sockets. A subscription to the topic "wong" receives all messages published to the topic "wong" or any child topic like "wong/amy" or "wong/leo"

Subscribe

Type in a topic and press Enter to subscribe to that topic.

/sub/

Publish

Once you're subscribed, type in a topic and a message to send a message on that topic.

/pub/

Push/pull allows multiple publishers to send messages that will be handled by exactly one subscriber in a rotation. Requesting a WebSocket from the URL /pull/bender creates a subscription to the topic "bender". Requesting a WebSocket from the URL /push/bender allows sending messages to the "bender" topic, which are then sent to a single subscriber.

Pull 1

Type in a topic and press Enter to subscribe to that topic.

/pull/

Pull 2

Type in a topic and press Enter to subscribe to that topic.

/pull/

Push

Once you're subscribed, type in a topic and a message to send a message on that topic.

/push/