Class: RabbitmqClient::Publisher

Inherits:
Object
  • Object
show all
Defined in:
lib/rabbitmq_client/publisher.rb

Overview

Publisher class is responsible for publishing events to rabbitmq exhanges

Instance Method Summary collapse

Constructor Details

#initialize(**config) ⇒ Publisher

Returns a new instance of Publisher.



8
9
10
11
12
13
14
15
# File 'lib/rabbitmq_client/publisher.rb', line 8

def initialize(**config)
  @config = config
  @session_params = session_params
  @exchange_registry = @config.fetch(:exchange_registry, nil)
  @session_params.freeze
  @session_pool = create_connection_pool
  notify('publisher_created', @session_params)
end

Instance Method Details

#publish(data, options) ⇒ Object



17
18
19
20
21
22
23
24
25
26
27
# File 'lib/rabbitmq_client/publisher.rb', line 17

def publish(data, options)
  return nil unless @exchange_registry

  if async
    PublisherJob.perform_async(@exchange_registry,
                               @session_pool, data, options)
  else
    PublisherJob.new.perform(@exchange_registry,
                             @session_pool, data, options)
  end
end