Publish/Subscribe is a messaging pattern that aims to decouple the sending (Publisher) and receiving (Subscriber) party. A real world example could be a sport mobile app that shows you up-to-date information of a particular football game you're interested in. In this case you are the subscriber, as you express interest in this specific game. On the other side sits the publisher, which is an online reporter that feeds a system with the actual match data. This system, which is often referred as the message broker brings the two parties together by sending the new data to all interested subscribers.
The Publish/Subscribe messaging pattern brings many benefits:
- Implement the publisher and subscriber parties independently from each other
- Publishers and Subscribers don't require to know each other
- One Subscriber could receive from many different Publishers
- One Publisher could send data to many different Subscribers
The benefits can be sumarized to Loose Coupling, the decoupling of publisher and subscriber, as well as Scalability through the parallel nature of the publisher and subscriber components.
Many standardized messaging protocols that implement a Publish/Subscribe pattern exist. In the area of application level protocols the most interesting ones are:
- AMQP, Advanced Message Queueing Protocol
- MQTT, MQ Telemetry Transport
- JMS, Java Messaging Service
- XMPP, Extensible Messaging and Presence Protocol
A publish/subscribe messaging protocol is only as useful as its message broker implementations.