Sha256: 6281f52d644ac3debdf4d792e5339ca9fca09c5cc831e630f93f19ec3f54b7d4
Contents?: true
Size: 1.77 KB
Versions: 1
Compression:
Stored size: 1.77 KB
Contents
require_relative "publishers/base" module SmartQue class Publisher < Publishers::Base # Initialize def initialize queue_list.each do |q_name| find_or_initialize_queue(q_name) end end # Instance methods # Publish message to the respective queue 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 ) log_message("Publish status: success, Queue : #{queue}, Content : #{payload}") else log_message("Publish status: failed, Queue(#{queue}) doesn't exist.") log_message("Content : #{payload}") raise QueueNotFoundError end end # unicast message to queues def unicast(q_name, payload = {}) x_default.publish( payload.to_json, routing_key: dot_formatted(q_name) ) log_message("unicast status: success, Queue : #{q_name}, Content : #{payload}") end # multicast message to queues based on topic subscription def multicast(topic, payload = {}) begin x_topic.publish( payload.to_json, routing_key: dot_formatted(topic) ) log_message("multicast status: success, Topic : #{topic}, Content : #{payload}") :success rescue => ex log("#{ex.message}") :error end end # broadcast message to queues based on topic subscription def broadcast(payload = {}) x_fanout.publish( payload.to_json ) log_message("broadcast status: success, Content : #{payload}") end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
smart-que-0.2.5 | lib/smart_que/publisher.rb |