Message system is responsible for the transmission of messages from one application to another application in the system. For the application itself, it does not need to care about the transmission process of message data, but only needs the relational data itself.
There are two typical patterns for asynchronous messaging in distributed messaging systems: point-to-point messaging systems and publis-subscribe messaging systems.
Let’s take a look at the characteristics of these two models.
Point-to-point messaging system
Not to say, first draw, see the real.
The diagram is a classic example of a point-to-point messaging system. Message outgoing sends message data to a message queue, which is then consumed by consumers, namely message receivers. However, there will be a message that can only be consumed once, and when a message data is consumed, the message data will disappear in the message queue.
This is also a feature of point-to-point messaging systems, because each message data can only be consumed once, so the problem of repeated consumption is avoided.
Publish subscribe messaging system
The diagram is shown below.
Publish-subscribe messaging systems are the preferred solution for most distributed enterprise systems.
The publisher persists the message data to a data queue, not exactly a data queue, but a Topic, which is consumed by multiple subscribers. Each message data can be consumed by multiple subscribers.
After the data is consumed, it is not deleted by the topic, and the message data sent to the topic can be consumed by all subscribers, which is the essential difference between publish-subscribe messaging system and point-to-point messaging system.
How to choose
If you want to choose the pattern of message queuing, you have to choose the scenario, for example if your service is being called by multiple services, then you have to choose the publis-subscribe messaging system.