2013-10-10 1 views
0

내 rSpec 테스트에서 AMQP에 연결하는 데 문제가 있습니다. 나는 RSpec에 실행할 때메시지를 보내려면 AMQP에 두 번 연결할 수 없습니다.

Module Rabbit 
    Class Client 

    def start 
     EventMachine.run do 
     connection = AMQP.connect(Settings_object) #it holds host, username and password information 

     channel = AMQP::Channel.new(connection) 
     channel.queue("queue_name", :durable => true) 
     channel.default_exchange.publish("A test message", :routing_key => "queue_name")  

     end 
    end 
end 


Module Esper 
    Class Server 

    def start 
     EventMachine.run do 
     connection = AMQP.connect(Settings_object) #it holds host, username and password information 

     =begin 
     Some code to subscribe to queues 
     =end 

     end 
    end 
end 

내 문제는 다음과 같습니다 : 나는 다음과 같은 코드가 첫 번째 클라이언트에서

@client = Rabbit::Client.new 
@server = Esper::Server.new 

Thread.new do 
    @client.start 
end 
Thread.new do 
    @server.start 
end 

는 AMQP에 연결할 수 있으며, 서버는하지 않습니다,하지만 난 때 두 번째로 실행하면 클라이언트가 서버에 연결할 수 없습니다. 나는이 문제를 극복하기 위해 볼 수 없다. 클라이언트가 두 번째 실행시 연결을 중지하는 이유가 표시되지 않습니까?

답변

0

이 문제의 근본 원인은 AMQP의 모든 대기열에 별도의 연결이 있어야한다는 것입니다. 예 :

queue1_connectom = AMQP::Channel.new(connection) 
queue2_connectom = AMQP::Channel.new(connection) 

이렇게 사용하십시오.

하지만이 전체적인 상황에서는 전체적으로 deamon-kit 보석을 사용하는 것이 좋습니다. AMQP는 별도의 응용 프로그램으로 분리되며 AMQP 연결은 해당 "응용 프로그램"또는 더 나은 아직 처리되지 않습니다 - Deamon.

또한 AMQP 용 생성기가 있으므로 사용하는 것이 좋습니다.

관련 문제