fusesource / mqtt-client

A Java MQTT Client
http://mqtt-client.fusesource.org/
Apache License 2.0
1.27k stars 369 forks source link

Dispatch queue 'mqtt client' was not executing, (currently executing: '<not-dispatched>') #98

Open eastpav opened 6 years ago

eastpav commented 6 years ago

I was encountered the error above when mqtt-client CallbackConnection runs in junit, a publish method would be triggering the error [org.fusesource.hawtdispatch.internal.SerialDispatchQueue.assertExecuting(SerialDispatchQueue.java:145)]. But, it works ok when the same code runs in normal.

The same thing will be happen when execute CallbackConnection.connect、CallbackConnection.listener and CallbackConnection.subscribe in order, In junit, subscribe method will trigger the error but in normal work ok.

Is some different from junit and normal? Thx

sfiloveyou commented 5 years ago

i have the same problem

alexluojian commented 3 years ago

this way may work. connection.getDispatchQueue().execute(()->{ connection.publish(topic, data, qos, retained, new Callback() { @Override public void onSuccess(Void value) { logger.debug("send success!"); } @Override public void onFailure(Throwable value) { logger.debug("send failed:", value); } }); });

wrenchzc commented 2 years ago

@alexluojian it works, but why?