Skip to content
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

ClassCastException when doing pub/sub from RedisStaticMasterReplicaConfiguration [DATAREDIS-1093] #1663

Closed
spring-projects-issues opened this issue Jan 29, 2020 · 4 comments
Assignees

Comments

@spring-projects-issues
Copy link

@spring-projects-issues spring-projects-issues commented Jan 29, 2020

Ryan Rich opened DATAREDIS-1093 and commented

When trying to use connections created through a LettuceConnectionFactory configured with a RedisStaticMasterReplicaConfiguration (for use with ElastiCache) you get ClassCastExceptions when trying to do pub/sub:

[RedisMessageListenerContainer]-[656 ]-SubscriptionTask aborted with exception: org.springframework.data.redis.RedisSystemException: Unknown redis exception; nested exception is java.lang.ClassCastException: Cannot cast io.lettuce.core.masterslave.StatefulRedisMasterSlaveConnectionImpl to io.lettuce.core.pubsub.StatefulRedisPubSubConnection at org.springframework.data.redis.FallbackExceptionTranslationStrategy.getFallback(FallbackExceptionTranslationStrategy .java:53) at org.springframework.data.redis.FallbackExceptionTranslationStrategy.translate(FallbackExceptionTranslationStrategy.j ava:43) at org.springframework.data.redis.connection.lettuce.LettuceConnection.convertLettuceAccessException(LettuceConnection. java:270) at org.springframework.data.redis.connection.lettuce.LettuceConnection.pSubscribe(LettuceConnection.java:820) at org.springframework.data.redis.listener.RedisMessageListenerContainer$SubscriptionTask.eventuallyPerformSubscription (RedisMessageListenerContainer.java:785) at org.springframework.data.redis.listener.RedisMessageListenerContainer$SubscriptionTask.run(RedisMessageListenerConta iner.java:752) at java.lang.Thread.run(Thread.java:748) Caused by: java.lang.ClassCastException: Cannot cast io.lettuce.core.masterslave.StatefulRedisMasterSlaveConnectionImpl to io.lettuce.core.pubsub.StatefulRedisPubSubConnection at java.lang.Class.cast(Class.java:3397) at org.springframework.data.redis.connection.lettuce.StaticMasterReplicaConnectionProvider.getConnection(StaticMasterReplicaConnectionProvider.java:79) at org.springframework.data.redis.connection.lettuce.LettuceConnection.switchToPubSub(LettuceConnection.java:882) at org.springframework.data.redis.connection.lettuce.LettuceConnection.initSubscription(LettuceConnection.java:886) at org.springframework.data.redis.connection.lettuce.LettuceConnection.pSubscribe(LettuceConnection.java:817) ... 3 common frames omitted

Affects: 2.2.4 (Moore SR4)

Backported to: 2.2.5 (Moore SR5), 2.1.16 (Lovelace SR16)

@spring-projects-issues
Copy link
Author

@spring-projects-issues spring-projects-issues commented Jan 29, 2020

Mark Paluch commented

Thanks for report. Using Master/Replica isn't going to work with Pub/Sub. First, there is no Pub/Sub implementation in Lettuce for Master/Replica. The second reason is that Redis Standalone or Replica does not propagate Pub/Sub messages across nodes. That's only available in Redis Cluster. So messages sent on one node cannot be received on a different node.

We should improve at least the exception and our docs to indicate that Pub/Sub isn't supported.

@spring-projects-issues
Copy link
Author

@spring-projects-issues spring-projects-issues commented Jan 29, 2020

Ryan Rich commented

Thanks for the update, it would be helpful to note something in the docs regarding this... I assume to use pub/sub then for something like ElastiCache (non-clustered) one should just use a RedisStandaloneConfiguration pointed to the primary and let the aws failover promotion (which I believe keeps the same primary url as the target) handle things?

@spring-projects-issues
Copy link
Author

@spring-projects-issues spring-projects-issues commented Jan 29, 2020

Mark Paluch commented

Yes, please use either the standalone config or the sentinel one (without setting ReadFrom). Both assume operations with a master node

@spring-projects-issues
Copy link
Author

@spring-projects-issues spring-projects-issues commented Feb 13, 2020

Mark Paluch commented

Documentation is updated now

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
2 participants