Skip to end of metadata
Go to start of metadata
Deprecation Announcement
This release of the Coherence Incubator is now deprecated. For the latest supported release, help and documentation, please refer to the Coherence Incubator Project on at

The Messaging Pattern Project
Provides a simple implementation of Store and Forward Messaging.


This is an example implementation of store and forward messaging built on top of Coherence.

The Messaging Pattern advocates that;

  1. Payload, typically represented as a Message object, may be sent to a Destination from a Sender (also commonly known as a Publisher).
  2. It is the responsibility of the infrastructure managing the Destination to ensure that Messages (arriving at the said Destination) are then stored (in some manner) and consequently forwarded (in the order in which they arrived at the said Destination) to one or more Receivers (also commonly known as Subscribers).
  3. The Subscribers appropriately consume (receive and acknowledge receipt) of the said Messages from the Destination in the order in which they were forwarded to the said Subscribers.
  4. The infrastructure managing the Messages appropriately clean-up (remove and garbage collect) the said Messages that have been consumed by Subscribers.
  5. The type of the Destination determines the method of delivery to the Subscribers on that Destination.
  6. A Topic Destination (or Topic) will store and forward Messages to all of the Subscribers of the said Topic Destination. This form of Message delivery is often called "publish-and-subscribe messaging", "one-to-many messaging" or "the observer pattern".
  7. A Queue Destination (or Queue) will store and forward Messages to at most one of the Subscribers of the said Queue Destination. For each Message a different Subscriber may be used, but this is implementation and runtime dependent. This form of Message delivery is often called "point-to-point messaging" or "one-to-one messaging".
  8. A Message may be Persistent or Non-Persistent. In the case of Persistent Messages, the infrastructure managing the Destination must safely store the said Messages to a persistent (and recoverable) storage device so that in the case of infrastructure failure, Messages may be recovered (not lost).
  9. A Subscriber to a Topic is either Durable or Non-Durable. Durable Subscriptions allow the system implementing the Subscriber to terminate and return without losing Messages that may have been delivered during the outage (or disconnection).

While it's rare that an architecture making extensive use of Coherence will require Store and Forward Messaging (due to the ability to use MapListeners, Continuous Queries and events for notifications), there are arguably some circumstances where the pattern is particularly useful.

Although providing an implementation of store and forward Messaging on-top-of-Coherence has always been possible (as demonstrated by this implementation), most application-level requirements for messaging are often satisfied using existing, off-the-shelf and standardized corporate messaging infrastructure, like JMS. In the cases where such infrastructure is not available or not appropriate, this implementation may provide some benefits.

While it is not the intention nor is it the purpose of this implementation to replace existing messaging infrastructure, this example is specifically designed to provide a flexible framework for application-specific, high-performance messaging on a Data Grid.

More specifically, this implementation has been designed as a minimal framework to support the implementation of multi-directional and multi-point (no single point of failure) guaranteed event distribution, typically between multiple Coherence clusters separated by high-latency, high-bandwidth and often unreliable wide-area-networks (WANs)... aka: The Event Distribution Pattern

Release Version: Version
Release Date: October 31, 2012
Coherence Version: 3.7.1+
Target Platforms: Java Standard Edition 6+
Dependencies: Coherence Common
Download: coherence-messagingpattern-
MD5: 34704d9a9097867e78493d4a508296e0
Source and
Java Doc:

* Previous releases are available from the attachments page

Revision History
Version 2.8.6 (changes since 2.8.4)

Version 2.8.6 resolves an issue where by Messages may be left in the Messages cache after they have been acknowledged.

Version 2.8.5 was an internal unreleased build
Version 2.8.4 (changes since 2.8.3)

Version 2.8.4 is a patch release to upgrade dependencies to Coherence Common.

Version 2.8.3 (changes since 2.8.2)

Version 2.8.3 is a patch release to upgrade dependencies to Coherence Common.

Version 2.8.2 (changes since 2.8.1)

