As Aaron Henderson said, you just need a global variable which holds the connection session.
You can specify name while creating queues, and same name can be used to
access it and the id parameter can be used to access the channel.
Initialize Bunny client with options like host, port and credentials:
$rmq_session = Bunny.new(
host: host,
port: port,
username: username,
password: password
)
$rmq_session.start
Create a channel with the bunny session.
sample_channel = $rmq_session.create_channel
The same channel can be accessed by the id parameter.
$rmq_session.channel(sample_channel.id)
Channels are identified by their ids which are integers. Bunny takes care of allocating and releasing them as channels are opened and closed. It is almost never necessary to specify channel ids explicitly. There is a limit on the maximum number of channels per connection, usually 65536. Note that allocating channels is very cheap on both client and server so having tens, hundreds or even thousands of channels is not a problem Read more about channel here.
Create a queue with the bunny session.
sample_queue = sample_channel.queue('sample.queue')
You can access the above created queue by referring the queue name. This will not create new queue if already one exists.
sample_queue = sample_channel.queue('sample.queue')