バニー (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