Version 2.8.2 is a patch release to upgrade dependencies to Coherence Common.

Version 2.8.1 (changes since 2.8.0)

Version 2.8.1 is a patch release to upgrade dependencies to Coherence Common and support the out and coming Coherence release.

Version 2.8.0 (changes since 2.7.3)

The most significant upgrade for this release is the adoption of Coherence 3.7. Overtime this will allow the pattern to take advantage of the lastest features, like "lite transactions" to ensure atomicity of multi-cache updates, without the overhead of "heavy" transactions.

Legend | = Breaking Change | = Improved | = New
  • Removed the separate pof and non-pof cache configurations. Cache configuration files now use the system-wide defined serializer. This dramatically simplifies serialization configuration and halves the number of cache configuration files.
  • Explicitly specifies xsds in configuration files to strictly enforce document validation.
  • Introduced the ability to ENABLE and DISABLE Subscriptions to support new Event Channel starting modes.
Implementation Discussion

Internally the Messaging Pattern uses three Coherence distributed caches: the Destination cache (for Topic and Queue objects), the Subscription cache and the Message cache.. To use Messaging, an application creates a destination, subscribes to that destination, then publishes messages to the destination. When an application publishes a message, it is put in the Message cache. A Message cache backing map listener receives an insert event and schedules a thread to process the newly inserted message. If the destination is a topic, the background thread will invoke each subscription to that topic notifying it about the new message. All topic subscriptions will receive the message. For a queue destination, the background thread will notify the queue, which then hands the message off to a single subscription, the next one waiting for a message. Meanwhile, the subscriber, which runs in the client JVM, has a client listener registered on the subscription cache.  When the messages arrives at the subscription, the subscriber listener is called and it puts the subscription object on an internal LinkedBlockingQueue. When the client thread calls the Subscriber.getMessage method, the subscriber waits until the LinkedBlockingQueue has an entry. Once the subscriber takes a entry off the queue, it then gets the message from the Message cache and returns the payload to the application.

Some of features of Messages

  1. Is naturally geared for accepting as many messages as physically possible (until the network capacity is exceeded or you run out of storage).
  2. Is completely JMX enabled and monitorable. Simply enable Coherence JMX monitoring to the Messaging tree which shows all topics, queues and subscriptions.
  3. Message delivery is guaranteed to occur in-order on a per client session basis (publisher).
  4. Server-loss (i.e.: cluster member loss) does not effect the availability of the messaging infrastructure (as it's built using Coherence distributed caching).

The most significant interface (from an application-level perspective) is the MessagingSession. Implementations of this interface, namely the DefaultMessagingSession, are how you control the messaging infrastructure, including;

  1. Creating Topic and Queue Destinations
  2. Subscribing and Unsubscribing to Destinations (creating Subscribers)
  3. Publishing Payload to Destinations, and
  4. Subscribing and reading (ie: consuming) Payload from Subscriptions

Using Topics and Queues

The following tabs outline the use Topics and Queues in an application.

Frequently Asked Questions

Why don't you support the Java Messaging Specification (ie: JMS) or feature X of JMS?

While it is theoretically possible for this implementation to be a SPI (Service Provider Implementation) for the Java Messaging Specification (JMS), this implementation has been explicitly designed to support the development of the Event Distribution Pattern and other WAN-based architectures, that of which do not necessarily require JMS.

How can I monitor the infrastructure?

Two ways. Firstly by enabling JMX, you'll find that all Destinations (ie: Topics) are automatically registered into the clustered JMX tree (under Messaging). Secondly, as all of the infrastructure state is represented using Coherence distributed caches; you may examine, listen to and mutate the appropriately named caches, called: "coherence.messagingpattern.destinations", "coherence.messagingpattern.messages" and "coherence.messagingpattern.subscriptions".

project project Delete
current current Delete
Enter labels to add to this page:
Please wait 
Looking for a label? Just start typing.