Class: ActiveMessage::Broker
- Inherits:
-
Object
- Object
- ActiveMessage::Broker
- Includes:
- Singleton
- Defined in:
- lib/active_message/broker.rb
Instance Attribute Summary collapse
-
#configuration ⇒ Object
Returns the value of attribute configuration.
-
#connection ⇒ Object
Returns the value of attribute connection.
-
#exchange ⇒ Object
Returns the value of attribute exchange.
Instance Method Summary collapse
- #ack(channel, delivery_tag) ⇒ Object
- #connect(config) ⇒ Object
- #disconnect ⇒ Object
- #generate_id ⇒ Object
-
#initialize ⇒ Broker
constructor
A new instance of Broker.
- #nack(channel, delivery_tag) ⇒ Object
- #publish(routing_key, message, properties = {}) ⇒ Object
Constructor Details
#initialize ⇒ Broker
Returns a new instance of Broker.
7 8 |
# File 'lib/active_message/broker.rb', line 7 def initialize end |
Instance Attribute Details
#configuration ⇒ Object
Returns the value of attribute configuration.
5 6 7 |
# File 'lib/active_message/broker.rb', line 5 def configuration @configuration end |
#connection ⇒ Object
Returns the value of attribute connection.
5 6 7 |
# File 'lib/active_message/broker.rb', line 5 def connection @connection end |
#exchange ⇒ Object
Returns the value of attribute exchange.
5 6 7 |
# File 'lib/active_message/broker.rb', line 5 def exchange @exchange end |
Instance Method Details
#ack(channel, delivery_tag) ⇒ Object
29 30 31 |
# File 'lib/active_message/broker.rb', line 29 def ack(channel, delivery_tag) channel.ack(delivery_tag, false) end |
#connect(config) ⇒ Object
10 11 12 13 14 15 |
# File 'lib/active_message/broker.rb', line 10 def connect(config) @configuration = config @connection = Bunny.new(host: ActiveMessage::Configuration.get(:host), auth_mechanism: "EXTERNAL", tls: ActiveMessage::Configuration.get(:tls), tls_cert: ActiveMessage::Configuration.get(:tls_cert), tls_key: ActiveMessage::Configuration.get(:tls_key), tls_ca_certificates: ActiveMessage::Configuration.get(:tls_ca_certificates)) @connection.start @exchange = @connection.topic(@configuration[:exchange] || "demo", auto_delete: true) end |
#disconnect ⇒ Object
17 18 19 |
# File 'lib/active_message/broker.rb', line 17 def disconnect self.connection.close end |
#generate_id ⇒ Object
48 49 50 |
# File 'lib/active_message/broker.rb', line 48 def generate_id SecureRandom.uuid end |
#nack(channel, delivery_tag) ⇒ Object
33 34 35 |
# File 'lib/active_message/broker.rb', line 33 def nack(channel, delivery_tag) channel.nack(delivery_tag, false, false) end |
#publish(routing_key, message, properties = {}) ⇒ Object
37 38 39 40 41 42 43 44 45 46 |
# File 'lib/active_message/broker.rb', line 37 def publish(routing_key, , properties = {}) ActiveMessage::Logger.debug "Publishing Message => '#{message.inspect}' to #{routing_key}" non_overridable_properties = { routing_key: routing_key, timestamp: Time.now.to_i, content_type: 'application/json' } properties[:message_id] ||= generate_id exchange.publish(, { persistent: true }.merge(properties).merge(non_overridable_properties)) end |