Module: Hutch::Consumer::ClassMethods

Defined in:
lib/hutch/consumer.rb

Instance Method Summary collapse

Instance Method Details

#arguments(arguments = {}) ⇒ Object

Allow to specify custom arguments that will be passed when creating the queue.



40
41
42
# File 'lib/hutch/consumer.rb', line 40

def arguments(arguments = {})
  @arguments = arguments
end

#consume(*routing_keys) ⇒ Object

Add one or more routing keys to the set of routing keys the consumer wants to subscribe to.



30
31
32
# File 'lib/hutch/consumer.rb', line 30

def consume(*routing_keys)
  @routing_keys = self.routing_keys.union(routing_keys)
end

#get_argumentsObject

Returns consumer custom arguments.



55
56
57
# File 'lib/hutch/consumer.rb', line 55

def get_arguments
  @arguments || {}
end

#get_queue_nameObject

The RabbitMQ queue name for the consumer. This is derived from the fully-qualified class name. Module separators are replaced with single colons, camelcased class names are converted to snake case.



47
48
49
50
51
52
# File 'lib/hutch/consumer.rb', line 47

def get_queue_name
  return @queue_name unless @queue_name.nil?
  queue_name = self.name.gsub(/::/, ':')
  queue_name.gsub!(/([^A-Z:])([A-Z])/) { "#{$1}_#{$2}" }
  queue_name.downcase
end

#queue_name(name) ⇒ Object

Explicitly set the queue name



35
36
37
# File 'lib/hutch/consumer.rb', line 35

def queue_name(name)
  @queue_name = name
end

#routing_keysObject

Accessor for the consumer’s routing key.



60
61
62
# File 'lib/hutch/consumer.rb', line 60

def routing_keys
  @routing_keys ||= Set.new
end