Caching and messaging

RabbitMQ basicReject

Reject without requeue; route to configured DLX or discard. Source-reviewed integration fragment or manual procedure, NOT RUN.

Formal Syntax & Structure

java syntaxjava
channel.basicReject(deliveryTag, false)

Working Example

Example Snippetjava
// Fragment: channel has a bounded prefetch; queue and DLX provisioned by lab owner.// Invoke on the channel owner. An exception stops this consumer; close channel to requeue.import com.rabbitmq.client.Channel;import com.rabbitmq.client.Delivery;import java.io.IOException;import java.util.function.Consumer;public class RabbitDelivery {    public static void handle(Channel channel, Delivery delivery,                              Consumer<byte[]> durableApply) throws IOException {        byte[] body = delivery.getBody();        if (body.length == 0 || body.length > 4096) {            channel.basicReject(delivery.getEnvelope().getDeliveryTag(), false);            return; // requires configured dead-letter routing, otherwise discarded        }        durableApply.accept(body);        channel.basicAck(delivery.getEnvelope().getDeliveryTag(), false);    }}
Java Reference