Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions lib/tasks/message_queue.rake
Original file line number Diff line number Diff line change
Expand Up @@ -20,21 +20,21 @@ namespace :message_queue do
retry_dlx = channel.fanout("#{name}_retry_dlx")
discarded_dlx = channel.fanout("#{name}_discarded_dlx")

channel
.queue(name, arguments: { "x-dead-letter-exchange" => retry_dlx.name })
.bind(exch, routing_key: routing_key)

# messages are queued on {queue}_discarded_dlx for 30s before their
# ttl completes then are routed to the {queue}_retry_dlx
channel
.queue(
"#{name}_wait_to_retry",
durable: true,
arguments: { "x-dead-letter-exchange" => discarded_dlx.name, "x-message-ttl" => 10 * 3000 },
)
.bind(retry_dlx)

# messages on the {queue}_discarded_dlx are routed back to the original queue
channel.queue(name).bind(discarded_dlx)
channel.queue(name, durable: true, arguments: { "x-dead-letter-exchange" => retry_dlx.name }).tap do |q|
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oooh I haven't come across tap before! It's very pleasing!

q.bind(exch, routing_key:)
# messages on the {queue}_discarded_dlx are routed back to the original queue
q.bind(discarded_dlx)
end
end
end

Expand Down
24 changes: 9 additions & 15 deletions spec/unit/tasks/message_queue_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,6 @@
discarded_dlx: instance_double(Bunny::Exchange, name: "search_api_bulk_reindex_discarded_dlx"),
queues: {
root: instance_double(Bunny::Queue, bind: nil),
discarded: instance_double(Bunny::Queue, bind: nil),
wait_to_retry: instance_double(Bunny::Queue, bind: nil),
},
},
Expand All @@ -93,7 +92,6 @@
discarded_dlx: instance_double(Bunny::Exchange, name: "search_api_govuk_index_discarded_dlx"),
queues: {
root: instance_double(Bunny::Queue, bind: nil),
discarded: instance_double(Bunny::Queue, bind: nil),
wait_to_retry: instance_double(Bunny::Queue, bind: nil),
},
},
Expand All @@ -109,10 +107,6 @@
.to receive(:queue).with(name, anything)
.and_return(config[:queues][:root])

allow(channel)
.to receive(:queue).with(name)
.and_return(config[:queues][:discarded])

allow(channel)
.to receive(:queue).with("#{name}_wait_to_retry", anything)
.and_return(config[:queues][:wait_to_retry])
Expand All @@ -123,23 +117,23 @@
queues.each do |config|
name = config[:name]
expect(channel).to have_received(:queue).with(
name,
arguments: { "x-dead-letter-exchange" => "#{name}_retry_dlx" },
name, durable: true,
arguments: { "x-dead-letter-exchange" => "#{name}_retry_dlx" }
)

expect(channel).to have_received(:queue).with(name)
expect(channel).to have_received(:queue).with(name, durable: true, arguments: { "x-dead-letter-exchange" => "#{name}_retry_dlx" })

expect(channel).to have_received(:queue).with(
"#{name}_wait_to_retry",
arguments: {
"x-dead-letter-exchange" => "#{name}_discarded_dlx",
"x-message-ttl" => 30_000,
},
"#{name}_wait_to_retry", durable: true,
arguments: {
"x-dead-letter-exchange" => "#{name}_discarded_dlx",
"x-message-ttl" => 30_000,
}
)

expect(config[:queues][:root]).to have_received(:bind).with(exchange, routing_key: config[:routing_key])
expect(config[:queues][:root]).to have_received(:bind).with(config[:discarded_dlx])
expect(config[:queues][:wait_to_retry]).to have_received(:bind).with(config[:retry_dlx])
expect(config[:queues][:discarded]).to have_received(:bind).with(config[:discarded_dlx])
end
end
end
Expand Down
Loading