Class: Istox::Publisher

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

Class Method Summary collapse

Class Method Details

.initialize!(amqp_config_path) ⇒ Object



4
5
6
# File 'lib/istox/helpers/publisher.rb', line 4

def initialize!(amqp_config_path)
  @@amqp_config_path = amqp_config_path
end

.publish(exchange, routing_key, message, persistent: true) ⇒ Object



8
9
10
11
12
13
14
15
16
17
# File 'lib/istox/helpers/publisher.rb', line 8

def publish(exchange, routing_key, message, persistent: true)
  Rails.logger.debug 'Before publish retrieve data..'
  durable = data.fetch('publish')[exchange]['durable']
  Rails.logger.debug "Publishing message: #{message} with exchange: #{exchange} routing key: #{routing_key}"
  enqueue do
    $channel
      .direct(exchange, durable: durable)
      .publish(message.to_json, routing_key: routing_key, durable: durable, persistent: persistent)
  end
end

.publish_to_fanout(exchange, message, persistent: true) ⇒ Object



19
20
21
22
23
24
25
26
27
# File 'lib/istox/helpers/publisher.rb', line 19

def publish_to_fanout(exchange, message, persistent: true)
  Rails.logger.debug 'Before publish retrieve data..'
  durable = data.fetch('publish')[exchange]['durable']
  enqueue do
    $channel
      .fanout(exchange, durable: durable)
      .publish(message.to_json, durable: durable, persistent: persistent)
  end
end