天天看点

【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 之自定义消费者与消费端的限流机制】