New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
How to use Redis pub/sub with Quarkus and ReactiveRedisClient? #21108
Comments
/cc @cescoffier, @gsmet, @machi1990 |
The error means you are trying to use the same client to publish and subscribe which is not allowed by the upstream redis client. /cc @pmlopes The issue has been reported in the past (I cannot find the reference to it) and our recommendation has been to create two separate clients using the multiple redis client feature. One create will perform the subscription and the other to publish.
@Inject
ReactiveRedisClient defaultClient; // you can use the default client for subscription
@Inject
@RedisClientName("publish")
ReactiveRedisClient publishingClient; // you can use this client for publishing |
@machi1990 Thank you for the answer, but I am not sure if this is the case. I literally don't have any code inside my test - it is just a subscribe called and nothing more - no one is publishing or any other action is going on. Could you try such a test by your side with latest Quarkus - I am using Quarkus dev services in test.
|
I also noticed this inside vertx github - vert-x3/vertx-redis-client#273. I have no idea what is a connection-less mode, but seems subscribe is not allowed in it - only publish/pubsub, but not subscribe. If someone could shed on a light on this it would be great. |
Right, I didn't know if you were referencing the subscribe command. I initially thought you were using the pubsub command, my mistake sorry.
@pmlopes would you have an idea? |
Hello. I'm currently facing the same issue which prevents even a simple application with a publisher and subscriber from properly working. Any news about a possible solution/workaround? Thanks. |
Today I had same time to dig deeper and found the issue. Basically the vertx redis client doesn't support pub/sub in connection pooled mode. https://vertx.io/docs/vertx-redis-client/java/#_connection_pooling https://vertx.io/docs/vertx-redis-client/java/#_pubsub_mode And since all Quarkus producers inside RedisClientsProducer class are using the BaseRedisClient which has a connection manager of a connection pool, then ReactiveRedisClient is not supporting pub/sub. In my opinion Quarkus should support a setting boolean flag to switch between connection pool mode and single connection mode for vertx redis extension. You can see in RedisAPIImpl class of Vertx:
In my opinion Quarkus needs a config flag which of the two constructors to use. Currently Quarkus uses only the 2nd constructor which calls the connection pooling of vertx and vertx doesn't support pub/sub in connection pooling mode. If Quarkus doesn't plan to fix this, then at least it should be mentioned in the doc. The workaround currently is to directly use the Vertx redis extension and bypass the Quarkus injectors. I managed to make it work with Mutiny by manually instantiating the Quarkus Redis Mutiny wrappers, but in my opinion it is much simpler to use directly what Vertx provides for pub/sub. Otherwise we need to subscribe to event bus, etc... Here is a simple example to use only Vertx:
To conclude - I think Quarkus should take some action - at least mention that in the doc and maybe provide that boolean flag config to be able to configure the injected client NOT to use pooling. And here is the workaround to use the Mutiny wrappers after manually getting the vertx connection from the callback, so the pooling is bypassed:
|
Forgot also to say: do NOT publish & consume in same connection like in the above examples - it was for a test. Just open separate connections. |
I had same issue, do you solve it? |
You should manage the connection manually, I suppose - Redis.createClient, like in the example I gave above. The Quarkus produced injectors are using connection pooling, which is not compatible with pub/sub. |
Oh, thanks so much. Your workaround working properly, but I hope Quarkus team can enhance this feature |
Thanks @digitalsamba @tamht298 for the investigation and workaround. Agreed, this should be better documented or made to work transparently without requiring extra work from the consumers of the extension as exposing yet another flag might confuse them.
@pmlopes I've just became aware of that, is this something new in one of the recent versions of the vertx-redis client? |
@machi1990 is there an elegant way to handle this? I am also facing the same issue. |
This will be handled in #24750 |
Thanks for that! |
Fixed in #26268 |
I am trying to use Redis pub/sub with Quarkus, but I cannot find any documentation about it. I managed to use the Quarkus Redis Extension with Redis Streams xadd and xread, but cannot make Redis pub/sub work. I am using ReactiveRedisClient and when I try to subscribe to a redis channel in a Quarkus test I receive following error:
Error received: io.vertx.core.impl.NoStackTraceThrowable: PubSub command in connection-less mode not allowed
I found the error is thrown in vertx redis extension BaseRedisClient class:
Generally I find Quarkus would benefit of documenting how to use Redis Pub/Sub cause I found other people are also confused how to use it exactly.
Thanks in advance for any help!
The text was updated successfully, but these errors were encountered: