【发布时间】: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