https://kotlinlang.org logo
#coroutines
Title
# coroutines
g

Gilles Barbier

10/11/2020, 8:16 AM
Hi all, if I have n workers listening the same channel, does Kotlin provide a way to distribute messages to a specific worker according to a key? (equivalent of "key shared" feature of some queueing systems... https://pulsar.apache.org/docs/en/2.6.1/concepts-messaging/#key_shared) ?
a

Andrea Giuliano

10/11/2020, 8:19 AM
I think you are looking for a router bus. Not super expert but afaik it doesn't exist in Kotlin. I wrote my own bus to do that. However you can use channel as a flow and filter in the worker the messages you are interested to
☝️ 1
g

Gilles Barbier

10/11/2020, 8:21 AM
As far as understand, only one (over n) worker will receive a given message, so I can not filter it at worker level
a

Andrea Giuliano

10/11/2020, 8:23 AM
you can use a broadcast channel (or shared flow when it gets released) to send the same message to multiple workers
problem with boroadcast channel is that is marked as experimental
g

Gilles Barbier

10/11/2020, 8:24 AM
I did not know broadcast channel - I'll have a look on it. What about creating n channel, each of them listen by 1 worker ? (but then I have to manage myself the dispatching to the right channel. I was wondering if Kotlin has built-in feature for that).
a

Andrea Giuliano

10/11/2020, 8:26 AM
yeah that's somewhat similar to what I do, I send the message to the workers launching them in a coroutine
3 Views