goxiaoy / emitter-csharp

Client library for emitter.io
Eclipse Public License 2.0
0 stars 1 forks source link

Subscriptions throwing exception if called immediately after Connect() #2

Open IliasP91 opened 2 years ago

IliasP91 commented 2 years ago

Do we really need to call the internal client directly in places like the following?

image

in my case if I do a subscription or publish right after the connect await returns then its throwing an exception image

where in the MQTTnet examples this is running perfectly fine(tried that snippet in my code as well and its ok) https://github.com/dotnet/MQTTnet/blob/master/Tests/MQTTnet.TestApp.NetCore/ManagedClientTest.cs

its not a big deal as the subscriptions etc could be added in a callback on the Connected event but if this could work then it makes the code flow a bit better i think

goxiaoy commented 2 years ago
  1. set recover to true to , see https://github.com/dotnet/MQTTnet/wiki/ManagedClient

All subscriptions are managed across server connections. There is no need to subscribe manually after the connection with the server is lost.

  1. delay subs after connection
            _emitter.Connected += async (s, e) =>
            {
                      await _emitter.Subscribe(.....)
            }
IliasP91 commented 2 years ago

ah i see so its intentionally designed like this to ignore the manage client's internal queue if recover is set to false. shouldnt the param also be named "queue" like the one in the Publish method though?

awesome it works just fine with setting the Subscribe recover param to true. thanks!

IliasP91 commented 2 years ago

in fact scratch that, if recover is set to true in the subscribe method right after connect, it still doesnt handle messages published later on not sure why though

goxiaoy commented 2 years ago

publish queue uses feature

All MQTT application messages are added to an internal queue and processed once the server is available.

subs recover uses feature

All subscriptions are managed across server connections. There is no need to subscribe manually after the connection with the server is lost.

But there is no gurantee that the listener can receive all messages. You can use retain option to keep latested message in mqtt protocol

IliasP91 commented 2 years ago

alright so the most "reliable" way would be to set subscribers only after the connected event has ben fired right? cool ill do some more testing later on but it should be alright. at least my main issue of not being able to connect with tls from a c# client is now working fine