tx7do / kratos-transport

kratos transport layer extension
MIT License
348 stars 95 forks source link

rabbitmq 生产者是否可以提供声明与绑定交换机队列功能?? 支持死信与延迟消息功能 #13

Closed shuqingzai closed 2 years ago

shuqingzai commented 2 years ago

目前声明或绑定交换机与队列都只能在消费端,生产端没有选项,没法实现 ttl 延时队列的功能,消费端绑定就会消费掉数据,希望可以添加选项,生产端可以选择绑定,实现死信与延迟消息功能

NekoParap commented 9 months ago

消费者应该如何绑定延迟交换机?

NekoParap commented 9 months 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(),
        ),
    )

执行后建不出延迟交换机,errorPRECONDITION_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"},
    )