DATAREDIS-1053 - Subscribe to cleanup publishers when canceling a listenTo() stream.
Cleanup publishers are now subscribed to instead of setting the subscribeOn Scheduler to ensure connections get closed after canceling the stream. Original Pull Request: #488
This commit is contained in:
committed by
Christoph Strobl
parent
f2bdeff048
commit
6851186cf2
@@ -235,7 +235,7 @@ public class ReactiveRedisTemplate<K, V> implements ReactiveRedisOperations<K, V
|
||||
return container
|
||||
.receive(Arrays.asList(topics), getSerializationContext().getStringSerializationPair(),
|
||||
getSerializationContext().getValueSerializationPair()) //
|
||||
.doFinally((signalType) -> container.destroyLater().subscribeOn(Schedulers.elastic()));
|
||||
.doFinally((signalType) -> container.destroyLater().subscribe());
|
||||
}
|
||||
|
||||
// -------------------------------------------------------------------------
|
||||
|
||||
@@ -18,7 +18,6 @@ package org.springframework.data.redis.listener;
|
||||
import reactor.core.publisher.Flux;
|
||||
import reactor.core.publisher.Mono;
|
||||
import reactor.core.publisher.MonoProcessor;
|
||||
import reactor.core.scheduler.Schedulers;
|
||||
|
||||
import java.nio.ByteBuffer;
|
||||
import java.util.Arrays;
|
||||
@@ -97,6 +96,12 @@ public class ReactiveRedisMessageListenerContainer implements DisposableBean {
|
||||
* @return the {@link Mono} signalling container termination.
|
||||
*/
|
||||
public Mono<Void> destroyLater() {
|
||||
return Mono.defer(this::doDestroy);
|
||||
}
|
||||
|
||||
private Mono<Void> doDestroy() {
|
||||
|
||||
ReactiveRedisConnection connection = this.connection;
|
||||
|
||||
if (connection != null) {
|
||||
|
||||
@@ -116,12 +121,8 @@ public class ReactiveRedisMessageListenerContainer implements DisposableBean {
|
||||
}
|
||||
}
|
||||
|
||||
if (terminationSignals != null) {
|
||||
return terminationSignals.collectList()
|
||||
.doFinally(signalType -> connection.closeLater().subscribeOn(Schedulers.immediate()))
|
||||
.flatMap(all -> Mono.empty());
|
||||
}
|
||||
this.connection = null;
|
||||
return terminationSignals != null ? terminationSignals.then(connection.closeLater()) : connection.closeLater();
|
||||
}
|
||||
|
||||
return Mono.empty();
|
||||
@@ -344,7 +345,7 @@ public class ReactiveRedisMessageListenerContainer implements DisposableBean {
|
||||
|
||||
/**
|
||||
* Unregister a subscriber and decrement subscriber count.
|
||||
*
|
||||
*
|
||||
* @return {@literal true} if this was the last unregistered subscriber.
|
||||
*/
|
||||
boolean unregister() {
|
||||
|
||||
Reference in New Issue
Block a user