For shared subscriptions in the .NET client, you can set up a subscription using the SubscribeOptionsBuilder with a per-subscription callback like this:
var builder = new SubscribeOptionsBuilder();var options = builder.WithSubscription( new TopicFilter("$share/group/topic/item", QualityOfService.AtLeastOnce), (sender, e) => { Console.WriteLine($"Message received: {e.Message.PayloadAsString}"); }) .Build();
The shared subscription format should be $share/GROUPID/TOPIC where:
$share is the static shared subscription identifier
There is a known issue reported where subscribing to both a regular topic and shared subscription of the same topic can cause unexpected behavior with message delivery
This may explain why you’re seeing the global OnMessageReceived event fire but not the per-subscription callback.
When using shared subscriptions, messages are distributed among subscribers in the same group rather than each subscriber receiving a copy
The broker sends the message with the actual topic (without the $share prefix), which is why you see “topic/item” in the message.
I hope this helps,
Best,
Dasha from The HiveMQ Team