Use Mono.create instead of Mono.fromCallable
It is better to poll message from `QueueChannel` when ever a reactive request happens. The `Mono.fromCallable()` operator does poll on subscription, not request and caches the value. However we may lose such a value in between. * Use `Mono.create()` with its `monoSink.onRequest()` callback in the `adaptPollableChannelToPublisher()` implementation to defer `inputChannel.receive()` until an on demand request downstream
This commit is contained in:
@@ -73,7 +73,9 @@ public final class MessageChannelReactiveUtils {
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
private static <T> Publisher<Message<T>> adaptPollableChannelToPublisher(PollableChannel inputChannel) {
|
||||
return Mono.fromCallable(() -> (Message<T>) inputChannel.receive(0))
|
||||
return Mono.<Message<T>>create(monoSink ->
|
||||
monoSink.onRequest(value ->
|
||||
monoSink.success((Message<T>) inputChannel.receive(0))))
|
||||
.subscribeOn(Schedulers.boundedElastic())
|
||||
.repeatWhenEmpty(it -> it.delayElements(Duration.ofMillis(100))) // NOSONAR - magic
|
||||
.repeat();
|
||||
|
||||
Reference in New Issue
Block a user