2 回答
TA贡献2039条经验 获得超7个赞
好吧,虽然我不必修改任何 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 关注
- 146 浏览
添加回答
举报