On 03/11/2021 14:29, Arjen Markus wrote:
> I have an other question, though, more a usage question: is it possible to publish or receive messages so that only the first client to receives it actually gets it. The idea I have is to have several workers that simply take a message from the queue and each one is getting a unique message: first come first serve. In my naïve experiment with two receivers, they both got the same messages.
>
There is a new feature in MQTT v5 called shared subscriptions, which
seems like it should do exactly what you are describing. To use a shared
subscription, you prefix the topic filter with $share/name/. So, in your
example you would use something like:
Receive subscribe {$share/echopool/ECHO} echoString
Here "echopool" is a name to group the workers for this subscription.
You can use a different name to create a different set of workers for
another topic filter.
Having said that; it doesn't yet work with my libraries. When you
brought it up, I already knew I hadn't implemented it in the broker. But
a quick test against the mosquitto broker showed that it also doesn't
work on the client side, probably due to the mismatch between the
subscribed and actual topic ($share/echopool/ECHO vs ECHO). When I tried
to work around that, I ran into a bug. I will look into it and let you know.
Schelte.