My controller is defined as follows with a create method.
class AtestController < BaseController
def create
result = create_something(params)
@connection = Bunny.new
@connection.start
@channel = @connection.create_channel
bunny = RabbitPublisherService::RabbitPublisher.new(@channel,@connection)
render :json => trigger, :status => :created
end
end
My Rabbit Publisher Service is defined as follows
module RabbitPublisherService
class RabbitPublisher
private
attr_accessor :channel, :connection
def initialize(channel, connection)
puts "I reached here"
@channel = channel
@connection = connection
end
def publish(message)
q = @channel.queue("task_queue", :durable => true)
q.publish(message, :persistent => true)
puts "Message is Published..."
sleep 1.0
@connection.close
end
end
end
When I try calling this service from the controllers create method, RabbitPublisherService::RabbitPublisher.new, I get an uninitialized constant error saying :error_message=>"uninitialized constant AtestController::RabbitPublisherService"
Can someone please help me find out what I am doing wrong?
include RabbitPublisherService
to the controller – Algae