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:後面還須要錯誤消息堆積問題~~~
相關文章
相關標籤/搜索