From 4c840bdff0a733018557ebc530bd7a1f6df0ada2 Mon Sep 17 00:00:00 2001 From: Brusk Awat Date: Wed, 1 Mar 2023 00:43:11 +0300 Subject: [PATCH] Adds singleton connection class --- lib/outboxable/connection.rb | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 lib/outboxable/connection.rb diff --git a/lib/outboxable/connection.rb b/lib/outboxable/connection.rb new file mode 100644 index 0000000..af3f92c --- /dev/null +++ b/lib/outboxable/connection.rb @@ -0,0 +1,26 @@ +require 'singleton' + +module Outboxable + class Connection + include ::Singleton + attr_reader :connection + + def initialize + @connection = Bunny.new( + host: RabbitCarrots.configuration.rabbitmq_host, + port: RabbitCarrots.configuration.rabbitmq_port, + user: RabbitCarrots.configuration.rabbitmq_user, + password: RabbitCarrots.configuration.rabbitmq_password, + vhost: RabbitCarrots.configuration.rabbitmq_vhost + ) + + @connection.start + end + + def channel + @channel ||= ConnectionPool.new do + connection.create_channel + end + end + end +end