Merge pull request #15 from arikarim/multi-exchange-

fix: Enhance run_task method to handle existing RabbitMQ exchanges by…
This commit is contained in:
Brusk Awat 2026-01-18 15:14:57 +03:00 committed by GitHub
commit 41074d617f
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 11 additions and 3 deletions

View File

@ -1,7 +1,7 @@
PATH PATH
remote: . remote: .
specs: specs:
rabbit_carrots (1.1.0) rabbit_carrots (1.1.1)
bunny (>= 2.22) bunny (>= 2.22)
connection_pool (>= 2.4) connection_pool (>= 2.4)

View File

@ -79,7 +79,15 @@ module RabbitCarrots
def run_task(queue_name:, handler_class:, routing_keys:, queue_arguments: {}, exchange_name: nil, kill_to_restart_on_standard_error: false) def run_task(queue_name:, handler_class:, routing_keys:, queue_arguments: {}, exchange_name: nil, kill_to_restart_on_standard_error: false)
RabbitCarrots::Connection.instance.channel.with do |channel| RabbitCarrots::Connection.instance.channel.with do |channel|
exchange = channel.topic(exchange_name || RabbitCarrots.configuration.rabbitmq_exchange_name, durable: true) exchange_name ||= RabbitCarrots.configuration.rabbitmq_exchange_name
begin
# Try to passively read an existing exchange without declaring it
exchange = channel.topic(exchange_name, passive: true)
rescue Bunny::NotFound
# If the exchange does not exist, declare it
exchange = channel.topic(exchange_name, durable: true)
end
logger.info "Listening on QUEUE: #{queue_name} for ROUTING KEYS: #{routing_keys}" logger.info "Listening on QUEUE: #{queue_name} for ROUTING KEYS: #{routing_keys}"
queue = channel.queue(queue_name, durable: true, arguments: queue_arguments) queue = channel.queue(queue_name, durable: true, arguments: queue_arguments)

View File

@ -1,5 +1,5 @@
# frozen_string_literal: true # frozen_string_literal: true
module RabbitCarrots module RabbitCarrots
VERSION = '1.1.0' VERSION = '1.1.1'
end end