Module: Rabbit::Publishing
- Extended by:
- Publishing
- Included in:
- Publishing
- Defined in:
- lib/rabbit/publishing.rb,
lib/rabbit/publishing/job.rb,
lib/rabbit/publishing/message.rb,
lib/rabbit/publishing/channels_pool.rb
Defined Under Namespace
Classes: ChannelsPool, Job, Message
Constant Summary
collapse
- MUTEX =
Mutex.new
Instance Method Summary
collapse
Instance Method Details
#pool ⇒ Object
32
33
34
|
# File 'lib/rabbit/publishing.rb', line 32
def pool
MUTEX.synchronize { @pool ||= ChannelsPool.new(create_client) }
end
|
#publish(msg) ⇒ Object
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
|
# File 'lib/rabbit/publishing.rb', line 13
def publish(msg)
return if Rabbit.config.skip_publish?
pool.with_channel msg.confirm_select? do |ch|
ch.basic_publish *msg.basic_publish_args
raise MessageNotDelivered, "RabbitMQ message not delivered: #{msg}" \
if msg.confirm_select? && !ch.wait_for_confirms
log msg
end
rescue Timeout::Error
raise MessageNotDelivered, <<~MESSAGE
Timeout while sending message #{msg}. Possible reasons:
- #{msg.real_exchange_name} exchange is not found
- RabbitMQ is extremely high loaded
MESSAGE
end
|