Module: Hutch::Consumer::ClassMethods
- Defined in:
- lib/hutch/consumer.rb
Instance Attribute Summary collapse
-
#initial_group_size ⇒ Object
readonly
Returns the value of attribute initial_group_size.
-
#queue_mode ⇒ Object
readonly
Returns the value of attribute queue_mode.
-
#queue_type ⇒ Object
readonly
Returns the value of attribute queue_type.
Instance Method Summary collapse
-
#arguments(arguments = {}) ⇒ Object
Configures an optional argument that will be passed when declaring the queue.
-
#classic_queue ⇒ Object
Explicitly set the queue type to ‘classic’.
-
#consume(*routing_keys) ⇒ Object
Add one or more routing keys to the set of routing keys the consumer wants to subscribe to.
-
#get_arguments ⇒ Object
Returns consumer custom arguments.
- #get_options ⇒ Object
-
#get_queue_name ⇒ Object
The RabbitMQ queue name for the consumer.
- #get_serializer ⇒ Object
-
#lazy_queue ⇒ Object
Explicitly set the queue mode to ‘lazy’.
-
#queue_name(name) ⇒ Object
Explicitly set the queue name.
-
#queue_options(options = {}) ⇒ Object
Congfiures queue options that will be passed when declaring the queue.
-
#quorum_queue(options = {}) ⇒ Object
Explicitly set the queue type to ‘quorum’.
-
#routing_keys ⇒ Object
Accessor for the consumer’s routing key.
-
#serializer(name) ⇒ Object
Set custom serializer class, override global value.
Instance Attribute Details
#initial_group_size ⇒ Object (readonly)
Returns the value of attribute initial_group_size.
43 44 45 |
# File 'lib/hutch/consumer.rb', line 43 def initial_group_size @initial_group_size end |
#queue_mode ⇒ Object (readonly)
Returns the value of attribute queue_mode.
43 44 45 |
# File 'lib/hutch/consumer.rb', line 43 def queue_mode @queue_mode end |
#queue_type ⇒ Object (readonly)
Returns the value of attribute queue_type.
43 44 45 |
# File 'lib/hutch/consumer.rb', line 43 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
70 71 72 |
# File 'lib/hutch/consumer.rb', line 70 def arguments(arguments = {}) @arguments = arguments end |
#classic_queue ⇒ Object
Explicitly set the queue type to ‘classic’
56 57 58 |
# File 'lib/hutch/consumer.rb', line 56 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.
36 37 38 39 40 41 |
# 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 |
#get_arguments ⇒ Object
Returns consumer custom arguments.
95 96 97 98 99 100 101 102 103 |
# 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 |
#get_options ⇒ Object
105 106 107 108 109 110 111 112 |
# File 'lib/hutch/consumer.rb', line 105 def = { durable: true } = .merge(@queue_options || {}) [:arguments] = get_arguments end |
#get_queue_name ⇒ Object
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.
87 88 89 90 91 92 |
# 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 |
#get_serializer ⇒ Object
119 120 121 |
# File 'lib/hutch/consumer.rb', line 119 def get_serializer @serializer end |
#lazy_queue ⇒ Object
Explicitly set the queue mode to ‘lazy’
51 52 53 |
# File 'lib/hutch/consumer.rb', line 51 def lazy_queue @queue_mode = 'lazy' end |
#queue_name(name) ⇒ Object
Explicitly set the queue name
46 47 48 |
# File 'lib/hutch/consumer.rb', line 46 def queue_name(name) @queue_name = name end |
#queue_options(options = {}) ⇒ Object
Congfiures queue options that will be passed when declaring the queue.
75 76 77 |
# File 'lib/hutch/consumer.rb', line 75 def ( = {}) @queue_options = end |
#quorum_queue(options = {}) ⇒ Object
Explicitly set the queue type to ‘quorum’
63 64 65 66 |
# File 'lib/hutch/consumer.rb', line 63 def quorum_queue( = {}) @queue_type = 'quorum' @initial_group_size = [:initial_group_size] end |
#routing_keys ⇒ Object
Accessor for the consumer’s routing key.
115 116 117 |
# File 'lib/hutch/consumer.rb', line 115 def routing_keys @routing_keys ||= Set.new end |
#serializer(name) ⇒ Object
Set custom serializer class, override global value
80 81 82 |
# File 'lib/hutch/consumer.rb', line 80 def serializer(name) @serializer = name end |