org.springframework.data.redis.connection.ReactiveSubscription Java Examples
The following examples show how to use
org.springframework.data.redis.connection.ReactiveSubscription.
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: RedissonSubscribeReactiveTest.java From redisson with Apache License 2.0 | 6 votes |
@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(); }
Example #2
Source File: RedissonSubscribeReactiveTest.java From redisson with Apache License 2.0 | 6 votes |
@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(); }
Example #3
Source File: RedissonSubscribeReactiveTest.java From redisson with Apache License 2.0 | 6 votes |
@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(); }
Example #4
Source File: RedissonSubscribeReactiveTest.java From redisson with Apache License 2.0 | 6 votes |
@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(); }
Example #5
Source File: RedissonSubscribeReactiveTest.java From redisson with Apache License 2.0 | 6 votes |
@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(); }
Example #6
Source File: RedissonSubscribeReactiveTest.java From redisson with Apache License 2.0 | 6 votes |
@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(); }
Example #7
Source File: RedisChatMessageListener.java From spring-redis-websocket with Apache License 2.0 | 5 votes |
public Mono<Void> subscribeMessageChannelAndPublishOnWebSocket() { return reactiveStringRedisTemplate.listenTo(new PatternTopic(MESSAGE_TOPIC)) .map(ReactiveSubscription.Message::getMessage) .flatMap(message -> ObjectStringConverter.stringToObject(message, ChatMessage.class)) .filter(chatMessage -> !chatMessage.getMessage().isEmpty()) .flatMap(chatWebSocketHandler::sendMessage) .then(); }
Example #8
Source File: RedissonReactivePubSubCommands.java From redisson with Apache License 2.0 | 4 votes |
@Override public Mono<ReactiveSubscription> createSubscription() { return Mono.just(new RedissonReactiveSubscription(executorService.getConnectionManager())); }
Example #9
Source File: RedissonReactivePubSubCommands.java From redisson with Apache License 2.0 | 4 votes |
@Override public Mono<ReactiveSubscription> createSubscription() { return Mono.just(new RedissonReactiveSubscription(executorService.getConnectionManager())); }
Example #10
Source File: RedissonReactivePubSubCommands.java From redisson with Apache License 2.0 | 4 votes |
@Override public Mono<ReactiveSubscription> createSubscription() { return Mono.just(new RedissonReactiveSubscription(executorService.getConnectionManager())); }