“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:
- publisher publishes a message with some unique property(such as
UUIDascorrelationID) - subscriber responds for the message with the same
UUIDascorrelationID - publisher(also subscriber of the reply topic) selects messages with the
UUIDsent.
Is this a wrong pattern?
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.