Class: SmartQue::Publisher
- Inherits:
-
SmartQue::Publishers::Base
- Object
- SmartQue::Publishers::Base
- SmartQue::Publisher
- Defined in:
- lib/smart_que/publisher.rb
Instance Method Summary collapse
-
#broadcast(payload = {}) ⇒ Object
broadcast message to queues based on topic subscription.
-
#initialize ⇒ Publisher
constructor
Initialize.
-
#multicast(topic, payload = {}) ⇒ Object
multicast message to queues based on topic subscription.
-
#publish(queue, payload = {}) ⇒ Object
Publish message to the respective queue.
-
#unicast(q_name, payload = {}) ⇒ Object
unicast message to queues.
Methods inherited from SmartQue::Publishers::Base
#channel, #channel_pool, #config, #connection, #find_or_initialize_queue, #get_queue, #log_message, #queue_list, #x_default, #x_direct, #x_fanout, #x_topic
Constructor Details
#initialize ⇒ Publisher
Initialize
7 8 9 10 11 |
# File 'lib/smart_que/publisher.rb', line 7 def initialize queue_list.each do |q_name| find_or_initialize_queue(q_name) end end |
Instance Method Details
#broadcast(payload = {}) ⇒ Object
broadcast message to queues based on topic subscription
54 55 56 57 58 59 |
# File 'lib/smart_que/publisher.rb', line 54 def broadcast(payload = {}) x_fanout.publish( payload.to_json ) ("broadcast status: success, Content : #{payload}") end |
#multicast(topic, payload = {}) ⇒ Object
multicast message to queues based on topic subscription
45 46 47 48 49 50 51 |
# File 'lib/smart_que/publisher.rb', line 45 def multicast(topic, payload = {}) x_topic.publish( payload.to_json, routing_key: dot_formatted(topic) ) ("multicast status: success, Topic : #{topic}, Content : #{payload}") end |
#publish(queue, payload = {}) ⇒ Object
Publish message to the respective queue
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/smart_que/publisher.rb', line 16 def publish(queue, payload = {}) # Check queue name includes in the configured list # Return if queue doesn't exist if queue_list.include? queue # Publish sms to queue x_direct.publish( payload.to_json, mandatory: true, routing_key: get_queue(queue).name ) ("Publish status: success, Queue : #{queue}, Content : #{payload}") else ("Publish status: failed, Queue(#{queue}) doesn't exist.") ("Content : #{payload}") raise QueueNotFoundError end end |
#unicast(q_name, payload = {}) ⇒ Object
unicast message to queues
35 36 37 38 39 40 41 |
# File 'lib/smart_que/publisher.rb', line 35 def unicast(q_name, payload = {}) x_default.publish( payload.to_json, routing_key: dot_formatted(q_name) ) ("unicast status: success, Queue : #{q_name}, Content : #{payload}") end |