@@ -314,7 +314,7 @@ void basicPublish(String exchange, String routingKey, boolean mandatory, boolean
314314 * @throws java.io.IOException if an error is encountered
315315 */
316316 default void basicPublish (String exchange , String routingKey , BasicProperties props , ByteBuffer body ) throws IOException {
317- basicPublish (exchange , routingKey , false , false , props , body );
317+ basicPublish (exchange , routingKey , false , false , props , body , null );
318318 }
319319
320320 /**
@@ -330,7 +330,7 @@ default void basicPublish(String exchange, String routingKey, BasicProperties pr
330330 */
331331 default void basicPublish (String exchange , String routingKey , boolean mandatory , BasicProperties props , ByteBuffer body )
332332 throws IOException {
333- basicPublish (exchange , routingKey , mandatory , false , props , body );
333+ basicPublish (exchange , routingKey , mandatory , false , props , body , null );
334334 }
335335
336336 /**
@@ -348,9 +348,70 @@ default void basicPublish(String exchange, String routingKey, boolean mandatory,
348348 */
349349 default void basicPublish (String exchange , String routingKey , boolean mandatory , boolean immediate , BasicProperties props , ByteBuffer body )
350350 throws IOException {
351+ basicPublish (exchange , routingKey , mandatory , immediate , props , body , null );
352+ }
353+
354+ /**
355+ * Publish a message with a {@link ByteBuffer} body and a {@link WriteListener} for
356+ * write completion notification.
357+ *
358+ * <p>The listener is called when the network layer has finished writing the body to the
359+ * socket. This is useful for off-heap buffers that must be released after the write completes.
360+ *
361+ * <p><strong>Threading:</strong> the listener may be called on the Netty event loop thread.
362+ * It must not perform blocking operations.
363+ *
364+ * @param exchange the exchange to publish the message to
365+ * @param routingKey the routing key
366+ * @param props other properties for the message - routing headers etc
367+ * @param body the message body
368+ * @param listener called when the write completes, may be {@code null}
369+ * @throws java.io.IOException if an error is encountered
370+ */
371+ default void basicPublish (String exchange , String routingKey , BasicProperties props , ByteBuffer body , WriteListener listener )
372+ throws IOException {
373+ basicPublish (exchange , routingKey , false , false , props , body , listener );
374+ }
375+
376+ /**
377+ * Publish a message with a {@link ByteBuffer} body and a {@link WriteListener} for
378+ * write completion notification.
379+ *
380+ * @param exchange the exchange to publish the message to
381+ * @param routingKey the routing key
382+ * @param mandatory true if the 'mandatory' flag is to be set
383+ * @param props other properties for the message - routing headers etc
384+ * @param body the message body
385+ * @param listener called when the write completes, may be {@code null}
386+ * @throws java.io.IOException if an error is encountered
387+ */
388+ default void basicPublish (String exchange , String routingKey , boolean mandatory , BasicProperties props , ByteBuffer body , WriteListener listener )
389+ throws IOException {
390+ basicPublish (exchange , routingKey , mandatory , false , props , body , listener );
391+ }
392+
393+ /**
394+ * Publish a message with a {@link ByteBuffer} body and a {@link WriteListener} for
395+ * write completion notification.
396+ *
397+ * @param exchange the exchange to publish the message to
398+ * @param routingKey the routing key
399+ * @param mandatory true if the 'mandatory' flag is to be set
400+ * @param immediate true if the 'immediate' flag is to be
401+ * set. Note that the RabbitMQ server does not support this flag.
402+ * @param props other properties for the message - routing headers etc
403+ * @param body the message body
404+ * @param listener called when the write completes, may be {@code null}
405+ * @throws java.io.IOException if an error is encountered
406+ */
407+ default void basicPublish (String exchange , String routingKey , boolean mandatory , boolean immediate , BasicProperties props , ByteBuffer body , WriteListener listener )
408+ throws IOException {
351409 byte [] bytes = new byte [body .remaining ()];
352410 body .get (bytes );
353411 basicPublish (exchange , routingKey , mandatory , immediate , props , bytes );
412+ if (listener != null ) {
413+ listener .done (true , null );
414+ }
354415 }
355416
356417 /**
0 commit comments