Search in sources :

Example 1 with RTopicRx

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

the class RedissonTopicRxTest method testRemoveListenerByInstance.

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

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

Example 2 with RTopicRx

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

the class RedissonTopicRxTest method testRemoveListenerById.

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

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

Example 3 with RTopicRx

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

the class RedissonTopicRxTest method testLong.

@Test
public void testLong() throws InterruptedException {
    RTopicRx topic = redisson.getTopic("test");
    Flowable<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));
    }
    Awaitility.waitAtMost(Duration.ofSeconds(10)).until(() -> list.equals(Arrays.asList("0", "1", "2", "3", "4", "5", "6", "7", "8", "9")));
}
Also used : RTopicRx(org.redisson.api.RTopicRx) ArrayList(java.util.ArrayList) Subscription(org.reactivestreams.Subscription) Test(org.junit.jupiter.api.Test)

Aggregations

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