redisson: RedissonReactiveSubscription is not initialized properly and as a result - no messages are handled
Expected behavior
In case of using through org.springframework.data.redis.core.ReactiveStringRedisTemplate, I expect to handle messages from the channel I subscribed to via reactiveRedisTemplate.listenTo(channel)
Actual behavior
The subscription via reactiveRedisTemplate.listenTo(channel)
is happening and redis-cli PUBLISH channel hello
returns (integer) 1
, but NO messages are handled.
Spent some time debugging, I noticed that anonymous subclass of BaseRedisPubSubListener
is created in RedissonReactiveSubscription.receive()
with overridden onMessage(CharSequence channel, Object msg)
method which as I understand should handle all the messages from redis channel (by the way, perhaps you could explain why BaseRedisPubSubListener
overrides onMessage
with empty implementation? ).
In fact the listener handles all messages and swallows it somewhere, debugging the message hits onMessage
breakpoint, but nothing happened then.
By the way, in some unexplainable cases (I really don’t know how to explain it) somewhere in the code the SubscribeListener
is initialized and message that is handled by that listener is handled downstream (happens only in debug mode with some combination of breakpoints placed:)).
But event in that base, a single message first handled by BaseRedisPubSubListener
empty implementation of onMessage
and only then by SubscribeListener
which translates the message downstream.
I tried a lot of times but didn’t understand what is really needed to achieve this.
Steps to reproduce or test case
- Initialize ReactiveStringRedisTemplate with regular spring config (example attached).
- Call
reactiveRedisTemplate.listenTo(channel)
and subscribe to it.
Redis version 5.0.5
Redisson version org.redisson:redisson-spring-data-22:3.12.4
Redisson configuration
@Bean(destroyMethod = "shutdown")
public RedissonClient redissonClient() {
Config config = new Config();
config.useSingleServer()
.setDnsMonitoringInterval(-1)
.setTimeout(commandTimeoutMillis)
.setAddress("redis://" + host + ":" + port);
return Redisson.create(config);
}
@Bean
public ReactiveRedisConnectionFactory redisConnectionFactory(RedissonClient redissonClient) {
return new RedissonConnectionFactory(redissonClient);
}
@Bean
ReactiveStringRedisTemplate reactiveRedisTemplate(ReactiveRedisConnectionFactory redisConnectionFactory) {
return new ReactiveStringRedisTemplate(redisConnectionFactory);
}
About this issue
- Original URL
- State: closed
- Created 4 years ago
- Comments: 30 (17 by maintainers)
Commits related to this issue
- Fixed - RedissonReactiveSubscription.subscribe and receive methods aren't synchronized. #2686 — committed to redisson/redisson by deleted user 4 years ago
- Fixed - RedissonReactiveSubscription.subscribe and receive methods aren't synchronized. #2686 — committed to redisson/redisson by deleted user 4 years ago
use
Config.setCodec
methodFixed! Could you try it with attached version?
redisson-spring-data-22-3.12.5-SNAPSHOT.jar.zip
I found the bug - subscribe and receive methods should be synchronized.