springboot rabbitmq 补充

springboot rabbitmq 补充

关于分布式环境下多listener的解答

  • topic分布式环境下,启动两个服务端,这样就至关于有两个listener,数据会不会重复读取?
    答:不会,一个消息能够扔到多个的队列,可是只要进了队列,每一个队列的消息只能被一个消费者消费

Queue和exchange的routingKey绑定与解绑的坑

  • 绑定a队列和exchange的routingkey是111,后来你又想把这个routingkey帮给b队列了,你必定要操做一下解绑的动做,你要是不操做,就会出现a队列绑定了111,b队列也绑定了111,这样按照这个routingkey发过来的数据就有两份被消费了

关于回调的AcknowledgeMode

clipboard.png

回调有以下方式,下面将分别实践spring

public enum AcknowledgeMode {
    NONE,
    MANUAL,
    AUTO;
}

关于回调官方文档上的说明springboot

NONE = no acks will be sent (incompatible with channelTransacted=true). RabbitMQ calls this "autoack" because the broker assumes all messages are acked without any action from the consumer.
MANUAL = the listener must acknowledge all messages by calling Channel.basicAck().
AUTO = the container will acknowledge the message automatically, unless the MessageListener throws an exception. Note that acknowledgeMode is complementary to channelTransacted - if the channel is transacted then the broker requires a commit notification in addition to the ack. This is the default mode. See also txSize.less

  • NONE
    能够称之为自动回调,即便无响应或者发生异常均会通知队列消费成功,会丢失数据。
  • AUTO
    自动检测异常或者超时事件,若是发生则返回noack,消息自动回到队尾,可是这种方式可能出现消息体自己有问题,返回队尾其余队列也不能消费,形成队列阻塞。
  • MANUAL手动回调,在程序中咱们能够对消息异常记性捕获,若是出现消息体格式错误问题,手动回复ack,接着再次调用发送接口把消息推到队尾。ps:后面还须要错误消息堆积问题~~~