Over a million developers have joined DZone.

Hazelcast 1.4: Distributed Events

DZone's Guide to

Hazelcast 1.4: Distributed Events

· ·
Free Resource
Hazelcast is a free distributed/partitioned queue, map, set, list, lock and executorservice implementation for Java. 1.4 release focuses on distributed events and messaging.

What is new:

  • Add, remove and update events for queue, map, set and list
  • Distributed Topic for pub/sub messaging
  • Integration with J2EE transactions via JCA complaint resource adapter
  • ExecutionCallback interface for distributed tasks
  • Cluster-wide unique id generator

Hazelcast documentation covers all these new features already but lets go over the Distributed Topic feature together. No configuration is needed to run the following code. Just download the zip, add the hazelcast.jar into your project, and run the following code on 5 JVM instances. You have cluster of 5 JVMs for pub/sub messaging! No config, no nothing...


 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.publish ("my-message-object");
	public void onMessage(Object msg) {
		System.out.println("Message received = " + msg);

I hope the new Topic is simple and functional enough. Remember that topic operations are cluster-wide. If you add a MessageListener from member M, you will receive all messages published by any member in the cluster, including the new members joined after you added the listener.

Listeners will process the events/messages in the order they are actually fired/published. If event A occurred before event B on cluster member M, then it is guaranteed that all of the listeners of these events in the cluster will process event A before B.

Documentation at hazelcast.com covers all these new stuff with code samples so please visit the site for details.

What is next? Extending the Queue implementation to java.util.concurrent.BlockingQueue and some other cool stuff. Complete list of planned features can be found here. Got interesting feature in mind, let me know.

Website: http://www.hazelcast.com

Weblog: http://www.jroller.com/talipozturk

Group  : http://groups.google.com/group/hazelcast



Opinions expressed by DZone contributors are their own.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}