亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

RabbitMQ:如何將失敗的消息從一個隊列移動到另一個隊列?

RabbitMQ:如何將失敗的消息從一個隊列移動到另一個隊列?

PHP
森欄 2023-10-01 15:58:48
我有兩個隊列:當我運行時同樣可見rabbitmqadmin list queues vhost name node messages message_stats.publish_details.rate -u admin -p admin:我得到:+-------+-------------------------+-------------------------+----------+------------------------------------+| vhost |          name           |          node           | messages | message_stats.publish_details.rate |+-------+-------------------------+-------------------------+----------+------------------------------------+| /     | high_priority           | rabbit@server-rabbitmq  | 5        | 0.0                                || /     | high_priority_secondary | rabbit@server-rabbitmq  | 0        | 0.0                                |+-------+-------------------------+-------------------------+----------+------------------------------------+我的交流(rabbitmqadmin -V / list exchanges -u admin -p admin)如下:+-------------------------+---------+|          name           |  type   |+-------------------------+---------+|                         | direct  || amq.direct              | direct  || amq.fanout              | fanout  || amq.headers             | headers || amq.match               | headers || amq.rabbitmq.trace      | topic   || amq.topic               | topic   || high_priority           | direct  || high_priority_secondary | direct  || low_priority            | direct  |+-------------------------+---------+隊列和整個相關邏輯是在 PHP / Symfony 中實現的,但是我想通過在終端中使用rabbitmqadmin或命令來使用本機邏輯(如果可能) 。rabbitmqctl如果消息失敗high_priority,我希望 RabbitMQ 自動將其移至隊列,high_priority_secondary而無需任何 PHP 參與。這可能嗎?我已經開始閱讀有關死信交換的內容,但我不知道如何解決這個問題。我已經為輔助隊列創建了一個消費者,因此一旦消息移動到那里,它就會被處理。僅在 CLI 中可以實現此目的嗎?僅供參考:SO 上有一些建議的帖子已經涵蓋了這個問題,但沒有一個解決方案是純粹的 CLI 解決方案。
查看完整描述

2 回答

?
largeQ

TA貢獻2039條經驗 獲得超8個贊

好吧,雖然我不必修改任何 PHP 代碼,但我確實必須更改yaml框架級別的配置,因為我希望我的解決方案得以保留并成為代碼庫的一部分。


在你的app/config/services/rabbitmq.yaml:


定義生產者:


high_priority:

    connection: default

    class: Foo\Infrastructure\RabbitMQ\SuppressedProducer

    exchange_options:

        name: 'high_priority'

        type: direct

high_priority_secondary:

    connection: default

    class: Foo\Infrastructure\RabbitMQ\SuppressedProducer

    exchange_options:

        name: 'high_priority_secondary'

        type: direct

message_hospital:

    connection: default

    class: Foo\Infrastructure\RabbitMQ\SuppressedProducer

    exchange_options:

        name: 'message_hospital'

        type: direct

定義消費者:


high_priority:

    connection: default

    exchange_options:

        name: 'high_priority'

        type: direct

    queue_options:

        name: 'high_priority'

        arguments:

            x-dead-letter-exchange: ['S', 'high_priority_secondary']

    qos_options:

        prefetch_size: 0

        prefetch_count: 1

        global: false

    callback: foo.task_bus.consumer

high_priority_secondary:

    connection: default

    exchange_options:

        name: 'high_priority_secondary'

        type: direct

    queue_options:

        name: 'high_priority_secondary'

        arguments:

            x-dead-letter-exchange: ['S', 'message_hospital']

    qos_options:

        prefetch_size: 0

        prefetch_count: 1

        global: false

    callback: foo.task_bus.consumer

message_hospital:

    connection: default

    exchange_options:

        name: 'message_hospital'

        type: direct

    queue_options:

        name: 'message_hospital'

    qos_options:

        prefetch_size: 0

        prefetch_count: 1

        global: false

    callback: foo.task_bus.consumer

現在隊列看起來像:

https://img1.sycdn.imooc.com//651926ff00016c3623740730.jpg

由于 DLX 屬性,消息一旦在之前的消息中失敗,就會立即進入醫院隊列。



查看完整回答
反對 回復 2023-10-01
?
RISEBY

TA貢獻1856條經驗 獲得超5個贊

high_priority_secondary隊列應該綁定到high_priority_secondary交換器。 high_priority隊列應該綁定到high_priority交換并且應該用 聲明x-dead-letter-exchange = high_priority_secondary。

因此隊列應該用死信交換來聲明。

要測試這一點,只需在從隊列中使用消息時通過重新排隊拒絕該消息即可high_priority。

https://img1.sycdn.imooc.com//6519271100017f8c11130379.jpg

查看完整回答
反對 回復 2023-10-01
  • 2 回答
  • 0 關注
  • 197 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號