FluxMessageChannel.send: no subscribers assertion
This commit is contained in:
@@ -25,6 +25,7 @@ import org.reactivestreams.Publisher;
|
||||
import org.reactivestreams.Subscriber;
|
||||
|
||||
import org.springframework.messaging.Message;
|
||||
import org.springframework.util.Assert;
|
||||
|
||||
import reactor.core.publisher.ConnectableFlux;
|
||||
import reactor.core.publisher.Flux;
|
||||
@@ -59,6 +60,7 @@ public class FluxMessageChannel extends AbstractMessageChannel
|
||||
|
||||
@Override
|
||||
protected boolean doSend(Message<?> message, long timeout) {
|
||||
Assert.state(subscribers.size() > 0, () -> "The [" + this + "] doesn't have subscribers to accept messages");
|
||||
this.sink.next(message);
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -16,6 +16,7 @@
|
||||
|
||||
package org.springframework.integration.channel.reactive;
|
||||
|
||||
import static org.hamcrest.Matchers.containsString;
|
||||
import static org.hamcrest.Matchers.equalTo;
|
||||
import static org.hamcrest.Matchers.instanceOf;
|
||||
import static org.junit.Assert.assertSame;
|
||||
@@ -259,4 +260,16 @@ public class ReactiveStreamsConsumerTests {
|
||||
assertThat(result, Matchers.<Message<?>>contains(testMessage, testMessage2, testMessage2));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFluxMessageChannelSendWithoutSubscription() {
|
||||
try {
|
||||
new FluxMessageChannel().send(new GenericMessage<>("foo"));
|
||||
}
|
||||
catch (Exception e) {
|
||||
assertThat(e, instanceOf(MessageDeliveryException.class));
|
||||
assertThat(e.getCause(), instanceOf(IllegalStateException.class));
|
||||
assertThat(e.getMessage(), containsString("doesn't have subscribers to accept messages"));
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user