繁体   English   中英

将请求重新发送到RabbitMQ和Ruby中的相同队列

[英]Resend the request to the same queue in RabbitMQ and Ruby

我有一个Ruby进程来消耗RabbitMQ队列:

AMQP.start(:host => $AMQP_URL) do |connection|
  @channel ||= AMQP::Channel.new(connection)
  @queue   ||= @channel.queue("results")

  @queue.subscribe do |body|
    puts "Received -> #{body}"       
    # Publish the same message again to the same queue 
  end
end

我知道这是不切实际的,但是我很想知道如何将同一条消息发布到同一队列中,即使直接将msg保留在其中,也无法通过直接渠道解决我的问题队列而不是删除它或只是再次重新发布msg,那会很棒

有任何想法吗 ?

正确的方法是拒绝带有否定确认的消息,它将自动重新排队:

@queue.subscribe do |metadata, payload|
  # reject and requeue
  channel.reject(metadata.delivery_tag, true)
end

无论如何,如果您想手动进行发布,则上一个示例中的“ metadata”参数将为您提供所需的所有信息。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM