0
将RabbitMQ与Bunny(Ruby)结合使用,我想发布并希望避免在扇出交换中不消耗队列时丢失消息。从我的图书馆角度来看,如果邮件发送与否,我愿意等待回复,并给予客户明确的答复。是在这个睡觉,实现这一目标的唯一途径?等待RabbitMQ强制发布?
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