Source:
<code>public Mono<Message> sendWithAck(final Message message) { if (isDisposed()) { return Mono.error(logger.logExceptionAsError(new IllegalStateException( "Cannot send a message when request response channel is disposed."))); } if (message == null) { <START> return Mono.error(logger.logExceptionAsError(new NullPointerException("message cannot be null"))); <END> } if (message.getMessageId() != null) { return Mono.error(logger.logExceptionAsError( new IllegalArgumentException("message.getMessageId() should be null"))); } if (message.getReplyTo() != null) { return Mono.error(logger.logExceptionAsError( new IllegalArgumentException("message.getReplyTo() should be null"))); } final UnsignedLong messageId = UnsignedLong.valueOf(requestId.incrementAndGet()); message.setMessageId(messageId); message.setReplyTo(replyTo); return RetryUtil.withRetry( Mono.when(sendLinkHandler.getEndpointStates().takeUntil(x -> x == EndpointState.ACTIVE), receiveLinkHandler.getEndpointStates().takeUntil(x -> x == EndpointState.ACTIVE)), operationTimeout, retryPolicy) .then( Mono.create(sink -> { try { logger.verbose("Scheduling on dispatcher. Message Id {}", messageId); unconfirmedSends.putIfAbsent(messageId, sink); provider.getReactorDispatcher().invoke(() -> { sendLink.delivery(UUID.randomUUID().toString() .replace("-", "").getBytes(UTF_8)); final int payloadSize = messageSerializer.getSize(message) + ClientConstants.MAX_AMQP_HEADER_SIZE_BYTES; final byte[] bytes = new byte[payloadSize]; final int encodedSize = message.encode(bytes, 0, payloadSize); receiveLink.flow(1); sendLink.send(bytes, 0, encodedSize); sendLink.advance(); }); } catch (IOException e) { sink.error(e); } })); }</code><technical_language>nit: FluxUtil in azure-core monoError static helper log return errors</technical_language>

Target:
public Mono<Message> sendWithAck(final Message message) { if (isDisposed()) { return monoError(logger, new IllegalStateException( "Cannot send a message when request response channel is disposed.")); } if (message == null) { return monoError(logger, new NullPointerException("message cannot be null")); } if (message.getMessageId() != null) { return monoError(logger, new IllegalArgumentException("message.getMessageId() should be null")); } if (message.getReplyTo() != null) { return monoError(logger, new IllegalArgumentException("message.getReplyTo() should be null")); } final UnsignedLong messageId = UnsignedLong.valueOf(requestId.incrementAndGet()); message.setMessageId(messageId); message.setReplyTo(replyTo); return RetryUtil.withRetry( Mono.when(sendLinkHandler.getEndpointStates().takeUntil(x -> x == EndpointState.ACTIVE), receiveLinkHandler.getEndpointStates().takeUntil(x -> x == EndpointState.ACTIVE)), operationTimeout, retryPolicy) .then( Mono.create(sink -> { try { logger.verbose("Scheduling on dispatcher. Message Id {}", messageId); unconfirmedSends.putIfAbsent(messageId, sink); provider.getReactorDispatcher().invoke(() -> { sendLink.delivery(UUID.randomUUID().toString() .replace("-", "").getBytes(UTF_8)); final int payloadSize = messageSerializer.getSize(message) + ClientConstants.MAX_AMQP_HEADER_SIZE_BYTES; final byte[] bytes = new byte[payloadSize]; final int encodedSize = message.encode(bytes, 0, payloadSize); receiveLink.flow(1); sendLink.send(bytes, 0, encodedSize); sendLink.advance(); }); } catch (IOException e) { sink.error(e); } })); }