Class: Artsy::EventService::RabbitMQConnection
- Inherits:
-
Object
- Object
- Artsy::EventService::RabbitMQConnection
- Defined in:
- lib/artsy-eventservice/artsy/event_service/rabbitmq_connection.rb
Class Method Summary collapse
-
.build_connection ⇒ Object
Build a new connection to RabbitMQ.
- .bunny_params ⇒ Object
- .config ⇒ Object
-
.get_channel ⇒ Object
Get a channel from the connection - synchronized access to create_channel is provided by Bunny.
-
.get_connection ⇒ Object
Synchronized access to the connection.
- .no_tls_params ⇒ Object
- .rabbitmq_url ⇒ Object
- .tls_params ⇒ Object
Class Method Details
.build_connection ⇒ Object
Build a new connection to RabbitMQ
11 12 13 14 15 |
# File 'lib/artsy-eventservice/artsy/event_service/rabbitmq_connection.rb', line 11 def self.build_connection conn = Bunny.new(self.rabbitmq_url, **self.bunny_params) conn.start conn end |
.bunny_params ⇒ Object
36 37 38 |
# File 'lib/artsy-eventservice/artsy/event_service/rabbitmq_connection.rb', line 36 def self.bunny_params self.config.tls ? self.tls_params : self.no_tls_params end |
.config ⇒ Object
54 55 56 |
# File 'lib/artsy-eventservice/artsy/event_service/rabbitmq_connection.rb', line 54 def self.config Artsy::EventService.config end |
.get_channel ⇒ Object
Get a channel from the connection - synchronized access to create_channel is provided by Bunny
25 26 27 28 29 30 |
# File 'lib/artsy-eventservice/artsy/event_service/rabbitmq_connection.rb', line 25 def self.get_channel channel = self.get_connection.create_channel yield channel if block_given? ensure channel.close if channel && channel.open? end |
.get_connection ⇒ Object
Synchronized access to the connection
18 19 20 21 22 |
# File 'lib/artsy-eventservice/artsy/event_service/rabbitmq_connection.rb', line 18 def self.get_connection @mutex.synchronize do @connection ||= self.build_connection end end |
.no_tls_params ⇒ Object
50 51 52 |
# File 'lib/artsy-eventservice/artsy/event_service/rabbitmq_connection.rb', line 50 def self.no_tls_params {} end |
.rabbitmq_url ⇒ Object
32 33 34 |
# File 'lib/artsy-eventservice/artsy/event_service/rabbitmq_connection.rb', line 32 def self.rabbitmq_url self.config.rabbitmq_url end |
.tls_params ⇒ Object
40 41 42 43 44 45 46 47 48 |
# File 'lib/artsy-eventservice/artsy/event_service/rabbitmq_connection.rb', line 40 def self.tls_params { tls: self.config.tls, tls_cert: self.config.tls_cert, tls_key: self.config.tls_key, tls_ca_certificates: [self.config.tls_ca_certificate], verify_peer: self.config.verify_peer } end |