module Hutch::Consumer::ClassMethods
Attributes
Public Instance Methods
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 70 def arguments(arguments = {}) @arguments = arguments end
Explicitly set the queue type to ‘classic’
# File lib/hutch/consumer.rb, line 56 def classic_queue @queue_type = 'classic' end
Add one or more routing keys to the set of routing keys the consumer wants to subscribe to.
# File lib/hutch/consumer.rb, line 36 def consume(*routing_keys) @routing_keys = self.routing_keys.union(routing_keys) # these are opt-in @queue_mode = nil @queue_type = nil end
Returns consumer custom arguments.
# File lib/hutch/consumer.rb, line 95 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
# File lib/hutch/consumer.rb, line 105 def get_options default_options = { durable: true } all_options = default_options.merge(@queue_options || {}) all_options[:arguments] = get_arguments all_options end
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 87 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
# File lib/hutch/consumer.rb, line 119 def get_serializer @serializer end
Explicitly set the queue mode to ‘lazy’
# File lib/hutch/consumer.rb, line 51 def lazy_queue @queue_mode = 'lazy' end
Explicitly set the queue name
# File lib/hutch/consumer.rb, line 46 def queue_name(name) @queue_name = name end
Congfiures queue options that will be passed when declaring the queue.
# File lib/hutch/consumer.rb, line 75 def queue_options(options = {}) @queue_options = options end
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 63 def quorum_queue(options = {}) @queue_type = 'quorum' @initial_group_size = options[:initial_group_size] end
Accessor for the consumer’s routing key.
# File lib/hutch/consumer.rb, line 115 def routing_keys @routing_keys ||= Set.new end
Set custom serializer class, override global value
# File lib/hutch/consumer.rb, line 80 def serializer(name) @serializer = name end