0

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

1 に答える 1

0

basic.return は、プロトコルの非同期操作です。同期プリミティブを使用できます (たとえば、Ruby には java.util.concurrent とはかけ離れたものがないため、Bunny には Concurrent::Condition があります) が、本当に必要なのは発行者の確認です。「メッセージはいつ確認されますか?」を参照してください。http://www.rabbitmq.com/confirms.htmlで。

于 2014-10-08T13:45:19.310 に答える