Module: Twingly::AMQP::Publisher

Included in:
DefaultExchangePublisher, TopicExchangePublisher
Defined in:
lib/twingly/amqp/publisher.rb

Instance Method Summary collapse

Instance Method Details

#configure_publish_options {|options| ... } ⇒ Object

Yields:

  • (options)


29
30
31
# File 'lib/twingly/amqp/publisher.rb', line 29

def configure_publish_options
  yield options
end

#publish(message, opts = {}) ⇒ Object



4
5
6
7
8
9
10
11
12
13
14
15
16
17
# File 'lib/twingly/amqp/publisher.rb', line 4

def publish(message, opts = {})
  payload =
    if message.kind_of?(Array)
      message
    elsif message.respond_to?(:to_h)
      message.to_h
    else
      raise ArgumentError
    end

  json_payload       = payload.to_json
  publishing_options = options.to_h.merge(opts)
  @exchange.publish(json_payload, publishing_options)
end

#publish_with_confirm(message, opts = {}) ⇒ Object

Only used by tests to lessen the time we need to sleep



20
21
22
23
24
25
26
27
# File 'lib/twingly/amqp/publisher.rb', line 20

def publish_with_confirm(message, opts = {})
  channel = @exchange.channel
  channel.confirm_select unless channel.using_publisher_confirmations?

  publish(message, opts)

  @exchange.wait_for_confirms
end