Closed shuqingzai closed 2 years ago
消费者应该如何绑定延迟交换机?
新建延迟交换机:
srv := rabbitmq.NewServer(
rabbitmq.WithAddress([]string{"xxxx"}),
rabbitmq.WithExchange("delay_exchange", true),
rabbitmq.WithBrokerOptions(
brokerrabbitmq.WithExchangeName("delay_exchange"),
brokerrabbitmq.WithExchangeType("x-delayed-message"),
brokerrabbitmq.WithDurableExchange(),
),
)
执行后建不出延迟交换机,error为 PRECONDITION_FAILED - Invalid argument, 'x-delayed-type' must be an existing exchange type
。需要在 ExchangeDeclare
时需要传入 args 参数,参考 https://github.com/rabbitmq/rabbitmq-delayed-message-exchange/issues/19 。
暂时只能手动新建交换机了:
ch.ExchangeDeclare(
"delay_exchange",
"x-delayed-message",
true,
false,
false,
false,
amqp.Table{"x-delayed-type": "topic"},
)
目前声明或绑定交换机与队列都只能在消费端,生产端没有选项,没法实现 ttl 延时队列的功能,消费端绑定就会消费掉数据,希望可以添加选项,生产端可以选择绑定,实现死信与延迟消息功能