本文整理汇总了Java中org.redisson.api.RedissonClient.getTopic方法的典型用法代码示例。如果您正苦于以下问题:Java RedissonClient.getTopic方法的具体用法?Java RedissonClient.getTopic怎么用?Java RedissonClient.getTopic使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.redisson.api.RedissonClient
的用法示例。
在下文中一共展示了RedissonClient.getTopic方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: main
import org.redisson.api.RedissonClient; //导入方法依赖的package包/类
public static void main(String[] args) throws InterruptedException {
// connects to 127.0.0.1:6379 by default
RedissonClient redisson = Redisson.create();
CountDownLatch latch = new CountDownLatch(1);
RTopic<String> topic = redisson.getTopic("topic2");
topic.addListener(new MessageListener<String>() {
@Override
public void onMessage(String channel, String msg) {
latch.countDown();
}
});
topic.publish("msg");
latch.await();
redisson.shutdown();
}
示例2: RedisBroadcastChannel
import org.redisson.api.RedissonClient; //导入方法依赖的package包/类
/**
* Builds a Broadcastchannel that knows how to communicate with Redis.
*
* @param redissonClient The client to use to communicate with Redis
*/
public RedisBroadcastChannel(RedissonClient redissonClient) {
this.topic = redissonClient.getTopic(REDIS_CHANNEL);
this.notifications = PublishSubject.create();
this.topicReadWriteLock = new ReentrantReadWriteLock();
listenerId = topic.addListener((channel, msg) -> { notifications.onNext(msg); });
}