use of org.springframework.data.redis.connection.ReactiveSubscription in project redisson by redisson.
the class RedissonSubscribeReactiveTest method testUnSubscribe.
@Test
public void testUnSubscribe() {
RedissonConnectionFactory factory = new RedissonConnectionFactory(redisson);
ReactiveRedisConnection connection = factory.getReactiveConnection();
Mono<ReactiveSubscription> s = connection.pubSubCommands().createSubscription();
AtomicReference<byte[]> msg = new AtomicReference<byte[]>();
ReactiveSubscription ss = s.block();
ss.subscribe(ByteBuffer.wrap("test".getBytes())).block();
ss.receive().doOnEach(message -> {
msg.set(message.get().getMessage().array());
}).subscribe();
connection.pubSubCommands().publish(ByteBuffer.wrap("test".getBytes()), ByteBuffer.wrap("msg".getBytes())).block();
Awaitility.await().atMost(Duration.ONE_SECOND).until(() -> Arrays.equals("msg".getBytes(), msg.get()));
ss.unsubscribe();
connection.pubSubCommands().publish(ByteBuffer.wrap("test".getBytes()), ByteBuffer.wrap("msg".getBytes())).block();
}
use of org.springframework.data.redis.connection.ReactiveSubscription in project redisson by redisson.
the class RedissonSubscribeReactiveTest method testSubscribe.
@Test
public void testSubscribe() {
RedissonConnectionFactory factory = new RedissonConnectionFactory(redisson);
ReactiveRedisConnection connection = factory.getReactiveConnection();
Mono<ReactiveSubscription> s = connection.pubSubCommands().createSubscription();
AtomicReference<byte[]> msg = new AtomicReference<byte[]>();
ReactiveSubscription ss = s.block();
ss.subscribe(ByteBuffer.wrap("test".getBytes())).block();
ss.receive().doOnEach(message -> {
msg.set(message.get().getMessage().array());
}).subscribe();
connection.pubSubCommands().publish(ByteBuffer.wrap("test".getBytes()), ByteBuffer.wrap("msg".getBytes())).block();
Awaitility.await().atMost(Duration.ONE_SECOND).until(() -> Arrays.equals("msg".getBytes(), msg.get()));
ss.unsubscribe();
connection.pubSubCommands().publish(ByteBuffer.wrap("test".getBytes()), ByteBuffer.wrap("msg".getBytes())).block();
}
Aggregations