Anyone have a code sample of reading messages from...
# flow
r
Anyone have a code sample of reading messages from RabbitMQ as a flow? Would it be possible to implement with the rabbitmq-java library client https://www.rabbitmq.com/api-guide.html? It does have support for NIO so I'm guessing it's possible to do in an efficient manner, but I'm newbie at coroutines in general so not sure...
c
How does the library manage the calls? Are they blocking, or is it callback-based?
If it's blocking, you just have to use
withContext(<http://Dispatchers.IO|Dispatchers.IO>)
; if it's callback-based on you can
suspendCancellableCoroutine
If you have an example of how regular Java code reads from it (e.g. using a cursor, etc) it's easy
For example, here is how to convert an Apache Cassandra ResultSet to Flow: https://gitlab.com/opensavvy/clovis/-/blob/main/utils/cassandra/src/main/kotlin/opensavvy/clovis/cassandra/utils/ResultSet.kt#L23 I'm not sure exactly how RabbitMQ code looks like, but I bet it's very similar
r
Thanks Ivan, that's very helpful!
The rabbitmq-java api is java callback based so I'm trying to implement it with
suspendCancellableCoroutine
. I'll give an update if/when I get a working example.
g
@Rasmus have you tried using the
reactor-rabbit
library? You can use the reactor extensions to turn the fluxes into flows and should be your best option
129 Views