2 回答

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
現在隊列看起來像:
由于 DLX 屬性,消息一旦在之前的消息中失敗,就會立即進入醫院隊列。

TA貢獻1856條經驗 獲得超5個贊
high_priority_secondary
隊列應該綁定到high_priority_secondary
交換器。 high_priority
隊列應該綁定到high_priority
交換并且應該用 聲明x-dead-letter-exchange = high_priority_secondary
。
因此隊列應該用死信交換來聲明。
要測試這一點,只需在從隊列中使用消息時通過重新排隊拒絕該消息即可high_priority
。
- 2 回答
- 0 關注
- 197 瀏覽
添加回答
舉報