Class: RabbitmqClient::MessagePublisher

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

Overview

ExchangeRegistry is a store for all managed exchanges and their details

Defined Under Namespace

Classes: ConfirmationFailed

Instance Method Summary collapse

Constructor Details

#initialize(data, exchange, channel, options) ⇒ MessagePublisher

Returns a new instance of MessagePublisher.



15
16
17
18
19
20
21
# File 'lib/rabbitmq_client/message_publisher.rb', line 15

def initialize(data, exchange, channel, options)
  @data = data.to_json
  @exchange = exchange
  @channel = channel
  @options = { headers: {} }.merge(options)
  @options[:headers][:tags] = TagsFilter.tags
end

Instance Method Details

#publishObject



23
24
25
26
27
28
29
# File 'lib/rabbitmq_client/message_publisher.rb', line 23

def publish
  exchange = @exchange.create(@channel)

  notify('publishing_message')
  exchange.publish(@data, **@options)
  notify('published_message')
end

#wait_for_confirmsObject

Raises:



31
32
33
34
35
36
37
38
39
# File 'lib/rabbitmq_client/message_publisher.rb', line 31

def wait_for_confirms
  notify('confirming_message')
  if @channel.wait_for_confirms
    notify('message_confirmed')
    return
  end
  raise ConfirmationFailed.new(@exchange.name, @channel.nacked_set,
                               @channel.unconfirmed_set)
end