Book Image

Getting Started with Hazelcast, Second Edition

By : Matthew Johns
Book Image

Getting Started with Hazelcast, Second Edition

By: Matthew Johns

Overview of this book

Table of Contents (19 chapters)
Getting Started with Hazelcast Second Edition
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Spreading the word


The final collection capability offered by Hazelcast is a broadcast messaging system. This is very much inspired by the JMS topics and offers a comparable set of features. With these features, we can publish events onto the messaging bus, to deliver to a large number of subscribed receivers.

As we can see in the following diagram, an application can publish a message onto a topic, which will then be distributed to all the instances of the application that have subscribed to the topic. This will include the instance that originally sent the message in the first place, assuming that it has a listener subscribed to the topic, too:

First things first, we'll need a MessageListener class to handle messages so that we can implement an onMessage(Message<T>) method, as required:

public class TopicListener implements MessageListener<String> {

  @Override
  public void onMessage(Message<String> msg) {
    System.err.println("Received: " + msg.getMessageObject());...