Exploring Messaging Models

In general, there are two main types of messaging models: point-to-point (PTP) and publish-and-subscribe (Pub/Sub). JMS refers to these models as messaging domains. A single JMS application can use both models; however, JMS focuses on applications that use one or the other.

A JMS client that sends (or publishes) a message is called a producer, whereas a JMS client that receives (or subscribes) to a message is called a consumer.

Point-to-Point Messaging Model

The PTP messaging model is intended for one-to-one delivery of messages, and is built around the concept of a message queue. Each message is sent to a specific queue; clients receive messages from the queue(s) established to hold their messages. They are point-to-point in the sense that a client sends a message to a specific queue. Receivers must either poll a queue periodically or listen to incoming events in order to extract their messages. Each message is consumed once and only once by a receiver. A message is automatically removed from the queue when it's consumed by a receiver. In PTP, a producer is called a sender, and a consumer is called a receiver. Figure 13.2 illustrates a few scenarios of PTP messaging.

Figure 13.2. Point-to-point messaging model.


As you can see in Figure 13.2, a queue might have more than one sender and more than one receiver, but only one receiver may consume each message. In the PTP model, a JMS client can choose to be a message browser that is allowed to peek into a message without consuming it.

Publish-and-Subscribe Messaging Model

The Pub/Sub messaging model is intended for one-to-many broadcast of messages and is built around the concept of a message topic. Each message published to a topic is broadcast to all the clients that subscribe to this topic. A Topic object encapsulates a provider-specific topic name. It is the way a client specifies the identity of a topic to JMS methods. Many Pub/Sub providers group topics into hierarchies and provide various options for subscribing to parts of the hierarchy. This is similar to the concept of newsgroups, in which a user subscribes to the newsgroup topic of interest. Each consumer receives a copy of each message, which is pushed to the clients subscribed to it. In the Pub/Sub model, a producer is called a publisher, and a consumer is called a subscriber. Figure 13.3 illustrates a few scenarios of Pub/Sub messaging.

Figure 13.3. Publish-and-subscribe messaging model.


In the Pub/Sub model, a JMS client can choose to be a durable subscriber that can disconnect and later connect to get its messages that it subscribed to.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.225.57.126