Class: Jackhammer::Topic
- Inherits:
-
Object
- Object
- Jackhammer::Topic
- Defined in:
- lib/jackhammer/topic.rb
Constant Summary collapse
- QUEUE_NAME_KEY =
'queue_name'.freeze
- ROUTING_KEY_KEY =
'routing_key'.freeze
Instance Method Summary collapse
-
#initialize(name:, queue_config:, options: {}) ⇒ Topic
constructor
A new instance of Topic.
-
#publish(message, options) ⇒ Object
We’re expecting the client to specify at least the routing_key in options for each message published.
- #queues ⇒ Object
- #subscribe_queues ⇒ Object
Constructor Details
#initialize(name:, queue_config:, options: {}) ⇒ Topic
Returns a new instance of Topic.
6 7 8 9 |
# File 'lib/jackhammer/topic.rb', line 6 def initialize(name:, queue_config:, options: {}) @topic = Jackhammer.channel.topic(name, ) @queue_config = normalize_queue_config(queue_config) end |
Instance Method Details
#publish(message, options) ⇒ Object
We’re expecting the client to specify at least the routing_key in options for each message published.
17 18 19 20 21 |
# File 'lib/jackhammer/topic.rb', line 17 def publish(, ) Jackhammer.client_middleware.call(, Jackhammer.()) do |msg, opts| topic.publish msg, opts end end |
#queues ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/jackhammer/topic.rb', line 23 def queues return @queues if @queues @queues = queue_config.map do || handler = MessageReceiver.new(.delete('handler')) routing_key = fetch_and_delete_key(, ROUTING_KEY_KEY) queue_name = .delete(QUEUE_NAME_KEY) || QueueName.from_routing_key(routing_key) queue = Jackhammer.channel.queue(queue_name, ) Log.info { "'#{queue_name}' configured to subscribe on '#{routing_key}'" } Queue.new(topic: topic, queue: queue, handler: handler, routing_key: routing_key) end end |
#subscribe_queues ⇒ Object
11 12 13 |
# File 'lib/jackhammer/topic.rb', line 11 def subscribe_queues queues.each(&:subscribe) end |