Majid Azimi
Majid Azimi

Reputation: 5745

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?

Upvotes: 6

Views: 3159

Answers (1)

Shashi
Shashi

Reputation: 15283

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.

Upvotes: 2

Related Questions