A simple, easy to use messaging framework for client side JavaScript.
Uses the STOMP messaging protocol which is supported by RabbitMQ, ActiveMQ, HornetQ etc.
All examples and sample projects have been tested on RabbitMQ.
- Support for many well-known Enterprise Integration Patterns
- Point to Point
- Publish/Subscribe
- Recipient List
- Scatter Gather
- Routing Slip
- Request/Response
- Auditing
- Exception Handling
bower install serviceconnect --save-dev
In this example we simply send a message from one endpoint and consume the same message on another endpoint. The sender and receiver can be in different browser sessions.
Calling initialize
creates an instance of the bus and connects to the queue serviceconnect.stomp.pointtopoint.sender
on the server http://localhost:15674/stomp
. queueMappings
defines were to send messages to and uses the format { routingKey: [endpoint1, endpoint2 ]}
. The onConnect
callback is called once the bus has connected to the messaging server.
var bus = Bus.initialize(function (config) {
config.queue = "serviceconnect.stomp.pointtopoint.sender";
config.url = "http://localhost:15674/stomp";
config.queueMappings = {
"Message1": ["serviceconnect.stomp.pointtopoint.consumer",]
};
config.onConnect = sendMessages;
});
To send a message using the send function we pass a routing key and a message. The bus looks up were to send the message using the queueMappings dictionary.
bus.send({
routingKey: "Message1",
message: {
data: "Message 1: Send"
}
});
Again, we configure an instance of the bus. This time, however we specify a message handler which says all messages with routing key Message1
should be processed by callback message1Handler
.
var bus = Bus.initialize(function (config) {
config.queue = "serviceconnect.stomp.pointtopoint.consumer";
config.url = "http://localhost:15674/stomp";
config.handlers = {
"Message1": [message1Handler]
};
});
Finally, we define a handler callback that will receive the message. The Context object contains headers and an instance of the bus.
var message1Handler = function(message, context) {
console.log(message);
};