Class: Asynk::Broker

Inherits:
Object
  • Object
show all
Defined in:
lib/asynk/broker.rb

Class Method Summary collapse

Class Method Details

.amqp_connectionObject



30
# File 'lib/asynk/broker.rb', line 30

def amqp_connection; @amqp_connection; end

.connectObject



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/asynk/broker.rb', line 6

def connect
  @amqp_connection = Bunny.new(host: Asynk.config[:mq_host],
                               port: Asynk.config[:mq_port],
                           username: Asynk.config[:mq_username],
                           password: Asynk.config[:mq_password],
                              vhost: Asynk.config[:mq_vhost])
  Asynk.logger.info [ "Connection to Rabbit with params host: #{Asynk.config[:mq_host]}:#{Asynk.config[:mq_port]}",
                      "username: '#{Asynk.config[:mq_username]}' ", "vhost: '#{Asynk.config[:mq_vhost]}'"
                    ].join(' ')

  @amqp_connection.start

  @pool = ConnectionPool.new(size: 10, timeout: 5) do
    channel = @amqp_connection.create_channel(nil, nil)
    [channel, channel.topic(Asynk.config[:mq_exchange]), channel.queue('', exclusive: true)]
  end
end

.disconnectObject



24
25
26
27
# File 'lib/asynk/broker.rb', line 24

def disconnect
  @amqp_connection.close if @amqp_connection
  @amqp_connection = nil
end

.poolObject



29
# File 'lib/asynk/broker.rb', line 29

def pool; @pool; end