I'm new to Ruby, using Bunny to consume messages from RabbitMQ.
So my class currently looks roughly like this:
class Consumer
include Validator
def initialize
#Start a RabbitMQ session
@rdSession = Session.new
@queueMain = rdSession.joinQueue('QueueMain')
@queueLittle = rdSession.joinQueue('QueueLittle')
...
@queueTen = rdSession.joinQueue('QueueTen')
goWork
end
def goWork
@queueMain.subscribe(:manual_ack => true) do |delivery_info, properties, payload|
goDoSomethingElse(payload)
end
....
@queueTen.subscribe(:manual_ack => true) do |delivery_info, properties, payload|
goDoAnotherPiece(payload)
end
end
My question is the file is becoming quite long so I want to reduce it somehow. So one thing I thought of is as those moving that long list of joining queues in initialize
into another file as they are constant.
However what is the correct way to do this, should I create a module, copy across all those joinQueue
lines, then refer to them in goWork
as constants like: QUEUEMAIN
?
Any ideas/suggestions would be appreciated.
Trying to understand good design for this?
Thanks.