Java Code Examples for org.redisson.api.RTopic#removeAllListeners()

The following examples show how to use org.redisson.api.RTopic#removeAllListeners() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: RedissonTopicTest.java    From redisson with Apache License 2.0 6 votes vote down vote up
@Test
public void testRemoveAllListeners() throws InterruptedException {
    RedissonClient redisson = BaseTest.createInstance();
    RTopic topic1 = redisson.getTopic("topic1");
    AtomicInteger counter = new AtomicInteger();
    
    for (int i = 0; i < 10; i++) {
        topic1.addListener(Message.class, (channel, msg) -> {
            counter.incrementAndGet();
        });
    }

    topic1 = redisson.getTopic("topic1");
    topic1.removeAllListeners();
    topic1.publish(new Message("123"));

    Thread.sleep(1000);
    assertThat(counter.get()).isZero();
    
    redisson.shutdown();
}
 
Example 2
Source File: RedissonTopicTest.java    From redisson with Apache License 2.0 6 votes vote down vote up
@Test
public void testRemoveAllListeners2() throws InterruptedException {
    RedissonClient redisson = BaseTest.createInstance();
    RTopic topic1 = redisson.getTopic("topic1");
    AtomicInteger counter = new AtomicInteger();
    
    for (int j = 0; j < 100; j++) {
        for (int i = 0; i < 10; i++) {
            topic1.addListener(Message.class, (channel, msg) -> {
                counter.incrementAndGet();
            });
        }
        
        topic1 = redisson.getTopic("topic1");
        topic1.removeAllListeners();
        topic1.publish(new Message("123"));
    }

    Thread.sleep(1000);
    assertThat(counter.get()).isZero();
    
    redisson.shutdown();
}
 
Example 3
Source File: RedisPlayground.java    From synapse with Apache License 2.0 5 votes vote down vote up
@Test
public void shouldRetrieveMessagesFromTopic() {
    RTopic topic = redisson.getTopic("test-topic");
    topic.addListener(String.class, (channel, message) -> {
        LOG.info("Received message={} from channel={}", message, channel);
    });
    topic.publish("some message");
    topic.removeAllListeners();
}