|
16 | 16 |
|
17 | 17 | package org.springframework.integration.channel;
|
18 | 18 |
|
| 19 | +import java.time.Duration; |
| 20 | + |
19 | 21 | import org.reactivestreams.Publisher;
|
20 |
| -import org.reactivestreams.Subscriber; |
21 | 22 |
|
22 | 23 | import org.springframework.messaging.Message;
|
23 | 24 | import org.springframework.messaging.MessageChannel;
|
|
27 | 28 |
|
28 | 29 | import reactor.core.publisher.EmitterProcessor;
|
29 | 30 | import reactor.core.publisher.Flux;
|
| 31 | +import reactor.core.publisher.Mono; |
30 | 32 | import reactor.core.scheduler.Schedulers;
|
31 | 33 |
|
32 | 34 | /**
|
@@ -69,34 +71,12 @@ private static <T> Publisher<Message<T>> adaptSubscribableChannelToPublisher(Sub
|
69 | 71 | });
|
70 | 72 | }
|
71 | 73 |
|
| 74 | + @SuppressWarnings("unchecked") |
72 | 75 | private static <T> Publisher<Message<T>> adaptPollableChannelToPublisher(PollableChannel inputChannel) {
|
73 |
| - return new PollableChannelPublisherAdapter<>(inputChannel); |
74 |
| - } |
75 |
| - |
76 |
| - private static final class PollableChannelPublisherAdapter<T> implements Publisher<Message<T>> { |
77 |
| - |
78 |
| - private final PollableChannel channel; |
79 |
| - |
80 |
| - PollableChannelPublisherAdapter(final PollableChannel channel) { |
81 |
| - this.channel = channel; |
82 |
| - } |
83 |
| - |
84 |
| - @Override |
85 |
| - @SuppressWarnings("unchecked") |
86 |
| - public void subscribe(Subscriber<? super Message<T>> subscriber) { |
87 |
| - Flux |
88 |
| - .<Message<T>>create(sink -> |
89 |
| - sink.onRequest(n -> { |
90 |
| - Message<?> m; |
91 |
| - while (!sink.isCancelled() && n-- > 0 |
92 |
| - && (m = this.channel.receive()) != null) { // NOSONAR |
93 |
| - sink.next((Message<T>) m); |
94 |
| - } |
95 |
| - })) |
96 |
| - .subscribeOn(Schedulers.elastic()) |
97 |
| - .subscribe(subscriber); |
98 |
| - } |
99 |
| - |
| 76 | + return Mono.fromCallable(() -> (Message<T>) inputChannel.receive()) |
| 77 | + .subscribeOn(Schedulers.boundedElastic()) |
| 78 | + .repeatWhenEmpty(it -> it.delayElements(Duration.ofMillis(10))) |
| 79 | + .repeat(); |
100 | 80 | }
|
101 | 81 |
|
102 | 82 | }
|
0 commit comments