Search in sources :

Example 1 with RTopicReactive

use of org.redisson.api.RTopicReactive in project redisson by redisson.

the class RedissonTopicReactiveTest method testRemoveListenerById.

@Test
public void testRemoveListenerById() throws InterruptedException {
    RTopicReactive topic1 = redisson.getTopic("topic1");
    MessageListener listener = new MessageListener() {

        @Override
        public void onMessage(CharSequence channel, Object msg) {
            Assertions.fail();
        }
    };
    Mono<Integer> res = topic1.addListener(Message.class, listener);
    Integer listenerId = res.block();
    topic1 = redisson.getTopic("topic1");
    topic1.removeListener(listenerId);
    topic1.publish(new Message("123"));
}
Also used : MessageListener(org.redisson.api.listener.MessageListener) RTopicReactive(org.redisson.api.RTopicReactive) Test(org.junit.jupiter.api.Test)

Example 2 with RTopicReactive

use of org.redisson.api.RTopicReactive in project redisson by redisson.

the class RedissonTopicReactiveTest method testLong.

@Test
public void testLong() throws InterruptedException {
    RTopicReactive topic = redisson.getTopic("test");
    Flux<String> messages = topic.getMessages(String.class);
    List<String> list = new ArrayList<>();
    messages.subscribe(new Subscriber<String>() {

        @Override
        public void onSubscribe(Subscription s) {
            s.request(10);
        }

        @Override
        public void onNext(String t) {
            list.add(t);
        }

        @Override
        public void onError(Throwable t) {
        }

        @Override
        public void onComplete() {
        }
    });
    for (int i = 0; i < 15; i++) {
        sync(topic.publish("" + i));
    }
    assertThat(list).containsExactly("0", "1", "2", "3", "4", "5", "6", "7", "8", "9");
}
Also used : ArrayList(java.util.ArrayList) Subscription(org.reactivestreams.Subscription) RTopicReactive(org.redisson.api.RTopicReactive) Test(org.junit.jupiter.api.Test)

Example 3 with RTopicReactive

use of org.redisson.api.RTopicReactive in project redisson by redisson.

the class RedissonTopicReactiveTest method testRemoveListenerByInstance.

@Test
public void testRemoveListenerByInstance() throws InterruptedException {
    RTopicReactive topic1 = redisson.getTopic("topic1");
    MessageListener listener = new MessageListener() {

        @Override
        public void onMessage(CharSequence channel, Object msg) {
            Assertions.fail();
        }
    };
    topic1.addListener(Message.class, listener).block();
    topic1 = redisson.getTopic("topic1");
    topic1.removeListener(listener);
    topic1.publish(new Message("123"));
}
Also used : MessageListener(org.redisson.api.listener.MessageListener) RTopicReactive(org.redisson.api.RTopicReactive) Test(org.junit.jupiter.api.Test)

Aggregations

Test (org.junit.jupiter.api.Test)3 RTopicReactive (org.redisson.api.RTopicReactive)3 MessageListener (org.redisson.api.listener.MessageListener)2 ArrayList (java.util.ArrayList)1 Subscription (org.reactivestreams.Subscription)1