Messaging oriented components

jWebSocket “messaging oriented” components. What to use?
 
The jWebSocket framework provides two components intended for inter-components communication, these are:
  1. The JMS Manager
  2. The EventBus
The following document explain the goals, pros and cons of each one.
The JMSManager
 
The component was a first intend to provide a high abstracted API for components inter-communication. Using the JMS API, the JMSManager can be used to send/receive messages locally or across distributed nodes.
Basically the JMSManager is a high level JMS client for Java and JavaScript (Scripting).
 
MapMessage lMessage = lJMSManager().buildMessage(“msg-namespace”, “msg-type”);
lMessage.setStringProperty("param", “some string value”);
 
// sending
lJMSManager().send(“topic://my.app.broadcast.channel”, lMessage);
 
Receiving/processing a message:
lJMSManager().subscribe(“topic://my.app.broadcast.channel”, new MessageListener() {
 
  @Override
  public void onMessage(Message aMessage) {
    ...
  }
 
}, "ns = 'target-namespace' AND msgType = 'message type'");
 
Note:
Script apps (JavaScript) JMSManager integration is documented here: https://jwebsocket.org/documentation/Plug-Ins/Scripting-Plug-In/Developer-Guide/jms-integration
 
 
  • Send messages to target JMS destinations.
  • Register/unregister multiple listeners for message receiving on target JMS destinations.
 
  • Provides pub/sub and point to point messaging mechanisms by using JMS topics or queues respectively.
  • Using a centralized JMS broker components remotely distributed can easily communicate each other.
  • Communication can be secured at broker level to guarantee that only granted users can send/read messages on target JMS destinations.
  • Inherits all JMS benefits: http://docs.oracle.com/javaee/6/tutorial/doc/bncdq.html 
Cons:
  • Designed as a generic JMS client, the component uses raw JMS messages instead of jWebSocket Tokens, in consequence is not jWebSocket users friendly.
  • Request/Reply mechanism is not explicit part of the API.
  • Message delivery timeout notification is not explicit part of the API.
  • Requires basic JMS experience.
 
The EventBus
 
The component was introduced as a more mature, high level and jWebSocket server focused messaging component. Inspired on the Vert.x EventBus, provides a very simple and concrete API for inter-components communication. Uses Tokens as message format.
 
The jWebSocket default EventBus implementation is JMS based. So the JMS provider acts as final message broker. Using this implementation requires cloned runtime environments in case you want to communicate distributed components (on multiple server nodes). More about JMS:  http://docs.oracle.com/javaee/6/tutorial/doc/bncdq.html
 
 
// broadcasting a message to "test.topic" name-space
lEventBus.publish(TokenFactory.createToken("test.topic", "someaction"));
Receiving/processing a message:
// receiving messages on "test.topic" name-space
lEventBus.register("test.topic", new Handler() {
 @Override
 public void OnMessage(Token aToken) {
    ...   
 }
});
 
Main features:
 
  • Send/Receive Token objects.
  • Register/unregister multiple listeners(handlers) for tokens receiving on target name-spaces.
  • Request/Reply mechanism support.
  • Message delivery/processing timeout notification support.
 
Pros:
  • Provides pub/sub and point to point messaging mechanisms.
  • Uses the jWebSocket Token class as message data structure. jWebSocket friendly API.
  • jWebSocket cluster oriented.
  • The JMS EventBus implementation stands on centralized JMS broker(s). Better performance than the JMSManager.
  • Multi-threading listeners execution.
 
Cons:
  • The JMS EventBus implementation requires cloned distributed runtime environments for clustering.
Conclusion
 
The jWebSocket EventBus is intended to be the standard communication backbone on jWebSocket servers. Provides a more friendly API to jWebSocket developers by using the Token class as message data structure and jWebSocket like response callbacks.
 
In the other hand if you need a pure JMS client with a high level API, then you need to use the JMSManager.

Copyright © 2013 Innotrade GmbH. All rights reserved.