ここのコメントで述べたように、私はその機能を試してみx-dead-letter-exchange
ましたが、ほとんどの要件で機能しました。1 つの質問/誤解は、TTL-PER-MESSAGE オプションです。
こちらの例をご覧ください。私の理解から:
- DLQ のタイムアウトは 10 秒です
- 最初のメッセージは、公開後 10 秒でサブスクライバーに表示されます。
- 2 番目のメッセージは、最初のメッセージの 1 秒後に投稿され、message-ttl (有効期限) は 3 秒です。
2 番目のメッセージは、公開から 3 秒後、最初のメッセージの前に発音されるはずです。
しかし、そのようには機能しませんでした。両方とも 10 秒後に利用可能になります。
Q: メッセージの有効期限が DLQ ttl を覆すべきではありませんか?
#!/usr/bin/env ruby
# encoding: utf-8
require 'bunny'
B = Bunny.new ENV['CLOUDAMQP_URL']
B.start
DELAYED_QUEUE='work.later'
DESTINATION_QUEUE='work.now'
def publish
ch = B.create_channel
# declare a queue with the DELAYED_QUEUE name
q = ch.queue(DELAYED_QUEUE, :durable => true, arguments: {
# set the dead-letter exchange to the default queue
'x-dead-letter-exchange' => '',
# when the message expires, set change the routing key into the destination queue name
'x-dead-letter-routing-key' => DESTINATION_QUEUE,
# the time in milliseconds to keep the message in the queue
'x-message-ttl' => 10000,
})
# publish to the default exchange with the the delayed queue name as routing key,
# so that the message ends up in the newly declared delayed queue
ch.basic_publish('message content 1 ' + Time.now.strftime("%H-%M-%S"), "", DELAYED_QUEUE, :persistent => true)
puts "#{Time.now}: Published the message 1"
# wait moment before next publish
sleep 1.0
# puts this with a shorter ttl
ch.basic_publish('message content 2 ' + Time.now.strftime("%H-%M-%S"), "", DELAYED_QUEUE, :persistent => true, :expiration => "3000")
puts "#{Time.now}: Published the message 2"
ch.close
end
def subscribe
ch = B.create_channel
# declare the destination queue
q = ch.queue DESTINATION_QUEUE, durable: true
q.subscribe do |delivery, headers, body|
puts "#{Time.now}: Got the message: #{body}"
end
end
subscribe()
publish()
sleep