MQTTnet icon indicating copy to clipboard operation
MQTTnet copied to clipboard

IManagedMqttClient.SubscribeAsync lacks support for subscription identifiers

Open thedmi opened this issue 2 years ago • 5 comments

Describe the bug

The IManagedMqttClient API lacks the possibility to specify subscription identifiers:

Task SubscribeAsync(ICollection<MqttTopicFilter> topicFilters);

The IMqttClient interface, on the other hand, allows this because it takes a MqttClientSubscribeOptions object:

Task<MqttClientSubscribeResult> SubscribeAsync(MqttClientSubscribeOptions options, 
    CancellationToken cancellationToken = default);

Using the internal client through the InternalClient property of IManagedMqttClient as a workaround is not an option, because the connection is not guaranteed to be open.

Which component is your bug related to?

  • ManagedClient

To Reproduce

Steps to reproduce the behavior:

  1. Using the latest Nuget version of MQTTnet
  2. Try to subscribe and pass a subscription identifier
  3. No such method is available

Expected behavior

The managed client offers the same subscription possibilities as the unmanaged client.

thedmi avatar Jan 05 '23 15:01 thedmi

Seems like the syntax changed and now expects a Collection of MqttTopicFilter objects.

So the new syntax appears to be like following:

await _managedMqttClient.SubscribeAsync(new Collection<MqttTopicFilter>{
    new MqttTopicFilterBuilder().WithTopic("subscribe/test-topic").Build(),
    new MqttTopicFilterBuilder().WithTopic("subscribe/another-test-topic").Build()
});

The docs in Managed_Client_Simple_Samples and Wiki - ManagedClient still need to be updated with this new syntax.

Rikj000 avatar Mar 07 '23 13:03 Rikj000

@Rikj000 The bug I'm referring to is not that a collection is required, but that it is a collection of MqttTopicFilter. So one cannot specify other subscribe options such as subscription identifiers (as indicated in my description above).

thedmi avatar Mar 07 '23 15:03 thedmi

I'm facing the same issue. Had been using the MqttClient client but wanted to move to ManagedMqttClient to get the reconnect functionality as well as the publish queue. However, our code is dependent on the subscription identifier to be set, so cannot do the migration which is a bummer.

+1 if we could get this fixed!

techmantel avatar Oct 05 '23 12:10 techmantel

Until the ManagedMqttClient API is fixed, I managed by doing await _managedMqttClient.InternalClient.SubscribeAsync(subscriberOptions); and as this code is running inside the ConnectedAsync handler, which fires when the internal client connects, I suppose this should be fine 😬

techmantel avatar Oct 05 '23 14:10 techmantel

Bump cause needed:

Could we extend TopicFilters for SubscriptionOptions?

felix-ulonska avatar Apr 30 '24 08:04 felix-ulonska