Open Gitter Chat

Messaging

One powerful collection capability offered by Hazelcast is the broadcast messaging system. This is inspired by JMS topics and offers a comparable set of features so you can publish events on a bus that can deliver to an arbitrary number of listeners.

Hazelcast Topics is not a full JMS provider, but it is in use delivering millions of messages scalably at organizations like Ericsson and NTT of Japan.

Applications can publish a message onto a topic which will be distributed to all instances of the application that have subscribed to that topic. 

One of the primary benefits of this style of messaging is that it can reliably be scaled to many nodes, thus increasing throughput of messages. Hazelcast lacks any single point of failure which is not easy to achieve with pure JMS solutions.

 

Hazelcast provides distribution mechanism for publishing messages that are delivered to multiple subscribers which is also known as publish/subscribe (pub/sub) messaging model. Publish and subscriptions are cluster-wide. When a member subscribes for a topic, it is actually registering for messages published by any member in the cluster, including the new members joined after you added the listener. Messages are ordered, meaning, listeners(subscribers) will process the messages in the order they are actually published. If cluster member M publishes messages m1, m2, m3…mn to a topic T, then Hazelcast makes sure that all of the subscribers of topic T will receive and process m1, m2, m3…mn in order.
import com.hazelcast.core.Topic;
import com.hazelcast.core.Hazelcast;
import com.hazelcast.core.MessageListener;

public class Sample implements MessageListener {

    public static void main(String[] args) { 
        Sample sample = new Sample();
        Topic topic = Hazelcast.getTopic ("default");  
        topic.addMessageListener(sample); 		
        topic.publish ("my-message-object");
    }  
	 
    public void onMessage(Object msg) {
        System.out.println("Message received = " + msg);
    } 
}

Hazelcast.org

Main Menu