Class: Msgr::Channel
Constant Summary collapse
- EXCHANGE_NAME =
'msgr'
Instance Attribute Summary collapse
-
#channel ⇒ Object
readonly
Returns the value of attribute channel.
-
#config ⇒ Object
readonly
Returns the value of attribute config.
Instance Method Summary collapse
- #ack(delivery_tag) ⇒ Object
- #close ⇒ Object
- #exchange ⇒ Object
-
#initialize(config, connection) ⇒ Channel
constructor
A new instance of Channel.
- #nack(delivery_tag) ⇒ Object
- #prefetch(count) ⇒ Object
- #prefix(name) ⇒ Object
- #queue(name) ⇒ Object
- #reject(delivery_tag, requeue = true) ⇒ Object
Methods included from Logging
Constructor Details
#initialize(config, connection) ⇒ Channel
Returns a new instance of Channel.
9 10 11 12 |
# File 'lib/msgr/channel.rb', line 9 def initialize(config, connection) @config = config @channel = connection.create_channel end |
Instance Attribute Details
#channel ⇒ Object (readonly)
Returns the value of attribute channel.
7 8 9 |
# File 'lib/msgr/channel.rb', line 7 def channel @channel end |
#config ⇒ Object (readonly)
Returns the value of attribute config.
7 8 9 |
# File 'lib/msgr/channel.rb', line 7 def config @config end |
Instance Method Details
#ack(delivery_tag) ⇒ Object
46 47 48 49 |
# File 'lib/msgr/channel.rb', line 46 def ack(delivery_tag) @channel.ack delivery_tag log(:debug) { "Acked message: #{delivery_tag}" } end |
#close ⇒ Object
61 62 63 |
# File 'lib/msgr/channel.rb', line 61 def close @channel.close if @channel.open? end |
#exchange ⇒ Object
18 19 20 21 22 23 24 25 26 27 |
# File 'lib/msgr/channel.rb', line 18 def exchange @exchange ||= begin @channel.topic(prefix(EXCHANGE_NAME), durable: true).tap do |ex| log(:debug) do "Created exchange #{ex.name} (type: #{ex.type}, " \ "durable: #{ex.durable?}, auto_delete: #{ex.auto_delete?})" end end end end |
#nack(delivery_tag) ⇒ Object
51 52 53 54 |
# File 'lib/msgr/channel.rb', line 51 def nack(delivery_tag) @channel.nack delivery_tag, false, true log(:debug) { "Nacked message: #{delivery_tag}" } end |
#prefetch(count) ⇒ Object
14 15 16 |
# File 'lib/msgr/channel.rb', line 14 def prefetch(count) @channel.prefetch count end |
#prefix(name) ⇒ Object
38 39 40 41 42 43 44 |
# File 'lib/msgr/channel.rb', line 38 def prefix(name) if config[:prefix].present? "#{config[:prefix]}-#{name}" else name end end |
#queue(name) ⇒ Object
29 30 31 32 33 34 35 36 |
# File 'lib/msgr/channel.rb', line 29 def queue(name) @channel.queue(prefix(name), durable: true).tap do |queue| log(:debug) do "Create queue #{queue.name} (durable: #{queue.durable?}, " \ "auto_delete: #{queue.auto_delete?})" end end end |
#reject(delivery_tag, requeue = true) ⇒ Object
56 57 58 59 |
# File 'lib/msgr/channel.rb', line 56 def reject(delivery_tag, requeue = true) @channel.reject delivery_tag, requeue log(:debug) { "Rejected message: #{delivery_tag}" } end |