6.2. Messaging Domains

The data push infrastructure in BlazeDS uses a message-based interaction model. Such an interaction model involves entities called producers, which send messages, and entities called consumers, which receive messages.

Producers and consumers can send and receive messages using either of two styles of communication: point-to-point or publish/subscribe. These two messaging styles are also referred to as messaging domains. In both these cases, the message-based communication between producers and consumers is predominantly asynchronous.

6.2.1. Point-to-Point

Point-to-point is a peer-to-peer messaging domain model. In this case, a logical entity called a queue is associated with each peer, and posting a message to a peer is equivalent to sending it to the queue that represents the peer. The communication is one-to-one.

Multiple producers can send messages to a single queue, and multiple consumers can fetch messages from a shared queue. When multiple consumers receive messages at the same queue, only one consumer can process an individual message. Let's illustrate this with an example. Say there are three consumers, c1, c2, and c3, and there are four messages, m1, m2, m3, and m4. Now if c1 consumes m1, then m1 cannot be consumed by c2 or c3. This behavior has two important implications:

  • If you need a message to be consumed by multiple consumers, then a point-to-point messaging domain may not be optimal. In a point-to-point model, sending a message, say m1, to all consumers, say c1, c2, and c3, will mean sending three distinct messages, one each to c1, c2, and c3. This means that as the number of senders and receivers increases, you could end up with a large number of message transmissions. The number of message transmissions will equal the cross-product of the number of senders and receivers involved.

  • If the order of message consumption is important, then you will have to externally manage the sequence in which the consumers, c1, c2, and c3, pick up the messages. In general, messages are placed sequentially in a queue, but their processing priority could be affected by factors such as the message expiration date, the message selectors, and message priority.

Consumers can be attached and detached to and from queues on demand, and that allows for a certain level of decoupling. Figure 6-6 summarizes a point-to-point messaging model.

If multiple producers and consumers need to interact, and each of the multiple consumers needs to process the same message, then using the publish/subscribe messaging model is more appropriate than using a point-to-point messaging model. You will learn about publish/subscribe messaging style next.

6.2.2. Publish-Subscribe

In the publish/subscribe messaging model, producers or senders of a message do not send messages directly to consumers or receivers of messages. Messages published by a producer can be classified into categories. Receivers or consumers register interest in particular categories and receive messages that are classified into those categories. Therefore, consumers receive only a subset of all the messages published.

Figure 6.6. Figure 6-6

The category or classification is sometimes also referred to as a filter or selector as it forms the criteria for selection of relevant messages from the entire bundle. Such category or filter definitions can be based on either of the following:

  • Topic — In such a scheme logical channels called topics define the categories. Publishers publish to a topic and receivers register interest in a topic. Receivers receive all messages published to their topic of interest.

  • Content — In such a scheme message metadata or content attributes define the classifier or the constraints. Receivers subscribe to messages based on these classifiers or constraints and receive all messages that match their subscription.

Publish/subscribe is most appropriate for cases where multiple consumers want to receive the same message. The model provides a system where the producers and receivers are totally decoupled. Therefore, such systems are scalable. Figure 6-7 summarizes a publish/subscribe messaging model.

Figure 6.7. Figure 6-7

Both the point-to-point and publish/subscribe messaging models involve a broker or a messaging infrastructure to send and receive messages. In the case of publish/subscribe, the broker could relay messages via a broadcast or a multicast. A broadcast involves sending messages to all connected consumers, whereas a multicast involves sending messages only to interested consumers and also optimizing the delivery by sending messages only once to a networked entity. This means that, in multicast, two logical entities sharing a network entity will receive only one message that will be shared between them.

Now that we have covered the fundamentals of messaging and messaging domains, I would like to jump to the topic of Java Message Service (JMS), which is used often with BlazeDS messaging.

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

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