Hi all, if I have n workers listening the same cha...
# coroutines
g
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
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
As far as understand, only one (over n) worker will receive a given message, so I can not filter it at worker level
a
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
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
yeah that's somewhat similar to what I do, I send the message to the workers launching them in a coroutine