With Radisson, simply receiving events is enough to add new items to the list. To do this, you need to do the following:
object Test extends App {
val redisson = Redisson.create()
val events = redisson.getQueue[String]("minio_events", new StringCodec())
events.addListener(new ListAddListener() {
override def onListAdd(o: String): Unit = println(o)
})
}
Difficulties begin when it needs to be wrapped in ZIO. How can I wrap this event in ZIO or ZStream to start the chain of event processing?
2
Answers
ZStream is pull based, that means you’ll have to pull the data from
minio_events
in some wayThis creates a
ZIO[Any, Throwable, String]
representing your polling operation which can now be turned into aZStream
by calling theZStream.fromEffect
methodIf you place this code inside a
zio.App
main function, you’ll see that it runs only once. So we need to make it run forever and retry it until if finds another elementIt looks like Redisson supports converting the
RedissonClient
into a reactive streams client which there is a zio-interop for. But if you just want to work directly with the java interface I think you can do something like this (note I haven’t actually tested this):