Module: Hutch::Consumer::ClassMethods

Defined in:
lib/hutch/consumer.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#initial_group_sizeObject (readonly)

Returns the value of attribute initial_group_size.



37
38
39
# File 'lib/hutch/consumer.rb', line 37

def initial_group_size
  @initial_group_size
end

#queue_modeObject (readonly)

Returns the value of attribute queue_mode.



37
38
39
# File 'lib/hutch/consumer.rb', line 37

def queue_mode
  @queue_mode
end

#queue_typeObject (readonly)

Returns the value of attribute queue_type.



37
38
39
# File 'lib/hutch/consumer.rb', line 37

def queue_type
  @queue_type
end

Instance Method Details

#arguments(arguments = {}) ⇒ Object

Configures an optional argument that will be passed when declaring the queue. Prefer using a policy to this DSL: www.rabbitmq.com/parameters.html#policies



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

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

#classic_queueObject

Explicitly set the queue type to ‘classic’



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

def classic_queue
  @queue_type = 'classic'
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
33
34
35
# File 'lib/hutch/consumer.rb', line 30

def consume(*routing_keys)
  @routing_keys = self.routing_keys.union(routing_keys)
  # these are opt-in
  @queue_mode = nil
  @queue_type = nil
end

#get_argumentsObject

Returns consumer custom arguments.



84
85
86
87
88
89
90
91
92
# File 'lib/hutch/consumer.rb', line 84

def get_arguments
  all_arguments = @arguments || {}

  all_arguments['x-queue-mode'] = @queue_mode if @queue_mode
  all_arguments['x-queue-type'] = @queue_type if @queue_type
  all_arguments['x-quorum-initial-group-size'] = @initial_group_size if @initial_group_size

  all_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.



76
77
78
79
80
81
# File 'lib/hutch/consumer.rb', line 76

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



99
100
101
# File 'lib/hutch/consumer.rb', line 99

def get_serializer
  @serializer
end

#lazy_queueObject

Explicitly set the queue mode to ‘lazy’



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

def lazy_queue
  @queue_mode = 'lazy'
end

#queue_name(name) ⇒ Object

Explicitly set the queue name



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

def queue_name(name)
  @queue_name = name
end

#quorum_queue(options = {}) ⇒ Object

Explicitly set the queue type to ‘quorum’

Parameters:

  • options (Hash) (defaults to: {})

    the options params related to quorum queue

Options Hash (options):

  • :initial_group_size (Integer)

    Initial Replication Factor



57
58
59
60
# File 'lib/hutch/consumer.rb', line 57

def quorum_queue(options = {})
  @queue_type = 'quorum'
  @initial_group_size = options[:initial_group_size]
end

#routing_keysObject

Accessor for the consumer’s routing key.



95
96
97
# File 'lib/hutch/consumer.rb', line 95

def routing_keys
  @routing_keys ||= Set.new
end

#serializer(name) ⇒ Object

Set custom serializer class, override global value



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

def serializer(name)
  @serializer = name
end