Message bus and Message queue understanding
Asked Answered
M

2

5

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

  1. 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 ?

  2. How does the subscriber receives the message ?

  3. 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.

Miter answered 4/8, 2019 at 8:16 Comment(1)
"how does the subscriber know what message it is interested in?" learn.microsoft.com/en-us/azure/service-bus-messaging/… read about topic and "rules" learn.microsoft.com/en-us/azure/service-bus-messaging/…Sociable
R
3

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 receiver 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.

Ray answered 5/8, 2019 at 7:22 Comment(0)
F
0

I know this question was already answered, but this is what i did to understand some of these concepts, i'll recommend practicing with actual code. For example, by doing the rabbitmq Tutorials from their official Page.
For instance, for your question:

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?

You can find your answer on The Tutorial N°5, where they explain how you can filter messages for specific topics,...
And the best part is that, just by playing with your Terminal and your IDE you can simulate multiple scenarios such as:

  • what happen when you add more Workers (you just add another terminal)
  • What Happen if server(publisher's or consumer's) is down(You close the publisher terminal)
  • how to save your messages (in-memory) to not loose them, and choose which category of message to save
  • And many more,... Happy coding :)
Fenelia answered 16/10, 2022 at 14:54 Comment(1)
It's better to answer the question than to pitch an educational material site.Spickandspan

© 2022 - 2024 — McMap. All rights reserved.