You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When subscribing to a new topic, a subscription is added to the list. When unsubscribing the topic is removed.
There are certain issues with the current implementation, and I would argue that subscriptions should not be held in the client at all.
IMHO it would be best to have a low level client that does not try to do anything smart, and then add a ManagedClient that can focus on providing nice user features built on the solid low level client. It would also reduce the API surface of the low level client and simplify thread safety.
@pglombardo what do you think? I'm happy to chat about this is private, feel free to send me an e-mail.
varclient=newHiveMQClient(newHiveMQClientOptionsBuilder().WithClientId("ConcurrentSubscribe").Build());varinbox=newConcurrentBag<string>();client.OnMessageReceived+=(_,e)=>{inbox.Add(e.PublishMessage.Topic!);};varconnectResult=awaitclient.ConnectAsync();Assert.True(connectResult.ReasonCode==ConnAckReasonCode.Success);Assert.True(client.IsConnected());varsubscribeResult=awaitclient.SubscribeAsync("/test/#",QualityOfService.ExactlyOnceDelivery,false);Assert.True(subscribeResult.Subscriptions.Count==1);Assert.True(subscribeResult.Subscriptions[0].SubscribeReasonCode==SubAckReasonCode.GrantedQoS2);Assert.Equal(1,client.Subscriptions.Count(s =>s.TopicFilter.Topic=="/test/#"));awaitclient.PublishAsync("/test/1","whatever");while(!inbox.Contains("/test/1")){awaitTask.Delay(50);}awaitclient.DisconnectAsync();awaitTask.Delay(1000);varreconnectResult=awaitclient.ConnectAsync();Assert.True(reconnectResult.ReasonCode==ConnAckReasonCode.Success);Assert.True(client.IsConnected());awaitclient.PublishAsync("/test/2","whatever");// client still contains subscription.Assert.True(client.Subscriptions.Any(s =>s.TopicFilter.Topic=="/test/#"));// we never receive the message, because the subscription is not re-establishedwhile(!inbox.Contains("/test/2")){awaitTask.Delay(50);}
Subscribing multiple times results in multiple subscriptions (for the same topic) in the subscription list. This also included the handler.
Subscription level message handlers burn up CPU time, even when not used. All Subscriptions are iterated and checked for a topic match using MatchTopic, which is quite expensive.
🐛 Bug Report
The client currently exposes a list of Subscriptions.
When subscribing to a new topic, a subscription is added to the list. When unsubscribing the topic is removed.
There are certain issues with the current implementation, and I would argue that subscriptions should not be held in the client at all.
IMHO it would be best to have a low level client that does not try to do anything smart, and then add a ManagedClient that can focus on providing nice user features built on the solid low level client. It would also reduce the API surface of the low level client and simplify thread safety.
@pglombardo what do you think? I'm happy to chat about this is private, feel free to send me an e-mail.
Issues:
hivemq-mqtt-client-dotnet/Source/HiveMQtt/Client/HiveMQClientEvents.cs
Lines 245 to 265 in b3700c3
🔬 How To Reproduce
Archive.zip
Environment
Current master or latest Nuget
The text was updated successfully, but these errors were encountered: