Class: Ears::PublisherConfirmationHandler

Inherits:
Object
  • Object
show all
Defined in:
lib/ears/publisher_confirmation_handler.rb

Overview

Handles publisher confirmations for RabbitMQ messages.

This class encapsulates the logic for publishing messages with confirmations, including timeout handling, channel cleanup, and pool coordination.

Instance Method Summary collapse

Constructor Details

#initialize(config:, logger:) ⇒ PublisherConfirmationHandler

Creates a new confirmation handler.

Parameters:

  • config (Ears::Configuration)

    The Ears configuration object.

  • logger (Logger)

    The logger instance for warnings and errors.



13
14
15
16
# File 'lib/ears/publisher_confirmation_handler.rb', line 13

def initialize(config:, logger:)
  @config = config
  @logger = logger
end

Instance Method Details

#publish_with_confirmation(channel:, exchange:, data:, routing_key:, options:) ⇒ void

This method returns an undefined value.

Publishes a message with confirmation.

Parameters:

  • channel (Bunny::Channel)

    The channel to use for publishing.

  • exchange (Bunny::Exchange)

    The exchange to publish to.

  • data (Hash, Array, Object)

    The data to publish.

  • routing_key (String)

    The routing key for the message.

  • options (Hash)

    The publish options.

Raises:



29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/ears/publisher_confirmation_handler.rb', line 29

def publish_with_confirmation(
  channel:,
  exchange:,
  data:,
  routing_key:,
  options:
)
  exchange.publish(data, { routing_key: routing_key }.merge(options))

  timeout = config.publisher_confirms_timeout
  unless wait_for_confirms_with_timeout(channel, timeout)
    handle_confirmation_failure(channel, timeout)
  end
end