module Hutch::Consumer::ClassMethods

Attributes

initial_group_size[R]
queue_mode[R]
queue_type[R]

Public Instance Methods

arguments(arguments = {}) click to toggle source

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

# File lib/hutch/consumer.rb, line 64
def arguments(arguments = {})
  @arguments = arguments
end
classic_queue() click to toggle source

Explicitly set the queue type to 'classic'

# File lib/hutch/consumer.rb, line 50
def classic_queue
  @queue_type = 'classic'
end
consume(*routing_keys) click to toggle source

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

# 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_arguments() click to toggle source

Returns consumer custom arguments.

# 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_name() click to toggle source

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.

# 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_serializer() click to toggle source
# File lib/hutch/consumer.rb, line 99
def get_serializer
  @serializer
end
lazy_queue() click to toggle source

Explicitly set the queue mode to 'lazy'

# File lib/hutch/consumer.rb, line 45
def lazy_queue
  @queue_mode = 'lazy'
end
queue_name(name) click to toggle source

Explicitly set the queue name

# File lib/hutch/consumer.rb, line 40
def queue_name(name)
  @queue_name = name
end
quorum_queue(options = {}) click to toggle source

Explicitly set the queue type to 'quorum' @param [Hash] options the options params related to quorum queue @option options [Integer] :initial_group_size Initial Replication Factor

# File lib/hutch/consumer.rb, line 57
def quorum_queue(options = {})
  @queue_type = 'quorum'
  @initial_group_size = options[:initial_group_size]
end
routing_keys() click to toggle source

Accessor for the consumer's routing key.

# File lib/hutch/consumer.rb, line 95
def routing_keys
  @routing_keys ||= Set.new
end
serializer(name) click to toggle source

Set custom serializer class, override global value

# File lib/hutch/consumer.rb, line 69
def serializer(name)
  @serializer = name
end