module Vx::Common::AMQP::Consumer::Configuration

Public Instance Methods

ack(value = nil) click to toggle source
# File lib/vx/common/amqp/consumer/configuration.rb, line 71
def ack(value = nil)
  consumer_configuration.ack = value unless value == nil
  consumer_configuration.ack
end
bind_options() click to toggle source
# File lib/vx/common/amqp/consumer/configuration.rb, line 88
def bind_options
  consumer_configuration.bind_options ||
    @@consumer_configuration_lock.synchronize do
      opts = {}
      opts[:routing_key] = routing_key if routing_key
      opts[:headers]     = headers     if headers
      consumer_configuration.bind_options = opts
    end
end
consumer_configuration() click to toggle source
# File lib/vx/common/amqp/consumer/configuration.rb, line 11
def consumer_configuration
  @consumer_configuration || reset_consumer_configuration!
end
consumer_id() click to toggle source
# File lib/vx/common/amqp/consumer/configuration.rb, line 80
def consumer_id
  if cid = Thread.current[:vx_amqp_consumer_id]
    "#{consumer_name}.#{cid}"
  else
    consumer_name
  end
end
consumer_name() click to toggle source
# File lib/vx/common/amqp/consumer/configuration.rb, line 76
def consumer_name
  consumer_configuration.consumer_name
end
content_type(value = nil) click to toggle source
# File lib/vx/common/amqp/consumer/configuration.rb, line 66
def content_type(value = nil)
  consumer_configuration.content_type = value if value
  consumer_configuration.content_type
end
headers(values = nil, &block) click to toggle source
# File lib/vx/common/amqp/consumer/configuration.rb, line 52
def headers(values = nil, &block)
  val = block || values
  if val
    consumer_configuration.headers = val
  else
    value_maybe_proc consumer_configuration.headers
  end
end
model(value = nil) click to toggle source
# File lib/vx/common/amqp/consumer/configuration.rb, line 61
def model(value = nil)
  consumer_configuration.model = value unless value == nil
  consumer_configuration.model
end
reset_consumer_configuration!() click to toggle source
# File lib/vx/common/amqp/consumer/configuration.rb, line 15
def reset_consumer_configuration!
  @@consumer_configuration_lock.synchronize do
    @consumer_configuration =
      OpenStruct.new(exchange:      OpenStruct.new(options: {}),
                     queue:         OpenStruct.new(options: {}),
                     consumer_name: make_consumer_name,
                     ack:           false,
                     content_type:  nil)
  end
end
routing_key(name = nil, &block) click to toggle source
# File lib/vx/common/amqp/consumer/configuration.rb, line 43
def routing_key(name = nil, &block)
  val = block || name
  if val
    consumer_configuration.routing_key = val
  else
    value_maybe_proc consumer_configuration.routing_key
  end
end

Private Instance Methods

make_consumer_name() click to toggle source
# File lib/vx/common/amqp/consumer/configuration.rb, line 109
def make_consumer_name
  to_s.split("::")
      .last
      .scan(/[A-Z][a-z]*/).join("_")
      .downcase
end
value_maybe_proc(val) click to toggle source
# File lib/vx/common/amqp/consumer/configuration.rb, line 100
def value_maybe_proc(val)
  case val
  when Proc
    val.call
  else
    val
  end
end