Posted onEdited onInRedisViews: Disqus: Symbols count in article: 1.1kReading time ≈2 mins.
Intro Redisson Sharded Topic
這篇介紹Redisson Sharded Topic。
Intro
1 2 3 4 5 6 7 8 9
Java implementation of Redis based RShardedTopic object implements Sharded Publish / Subscribe mechanism. It allows to subscribe on events published with multiple instances of RShardedTopic object with the same name. Subscribe/publish operations are executed only on Redis node in Cluster which is bounded to specific topic name.
Published messages via RShardedTopic aren't broadcasted across all Redis nodes as for RTopic object. Which reduces network bandwidth and Redis load. Listeners are re-subscribed automatically after reconnection to Redis or Redis failover. All messages sent during absence of connection to Redis are lost. Use Reliable Topic for reliable delivery.
Code example
1 2 3 4 5 6 7 8 9 10 11
RShardedTopic topic = redisson.getShardedTopic("myTopic"); int listenerId = topic.addListener(SomeObject.class, new MessageListener<SomeObject>() { @Override public void onMessage(String channel, SomeObject message) { //... } });
// in other thread or JVM RShardedTopic topic = redisson.getShardedTopic("myTopic"); long clientsReceivedMessage = topic.publish(new SomeObject());