Steve Nesh
Steve Nesh

Reputation: 85

RabbitMQ - how to avoid to receive own messages

I am creating a service (accessible via web and app) where users belong to a team. Whenever a user does something, all the other online users (*) in his/her team must be notified. I am evaluating RabbitMQ for this.

(*) Note that it is possible that the same user has multiple sessions at the same time: he could be logged in in different browsers at the same time, or more likely in the browser and and app at the same time.

My current approach is to create a topic exchange for each team:

This is great, because the update message must only be sent once by the backend. However, the problem here is that the initiator also receives his own update. I would like to avoid that. Is that possible? Or should I have another design?

Ofcourse, I can always add the user identifier of the initiator in the payload of the update message and filter on that field when receiving an update message, but the message is still received.

Upvotes: 3

Views: 1239

Answers (1)

Mitra Ghorpade
Mitra Ghorpade

Reputation: 717

That is an interesting question. After thinking about this for a while with this particular design, when the user wants to get the update and also make some changes while others should know about it I feel like you need to think of some other design.

With Topic as an Exchange you will always get the notification as the queue is created when you logged into the system. And Topic will broadcast it.

The topic is more for a subscription kind of thing where you can not specify easily where you want to skip one subscription or not.

One design I can think of which is bit complicated is as follow:

  1. Create one Topic Exchange per person in the team.
  2. When another User logs in he will subscribe to the Exchange of all other team members.
  3. When a user makes an update it is sent to his own Exchange where all others are listening.
  4. That way the user will not get his own update as he is listening to others topics.

Upvotes: 1

Related Questions