Closed eduardkieser closed 6 months ago
Does it work if you use the loop()
calls manually? This loop_forever()
is a bit troublesome and I dont seem to find out why, maybe I should remove or hide it :P
Hi, yes it seems to work well enough with the manual loop()
call. I would be able to make it work better if I could figure out if there are still things in the upload Q. In my case I'm trying to use it for inter process communication, so I want to shove quit a lot of data through. It seems like the publish() command does not wait for the upload to finish, so if I do a manual loop() in my main loop then the program happily publishes and exits before all the data got to the broker. My work around is to add another fixed length for loop with some loop()
and sleep
commands to allow all the messages to be uploaded, but I'm sure there must be a more elegant way. Is it possible for the client to figure out if there are still messages to upload?
I dont know of a way to check an output queue for Mosquitto, but Mosquitto can give feedback, when the message was transfered to the broker. This is basically done when setting the waitcb
flag, as is done in example 08 (internally another callback is done by Mosquitto, putting the message id in a channel). I think however that for qos 0, it just returns immediately as it doesnt wait for feedback from the broker in any way, so I recommend using this with at least qos 1. Unfortunately this makes the publish command block, so loop_forever
is required for it currently.
I think I could change the publish command to also return the message ID, then the arrival of the message at the broker could be checked without using the loop_forever
I made an update on the main branch. Example 8 shows how to publish and wait for broker feedback without using loop_forever
.
I also noticed that a problem might have existed in the old example 8 (now example 9) as I was running loop_forever
with @async there.
Let me know if this update helps you. You need to checkout main actually.
Some update on this. I release the 0.9 which allows you to check if a message was published. I also removed the export from loop_forever
and recommend using loop instead
, an example is shown in 08_publish_puback.jl
.
Also, I figured out there is a way to check if there is something to be sent, called want_write . I just didnt implement it properly, but I put this on my list https://github.com/denglerchr/Mosquitto.jl/issues/23 .
Closing this one for now, as I believe you can use loop
and I cannot reproduce the issues with loop_forever
on my side.
When running the
07_subscribe_loop_forever.jl
and08_publish_loop_forever.jl
example it works with the test server, but if I replace it with my localhost broker the subscriber does not seem to subscribe properly.Testing (as on main
2731c2608e2a1c82a3004feebe1ff8feb10abe30
) run07
startup is good:run
08
all looks good, see output on07
terminal:Now if I replace
"test.mosquitto.org"
with"localhost"
, the start up of07
still looks good, but if I run08
I don't see the messages printed on the07
terminal. I think the problem is in07
because if I set up a subscriber using:mosquitto_sub -h localhost -p 1883 -t 'eduard/#' -v
I do see the messages come through via the local broker.Additionally, if I look at the output of my local broker I can see it connect to the
07
client and get the messages from the08
publisher, but I don't see it trying to pass on the message the the07
client. The client does seem to be connected because I see the occasional ping-request and response between broker and the07
client.it looks a lot like #19 , but might be unrelated..