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.



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

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.



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

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

#get_serializerObject



69
70
71
# File 'lib/hutch/consumer.rb', line 69

def get_serializer
  @serializer
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.



65
66
67
# File 'lib/hutch/consumer.rb', line 65

def routing_keys
  @routing_keys ||= Set.new
end

#serializer(name) ⇒ Object

Set custom serializer class, override global value



45
46
47
# File 'lib/hutch/consumer.rb', line 45

def serializer(name)
  @serializer = name
end