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
38 39 40 |
# File 'lib/artsy-eventservice/artsy/event_service/rabbitmq_connection.rb', line 38 def self.bunny_params self.config.tls ? self.tls_params : self.no_tls_params end |
.config ⇒ Object
56 57 58 |
# File 'lib/artsy-eventservice/artsy/event_service/rabbitmq_connection.rb', line 56 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
27 28 29 30 31 32 |
# File 'lib/artsy-eventservice/artsy/event_service/rabbitmq_connection.rb', line 27 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 23 24 |
# File 'lib/artsy-eventservice/artsy/event_service/rabbitmq_connection.rb', line 18 def self.get_connection @mutex.synchronize do @connection ||= self.build_connection @connection = self.build_connection if @connection.closed? @connection end end |
.no_tls_params ⇒ Object
52 53 54 |
# File 'lib/artsy-eventservice/artsy/event_service/rabbitmq_connection.rb', line 52 def self.no_tls_params {} end |
.rabbitmq_url ⇒ Object
34 35 36 |
# File 'lib/artsy-eventservice/artsy/event_service/rabbitmq_connection.rb', line 34 def self.rabbitmq_url self.config.rabbitmq_url end |
.tls_params ⇒ Object
42 43 44 45 46 47 48 49 50 |
# File 'lib/artsy-eventservice/artsy/event_service/rabbitmq_connection.rb', line 42 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 |