【问题标题】:Waiting for RabbitMQ mandatory publish?等待 RabbitMQ 强制发布?
【发布时间】:2014-10-07 03:55:56
【问题描述】:

将 RabbitMQ 与 Bunny (Ruby) 一起使用,我想发布并希望避免在没有队列消耗来自 fanout 交换的情况下丢失消息。从我图书馆的角度来看,我愿意等待返回,如果消息已发送,我会向客户给出明确的答复。这是实现这一目标的唯一方法吗?

def publish(topic, message_type, message, key = nil)
    ch = @conn.create_channel
    exchange = ch.fanout(topic, :durable => true, :auto_delete => false)

    sent = true
    exchange.on_return do |return_info, properties, content|
        sent = false
    end

    exchange.publish(message,
        :mandatory => true,
        :persistent => true,
        :type => message_type,
        :app_id => Emque::Producing.configuration.app_name,
        :content_type => "application/json")

    # Give message a chance to return if it can't be routed
    sleep 0.5

    ch.close
    return sent
end

【问题讨论】:

    标签: rabbitmq messaging amqp bunny


    【解决方案1】:

    basic.return 是协议中的异步操作。您可以使用同步原语(例如,Bunny 具有 Concurrent::Condition,因为 Ruby 缺少与 java.util.concurrent 非常相似的任何内容),但您真正想要的是发布者确认。请参阅“何时确认消息?”在http://www.rabbitmq.com/confirms.html

    【讨论】:

      猜你喜欢
      • 2012-04-09
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-02-16
      • 2018-12-14
      • 2020-10-30
      相关资源
      最近更新 更多