@@ -113,8 +113,9 @@ public Mono<Void> send(Publisher<OutboundMessage> messages, SendOptions options)
113113 // TODO using a pool of channels?
114114 // would be much more efficient if send is called very often
115115 // less useful if seldom called, only for long or infinite message flux
116- final Mono <? extends Channel > currentChannelMono = getChannelMono ();
116+ final Mono <? extends Channel > currentChannelMono = getChannelMono (options );
117117 final BiConsumer <SendContext , Exception > exceptionHandler = options .getExceptionHandler ();
118+ final BiConsumer <SignalType , Channel > channelCloseHandler = getChannelCloseHandler (options );
118119
119120 return currentChannelMono .flatMapMany (channel ->
120121 Flux .from (messages )
@@ -143,7 +144,8 @@ public Flux<OutboundMessageResult> sendWithPublishConfirms(Publisher<OutboundMes
143144 // TODO using a pool of channels?
144145 // would be much more efficient if send is called very often
145146 // less useful if seldom called, only for long or infinite message flux
146- final Mono <? extends Channel > currentChannelMono = getChannelMono ();
147+ final Mono <? extends Channel > currentChannelMono = getChannelMono (options );
148+ final BiConsumer <SignalType , Channel > channelCloseHandler = getChannelCloseHandler (options );
147149
148150 return currentChannelMono .map (channel -> {
149151 try {
@@ -156,8 +158,15 @@ public Flux<OutboundMessageResult> sendWithPublishConfirms(Publisher<OutboundMes
156158 .flatMapMany (channel -> new PublishConfirmOperator (messages , channel , channelCloseHandler , options ));
157159 }
158160
159- private Mono <? extends Channel > getChannelMono () {
160- return channelMono != null ? channelMono : connectionMono .map (CHANNEL_CREATION_FUNCTION );
161+ private Mono <? extends Channel > getChannelMono (SendOptions options ) {
162+ return Stream .of (options .getChannelMono (), channelMono )
163+ .filter (Objects ::nonNull )
164+ .findFirst ().orElse (connectionMono .map (CHANNEL_CREATION_FUNCTION ));
165+ }
166+
167+ private BiConsumer <SignalType , Channel > getChannelCloseHandler (SendOptions options ) {
168+ return options .getChannelCloseHandler () != null ?
169+ options .getChannelCloseHandler () : this .channelCloseHandler ;
161170 }
162171
163172 public RpcClient rpcClient (String exchange , String routingKey ) {
0 commit comments