Class: GorgService::Producer

Inherits:
Object
  • Object
show all
Defined in:
lib/gorg_service/producer.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(environment_: GorgService.environment, default_exchange_: nil) ⇒ Producer

Returns a new instance of Producer.



11
12
13
14
# File 'lib/gorg_service/producer.rb', line 11

def initialize(environment_: GorgService.environment ,default_exchange_: nil)
  self.environment=environment_
  self.default_exchange= default_exchange_ || environment.event_exchange
end

Instance Attribute Details

#default_exchangeObject

Returns the value of attribute default_exchange.



8
9
10
# File 'lib/gorg_service/producer.rb', line 8

def default_exchange
  @default_exchange
end

#environmentObject

Returns the value of attribute environment.



9
10
11
# File 'lib/gorg_service/producer.rb', line 9

def environment
  @environment
end

Instance Method Details

#publish_message(message, exchange: default_exchange) ⇒ Object



17
18
19
20
21
22
23
# File 'lib/gorg_service/producer.rb', line 17

def publish_message(message, exchange: default_exchange)
  x=exchange.is_a?(Bunny::Exchange) ? exchange : environment.find_exchange_by_name(exchange)
  GorgService.logger.info "Publish to #{x.name} - key : #{message.routing_key}"
  GorgService.logger.debug "Message content : #{message.body.to_s[0...10000]}"

  x.publish(message.to_json, message.properties)
end