Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can we use request/reply model in publish/subscribe messaging?

"Java Message Service" book by O'Reilly Media says:

use request/reply model in point-to-point messaging.

We can use message selectors in pub/sub messaging, so writing a request/reply model is as simple as writing a simple selector on reply topic:

  1. publisher publishes a message with some unique property(such as UUID as correlationID)
  2. subscriber responds for the message with the same UUID as correlationID
  3. publisher(also subscriber of the reply topic) selects messages with the UUID sent.

Is this a wrong pattern?

like image 484
Majid Azimi Avatar asked Jun 19 '12 05:06

Majid Azimi


People also ask

What is publish subscribe messaging model in JMS?

Publish Subscribe Messaging Model is a messaging paradigm supported by JMS (Java Message Service). It is intended to provide asynchronous message transmission between publisher and subscriber using topics. In this article, lets discuss about Publish Subscribe Messaging Model Architecture in detail.

What is the difference between point-to-point and publish/subscribe message models?

Another difference is in the point-to-point model, the message sender must know the receiver but in the publish/subscribe the message publishers do not need to know where the message will be consumed. This characteristic provides a high decoupling for the application when applying the publish/subscribe message model.

How are messages sent to subscribers?

Messages are sent (pushed) from a publisher to subscribers as they become available. The host (publisher) publishes messages (events) to channels (topics).

What is the difference between request-response and publish-subscribe?

The two we'll look at are request-response and publish-subscribe. The typical model for computers communicating on a network is request-response. In the request-response model, a client computer or software requests data or services, and a server computer or software responds to the request by providing the data or service.


1 Answers

Request/Reply messaging pattern is typically used for invoking a service hosted by service provider. Based on service request, a provider will reply with an appropriate response. So it's one-to-one. Here requestor and responder know each other.

In case of pub/sub, publisher and subscriber do not know each other. There could be a number of publisher publishing on a topic and there could be thousands of subscribers listening for that topic. So after receiving publication, if a subscriber replies to request using a topic, then that publication could go to a number of subscribers. Such a thing might flood the network.

In my opinion Request/Reply model must be used in P2P messaging and not Pub/Sub.

like image 175
Shashi Avatar answered Nov 09 '22 08:11

Shashi