Persistence: Stores and Durables

Persistence is the ability to temporarily store a message at an intermediary between publishers and subscribers.

Message delivery through a transport bus is immediate and transient:

  • Transports carry messages immediately from publisher to subscribers. Messages do not pass through an intermediary, such as a server. Transports neither store messages in transit, nor forward them later.
  • Messages are transient. Publisher objects and transports do not indefinitely retain messages after transmitting them to current subscribers.

These two qualities, immediacy and transience, promote speed and simplicity. However, sometimes we need a different quality, persistence, which is the potential to store a message between sending and receiving it.

We can introduce a store-and-forward intermediary to provide persistence. Consider the following aspects of its operation.

Persistent Message Streams

To receive a message through a transport, a subscriber must be present when the message is published, and the transport bus between publisher and subscriber must be working properly.

To transcend the limitations of transient messages, a store-and-forward intermediary, called a store, can maintain a persistent message stream, collecting and retaining messages from publishers. In a sense, it serves as a backup publisher for the benefit of subscribers.

Persistent Message Interest (Durable)

A subscriber object expresses transient interest in a message stream. When the subscriber closes, its interest in those messages ceases. A subscriber misses any messages that pass through a transport bus after the subscriber closes or before the client program creates the subscriber.

To transcend the limitations of transient interest, a store-and-forward intermediary can express interest that endures even when no subscriber object is present, maintaining persistent interest for the benefit of subscribers. A durable is the data structure within a store that represents subscriber interest.

Apportion Message Streams

In one-to-many publishing, each subscriber expresses interest in a message stream, and receives every message in that stream through the transport bus.

However, sometimes we might want to apportion a message stream among a set of cooperating subscribers, so that only one subscriber receives and processes each message, but acting together they process every message in the stream. A store-and-forward intermediary can facilitate this behavior.

Last Value

In some applications, a newly started application process needs only the most recent message from a message stream, rather than the entire stream. For example, in financial market ticker applications, the most recent price information about a stock is very important when an application starts or restarts, while previous messages containing out-of-date price information could be unimportant. In applications that monitor information technology environments, the current status of each resource is very important, and the status history of a resource could be unimportant.

A store-and-forward intermediary can express interest in a message stream, divide the message stream into sub-streams based on the string value of a key field, and cache the most recent message in each sub-stream. Applications can subscribe to individual sub-streams.

Key/Value Maps

A key/value map stores key/value pairs, in which each key is a string, and a key's value is a message. Applications can use map methods to store and retrieve key/value pairs, and to iterate over the pairs in a map. Map methods provide a convenient way to use the store-and-forward intermediary as a simple database table.