Search code examples
c#mqtthivemq

HiveMQ shared subscriptions using M2Mqtt


If subscriber has topic as $share/group/my_topic, it doesn't receive any messages, but if I change the topic to /my_topic - everything works just fine.

It seems that M2Mqtt doesn't support shared subscriptions. Is there a workaround for this? I also need persistence to work with shared subscriptions.

If there's no workaround, offers to other libraries are welcome!


Solution

  • I can't test this but I have a theory.

    The problem is that you have a leading / on your base topic /my_topic

    If you remove this and publish messages on my_topic then the shared topic should match.

    Having a leading / adds a null element to the topic, which you can't include in the $share/group/[null]/my_topic

    While leading a / is allowed in the MQTT spec it is considered bad practice (and can lead to issues like this).

    Also the client library has no knowledge of shared subscriptions, this is entirely a broker side feature. All clients should "just work"