|
1 | 1 | /*
|
2 |
| - * Copyright 2016-2022 the original author or authors. |
| 2 | + * Copyright 2016-2024 the original author or authors. |
3 | 3 | *
|
4 | 4 | * Licensed under the Apache License, Version 2.0 (the "License");
|
5 | 5 | * you may not use this file except in compliance with the License.
|
|
34 | 34 | import reactor.core.Disposable;
|
35 | 35 | import reactor.core.publisher.Flux;
|
36 | 36 | import reactor.core.scheduler.Schedulers;
|
| 37 | +import reactor.test.StepVerifier; |
37 | 38 |
|
38 | 39 | import org.springframework.beans.factory.annotation.Autowired;
|
39 | 40 | import org.springframework.beans.factory.annotation.Qualifier;
|
|
45 | 46 | import org.springframework.integration.config.EnableIntegration;
|
46 | 47 | import org.springframework.integration.dsl.IntegrationFlow;
|
47 | 48 | import org.springframework.integration.dsl.MessageChannels;
|
| 49 | +import org.springframework.integration.dsl.MessageProducerSpec; |
48 | 50 | import org.springframework.integration.dsl.context.IntegrationFlowContext;
|
49 | 51 | import org.springframework.integration.endpoint.AbstractEndpoint;
|
| 52 | +import org.springframework.integration.endpoint.MessageProducerSupport; |
| 53 | +import org.springframework.integration.endpoint.ReactiveMessageSourceProducer; |
50 | 54 | import org.springframework.integration.endpoint.ReactiveStreamsConsumer;
|
51 | 55 | import org.springframework.messaging.Message;
|
52 | 56 | import org.springframework.messaging.MessageChannel;
|
@@ -240,6 +244,27 @@ void fixedSubscriberChannelFlowTest() throws InterruptedException {
|
240 | 244 | assertThat(latch.await(10, TimeUnit.SECONDS)).isTrue();
|
241 | 245 | }
|
242 | 246 |
|
| 247 | + @Autowired |
| 248 | + MessageProducerSupport testMessageProducer; |
| 249 | + |
| 250 | + @Autowired |
| 251 | + Publisher<Message<String>> messageProducerFlow; |
| 252 | + |
| 253 | + @Test |
| 254 | + void messageProducerIsNotStartedAutomatically() { |
| 255 | + assertThat(this.testMessageProducer.isRunning()).isFalse(); |
| 256 | + |
| 257 | + Flux<String> flux = |
| 258 | + Flux.from(this.messageProducerFlow) |
| 259 | + .map(Message::getPayload); |
| 260 | + |
| 261 | + StepVerifier.create(flux) |
| 262 | + .expectNext("test") |
| 263 | + .expectNext("test") |
| 264 | + .thenCancel() |
| 265 | + .verify(Duration.ofSeconds(10)); |
| 266 | + } |
| 267 | + |
243 | 268 | @Configuration
|
244 | 269 | @EnableIntegration
|
245 | 270 | public static class ContextConfiguration {
|
@@ -285,6 +310,26 @@ public Publisher<Message<String>> fixedSubscriberChannelFlow() {
|
285 | 310 | .toReactivePublisher();
|
286 | 311 | }
|
287 | 312 |
|
| 313 | + @Bean |
| 314 | + public Publisher<Message<String>> messageProducerFlow() { |
| 315 | + TestMessageProducerSpec testMessageProducerSpec = |
| 316 | + new TestMessageProducerSpec(new ReactiveMessageSourceProducer(() -> new GenericMessage<>("test"))) |
| 317 | + .id("testMessageProducer"); |
| 318 | + |
| 319 | + return IntegrationFlow |
| 320 | + .from(testMessageProducerSpec) |
| 321 | + .toReactivePublisher(true); |
| 322 | + } |
| 323 | + |
| 324 | + } |
| 325 | + |
| 326 | + private static class TestMessageProducerSpec |
| 327 | + extends MessageProducerSpec<TestMessageProducerSpec, ReactiveMessageSourceProducer> { |
| 328 | + |
| 329 | + TestMessageProducerSpec(ReactiveMessageSourceProducer producer) { |
| 330 | + super(producer); |
| 331 | + } |
| 332 | + |
288 | 333 | }
|
289 | 334 |
|
290 | 335 | }
|
0 commit comments