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
Configures 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.
-
#without_namespace ⇒ Object
Opt out of the namespace prefix for this consumer's queue.
- #without_namespace? ⇒ Boolean
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: https://www.rabbitmq.com/parameters.html#policies
79 80 81 |
# File 'lib/hutch/consumer.rb', line 79 def arguments(arguments = {}) @arguments = arguments end |
#classic_queue ⇒ Object
Explicitly set the queue type to 'classic'
65 66 67 |
# File 'lib/hutch/consumer.rb', line 65 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.
104 105 106 107 108 109 110 111 112 |
# File 'lib/hutch/consumer.rb', line 104 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
114 115 116 117 118 119 120 121 |
# File 'lib/hutch/consumer.rb', line 114 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.
96 97 98 99 100 101 |
# File 'lib/hutch/consumer.rb', line 96 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
128 129 130 |
# File 'lib/hutch/consumer.rb', line 128 def get_serializer @serializer end |
#lazy_queue ⇒ Object
Explicitly set the queue mode to 'lazy'
60 61 62 |
# File 'lib/hutch/consumer.rb', line 60 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
Configures queue options that will be passed when declaring the queue.
84 85 86 |
# File 'lib/hutch/consumer.rb', line 84 def ( = {}) @queue_options = end |
#quorum_queue(options = {}) ⇒ Object
Explicitly set the queue type to 'quorum'
72 73 74 75 |
# File 'lib/hutch/consumer.rb', line 72 def quorum_queue( = {}) @queue_type = 'quorum' @initial_group_size = [:initial_group_size] end |
#routing_keys ⇒ Object
Accessor for the consumer's routing key.
124 125 126 |
# File 'lib/hutch/consumer.rb', line 124 def routing_keys @routing_keys ||= Set.new end |
#serializer(name) ⇒ Object
Set custom serializer class, override global value
89 90 91 |
# File 'lib/hutch/consumer.rb', line 89 def serializer(name) @serializer = name end |
#without_namespace ⇒ Object
Opt out of the namespace prefix for this consumer's queue
51 52 53 |
# File 'lib/hutch/consumer.rb', line 51 def without_namespace @without_namespace = true end |
#without_namespace? ⇒ Boolean
55 56 57 |
# File 'lib/hutch/consumer.rb', line 55 def without_namespace? !!@without_namespace end |