问题
I would like to know if my understanding of Message Bus and Message Queue workings is correct.
First thing first, I need to clear the naming, a service bus is used interchangeably with message bus? It is a publisher-subscriber type of system where messages are added let's say to a message collection by any number of publishers and from where any number of subscribers can read, am i right so far ?
P1 --- /``````S1
\________ Service Bus Middleware ------+------ S2
/ MESSAGE-COLLECTION \______S3
P2 ---
What I don't understand is
how does a subscriber know what message it is interested in, I mean it subscribes to it obviously, but how does it know to which message(s) it should subscribe?, Where does it see the message list, how is this available to it? via an API with or how ?
How does the subscriber receives the message ?
when is a message removed from MESSAGE-COLLECTION? What I can imagine is that some counter is kept for each message, the counter represents the total number of subscribers which gets decremented as soon as one subscriber successfully processed the message.
A message queue also known as a message-broker is a push-pull type of system. There are any number of producers and any number of consumers. Each producer creates a queue per consumer to which it feeds messages.
--- Message Queue 1 ---- C1
/
P1 ------ +
\
--- Message Queue 2 ---- C2
P2 ------ + --- Message Queue 1 ---- C1
Since this is the case, the message gets removed as soon as the consumer successfully processes it. Are my message queue understanding of its workings correct ?
Another concept that I'm not sure of what exactly does is event hub.
回答1:
I would like to know if my understanding of Message Bus and Message Queue workings is correct.
Some comments/answers. This is not going to be comprehensive as many aspects are specific to the queue being used.
a service bus is used interchangeably with message bus?
Right. A service bus is a message bus infrastructure used in service-oriented solution, providing the back-end data transport mechanism between the services.
It is a publisher-subscriber type of system where messages are added let's say to a message collection by any number of publishers and from where any number of subscribers can read
There are generally two models:
1) Publish/Subscribe, where a publisher sends data to a bus without a specific target in mind. One or more subscribers can then consume the message (or not, see below).
2) Request/Response, where a senders sends the data to the bus but expects a specific received to handle the message and return a response.
how does a subscriber know what message it is interested in...?
Most service bus implementations use the concept of routing keys. Each data entity sent to the bus is accompanied by a key that the subscribers can then filter by.
Of course, subscribers may also choose to get all messages posted to a particular queue.
How does the subscriber receives the message ?
This varies among service queue products. In RabbitMQ, for example, messages are delivered to a subscriber by the API whereas in Kafka, the client must poll the server periodically for messages.
when is a message removed from MESSAGE-COLLECTION?
Sometimes not at all. This also varies both between products and configurations. Sometimes a message is delivered to only one receiver and is deleted once delivery has been confirmed, but sometimes messages are left on the bus until they are expired based on a time stamp. Many scenarios are possible.
来源:https://stackoverflow.com/questions/57345003/message-bus-and-message-queue-understanding