Class: PikaQ::Publisher

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(channel, exchange_name, exchange_type = :default, exchange_options = { durable: false, auto_delete: false }) ⇒ Publisher

Returns a new instance of Publisher.



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

def initialize(channel, exchange_name, exchange_type = :default, exchange_options = { durable: false, auto_delete: false })
  @channel = channel
  @exchange_name = exchange_name
  @exchange_type = exchange_type
  @exchange_options = exchange_options
  @exchange = connect_to_exchange
end

Instance Attribute Details

#channelObject (readonly)

Returns the value of attribute channel.



7
8
9
# File 'lib/pika_q/publisher.rb', line 7

def channel
  @channel
end

#exchangeObject (readonly)

Returns the value of attribute exchange.



7
8
9
# File 'lib/pika_q/publisher.rb', line 7

def exchange
  @exchange
end

#exchange_nameObject (readonly)

Returns the value of attribute exchange_name.



7
8
9
# File 'lib/pika_q/publisher.rb', line 7

def exchange_name
  @exchange_name
end

#exchange_optionsObject (readonly)

Returns the value of attribute exchange_options.



7
8
9
# File 'lib/pika_q/publisher.rb', line 7

def exchange_options
  @exchange_options
end

#exchange_typeObject (readonly)

Returns the value of attribute exchange_type.



7
8
9
# File 'lib/pika_q/publisher.rb', line 7

def exchange_type
  @exchange_type
end

Instance Method Details

#close_channelObject



24
25
26
# File 'lib/pika_q/publisher.rb', line 24

def close_channel
  channel.close
end

#send_message(payload, message_options = {}) ⇒ Object



17
18
19
20
21
22
# File 'lib/pika_q/publisher.rb', line 17

def send_message(payload, message_options = {})
  message_options ||= {}
  message_options = default_message_options.merge(message_options)
  published = exchange.publish(payload, message_options)
  published
end