24 lines
599 B
Ruby
24 lines
599 B
Ruby
require 'sylvilagus/init'
|
|
require 'sylvilagus/ch02'
|
|
|
|
require 'rabbitmq-client.jar'
|
|
import com.rabbitmq.client.ConnectionFactory
|
|
|
|
module Sylvilagus::Ch02::HelloWorld
|
|
module ClassMethods
|
|
def with_hello_world_channel(&block)
|
|
factory = ConnectionFactory.new
|
|
factory.uri = ENV.fetch('SYLVILAGUS_AMQP_URI')
|
|
conn = factory.new_connection
|
|
|
|
channel = conn.create_channel
|
|
channel.exchange_declare('hello-exchange', 'direct', true)
|
|
channel.queue_declare('hello-queue', false, false, false, nil)
|
|
|
|
block.call(channel)
|
|
ensure
|
|
conn.close
|
|
end
|
|
end
|
|
end
|