Subscribe to Publisher in the NullChannel (#3448)

* Subscribe to Publisher in the NullChannel

If a payload of the message in the flow is a `org.reactivestreams.Publisher`,
it must be subscribed somewhere downstream to initiate reactive processing.
The `NullChannel` just ignores the message altogether and therefore `Publisher`
is lost

* Check the payload of the message in the `NullChannel` for `Publisher` type
and subscribe to it
* Verify in the test and mention this logic in the docs

**Cherry-pick to 5.4.x**

* Apply suggestions from code review

Co-authored-by: Gary Russell <grussell@vmware.com>

Co-authored-by: Gary Russell <grussell@vmware.com>
This commit is contained in:
Artem Bilan
2020-12-22 12:20:12 -05:00
committed by GitHub
parent ad57c6187a
commit c38da2f4ee
3 changed files with 50 additions and 5 deletions

View File

@@ -19,6 +19,8 @@ package org.springframework.integration.channel;
import static org.assertj.core.api.Assertions.assertThat;
import java.time.Duration;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicInteger;
import org.junit.jupiter.api.Test;
@@ -28,6 +30,7 @@ import org.springframework.messaging.support.GenericMessage;
import reactor.core.Disposable;
import reactor.core.Disposables;
import reactor.core.publisher.Mono;
import reactor.core.scheduler.Schedulers;
import reactor.test.StepVerifier;
import reactor.util.concurrent.Queues;
@@ -104,4 +107,13 @@ class MessageChannelReactiveUtilsTests {
.isLessThanOrEqualTo(Queues.SMALL_BUFFER_SIZE);
}
@Test
void testPublisherPayloadWithNullChannel() throws InterruptedException {
NullChannel nullChannel = new NullChannel();
CountDownLatch publisherSubscribed = new CountDownLatch(1);
Mono<Object> mono = Mono.empty().doOnSubscribe((s) -> publisherSubscribed.countDown());
nullChannel.send(new GenericMessage<>(mono));
assertThat(publisherSubscribed.await(10, TimeUnit.SECONDS)).isTrue();
}
}