MQTTnet
MQTTnet copied to clipboard
IManagedMqttClient.SubscribeAsync lacks support for subscription identifiers
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:
- Using the latest Nuget version of MQTTnet
- Try to subscribe and pass a subscription identifier
- No such method is available
Expected behavior
The managed client offers the same subscription possibilities as the unmanaged client.
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 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).
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!
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 😬
Bump cause needed:
Could we extend TopicFilters for SubscriptionOptions?