Based on shared subscription

Currently, I have done a Shared subscription and the broker randomly selects one subscriber in each group and sends a message to that subscriber. I want it more like group communication, where one member of each group receives a message they pass this message to every other member of the group. So that each subscriber receives every message. How can I do it?

Hello @fini,

I have done a Shared subscription and the broker randomly selects one subscriber in each group and sends a message to that subscriber.

That is how shared subscriptions work.

I want it more like group communication, where one member of each group receives a message they pass this message to every other member of the group.

An shared subscription can’t do this, as they are not intended for that.

Possible solutions are…

  • Client base solution: let each client that received a message for a shared subscription republish that message to an “internal topic” where only the other clients in the shared group are subscribed (with a normal subscription).
  • Extension system: build a collection that holds information about all clients that have a shared subscription (use the SubscribeInboundInterceptor to do that), then in the PublishOutboundInterceptor you could then check if a message goes to one of the clients and republish it accordingly to the other clients in the shared group (using the PublishService).

Though both solutions only work if your shared group clients are only subscribed to the shared subscription topic filter and don’t have another overlapping subscription to that topic filter (i.e. can’t have $share/group1/topic1 and topic1 subscription).

Hope that helps,
Michael from the HiveMQ team

1 Like

Hi @fini,

what prevents your clients from just subscribing all to the topic of interest?

This would be pretty much what pub/sub is made for:

https://www.hivemq.com/blog/mqtt-essentials-part2-publish-subscribe/

Have a nice day
Georg

2 Likes

Thanks for your reply