@@ -54,8 +54,6 @@ public class FluxMessageChannel extends AbstractMessageChannel
54
54
55
55
private final Sinks .Many <Message <?>> sink = Sinks .many ().multicast ().onBackpressureBuffer (1 , false );
56
56
57
- private final Sinks .Many <Boolean > subscribedSignal = Sinks .many ().replay ().limit (1 );
58
-
59
57
private final Disposable .Composite upstreamSubscriptions = Disposables .composite ();
60
58
61
59
private volatile boolean active = true ;
@@ -102,19 +100,9 @@ private boolean tryEmitMessage(Message<?> message) {
102
100
@ Override
103
101
public void subscribe (Subscriber <? super Message <?>> subscriber ) {
104
102
this .sink .asFlux ()
105
- .doFinally ((s ) -> this .subscribedSignal .tryEmitNext (this .sink .currentSubscriberCount () > 0 ))
106
103
.publish (1 )
107
104
.refCount ()
108
105
.subscribe (subscriber );
109
-
110
- Mono <Boolean > subscribersBarrier =
111
- Mono .fromCallable (() -> this .sink .currentSubscriberCount () > 0 )
112
- .filter (Boolean ::booleanValue )
113
- .doOnNext (this .subscribedSignal ::tryEmitNext )
114
- .repeatWhenEmpty ((repeat ) ->
115
- this .active ? repeat .delayElements (Duration .ofMillis (100 )) : repeat ); // NOSONAR
116
-
117
- addPublisherToSubscribe (Flux .from (subscribersBarrier ));
118
106
}
119
107
120
108
private void addPublisherToSubscribe (Flux <?> publisher ) {
@@ -144,8 +132,11 @@ private void disposeUpstreamSubscription(AtomicReference<Disposable> disposableR
144
132
public void subscribeTo (Publisher <? extends Message <?>> publisher ) {
145
133
Flux <Object > upstreamPublisher =
146
134
Flux .from (publisher )
147
- .delaySubscription (this .subscribedSignal .asFlux ().filter (Boolean ::booleanValue ).next ())
148
- // .publishOn(this.scheduler)
135
+ .delaySubscription (
136
+ Mono .fromCallable (this .sink ::currentSubscriberCount )
137
+ .filter ((value ) -> value > 0 )
138
+ .repeatWhenEmpty ((repeat ) ->
139
+ this .active ? repeat .delayElements (Duration .ofMillis (100 )) : repeat ))
149
140
.flatMap ((message ) ->
150
141
Mono .just (message )
151
142
.handle ((messageToHandle , syncSink ) -> sendReactiveMessage (messageToHandle ))
@@ -180,7 +171,6 @@ private void sendReactiveMessage(Message<?> message) {
180
171
public void destroy () {
181
172
this .active = false ;
182
173
this .upstreamSubscriptions .dispose ();
183
- this .subscribedSignal .emitComplete (Sinks .EmitFailureHandler .FAIL_FAST );
184
174
this .sink .emitComplete (Sinks .EmitFailureHandler .FAIL_FAST );
185
175
super .destroy ();
186
176
}
0 commit comments