天天看點

【RabbitMQ 之自定義消費者與消費端的限流機制】

1、通過繼承DefaultConsumer

public class MyConsumer extends DefaultConsumer {
    private Channel channel;
    public MyConsumer(Channel channel) {
        super(channel);
        this.channel = channel;
    }

    /**
     * 重寫此方法
     * @param consumerTag
     * @param envelope
     * @param properties
     * @param body
     * @throws IOException
     */
    @Override
    public void handleDelivery(String consumerTag, Envelope envelope, AMQP.BasicProperties properties, byte[] body) throws IOException {
        //實作自己的業務邏輯
    }
}
           
【RabbitMQ 之自定義消費者與消費端的限流機制】