Skip to content

R-Suite/ServiceConnect-JavaScript

Repository files navigation

ServiceConnect JavaScript

Join the chat at https://gitter.im/R-Suite/ServiceConnect-JavaScript bitHound Score

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.

Features

  • Support for many well-known Enterprise Integration Patterns
    • Point to Point
    • Publish/Subscribe
    • Recipient List
    • Scatter Gather
    • Routing Slip
    • Request/Response
  • Auditing
  • Exception Handling

Installation

bower install serviceconnect --save-dev

Simple example

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.

1. Configure the sender bus instance

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;
});
2. Send your message

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"
    }
});
3. Configure the consumer bus instance

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]
    };
});
4. Receive your message

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);
};

About

A simple, easy to use messaging framework for client side JavaScript.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Contributors 2

  •  
  •