Class: Istox::Publisher
- Inherits:
-
Object
- Object
- Istox::Publisher
- Defined in:
- lib/istox/helpers/publisher.rb
Overview
Publisher is relying on BunnyBoot to publish message, please make sure BunnyBoot is initalised properly first during runtime.
Class Method Summary collapse
-
.manual_publish(exchange:, routing_key: nil, message:, exchange_type: 'direct', exchange_durable: true, options: {}) ⇒ Object
publish without defining exchange and queue in amqp.yml.
-
.publish(exchange: nil, routing_key: nil, message:, options: {}) ⇒ Object
routing_key can be nil if publishing to fanout exchange exchange can be nil if routing_key is unique in “publish” section, this function will be able to identify which exchange it is using else both routing_key and exchange should be provided check reference.rubybunny.info/Bunny/Exchange.html#publish-instance_method for available publish options.
Class Method Details
.manual_publish(exchange:, routing_key: nil, message:, exchange_type: 'direct', exchange_durable: true, options: {}) ⇒ Object
publish without defining exchange and queue in amqp.yml
37 38 39 40 41 42 43 |
# File 'lib/istox/helpers/publisher.rb', line 37 def manual_publish(exchange:, routing_key: nil, message:, exchange_type: 'direct', exchange_durable: true, options: {}) [:durable] = [:durable].nil? ? true : [:durable] [:persistent] = [:persistent].nil? ? true : [:persistent] (exchange: exchange, routing_key: routing_key, message: , exchange_type: exchange_type, exchange_durable: exchange_durable, options: ) end |
.publish(exchange: nil, routing_key: nil, message:, options: {}) ⇒ Object
routing_key can be nil if publishing to fanout exchange exchange can be nil if routing_key is unique in “publish” section, this function will be able to identify which exchange it is using else both routing_key and exchange should be provided check reference.rubybunny.info/Bunny/Exchange.html#publish-instance_method for available publish options
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/istox/helpers/publisher.rb', line 11 def publish(exchange: nil, routing_key: nil, message:, options: {}) raise 'Exchange and routing key cannot be nil at the same time.' if exchange.nil? && routing_key.nil? queue_publish_config = nil if routing_key.present? exchange = search_exchange_of_routing_key!(routing_key) if exchange.nil? puts "EXCYANGE IS #{exchange}" queue_publish_config = queue_publish_config!(routing_key: routing_key, exchange: exchange) end exchange_config = exchange_config!(exchange) exchange_durable = exchange_config['durable'].nil? ? true : exchange_config['durable'] queue_durable = queue_publish_config.present? ? queue_publish_config['durable'] : nil queue_durable = exchange_config['durable'].nil? ? true : exchange_config['durable'] if queue_durable.nil? [:durable] = queue_durable [:persistent] = [:persistent].nil? ? true : [:persistent] (exchange: exchange, routing_key: routing_key, message: , exchange_type: exchange_config['type'], exchange_durable: exchange_durable, options: ) end |