기본 예제를 작성 중이며 해결할 수 없습니다.RabbitMQ 삽 기본 예문
큐 (TestQ)를 통해 한 컴퓨터 (Machine1)에서 다른 컴퓨터 (Machine2)로 메시지를 전달해야합니다. 프로듀서는 Machine1에서 실행 중이며 Machine2의 소비자에서 실행 중입니다. 머신 1의 토끼 브로커 설정에서
내 설정 :
을 Machine2는 기본 설정을 가지고 있으며, 더 삽을 사용하지 플러그인이{rabbitmq_shovel, [ {shovels, [
{shovel_test, [
{sources, [{broker, "amqp://" }]},
{destinations, [{broker, "amqp://Machine2" }]},
{queue, <<"TestQ">>},
{ack_mode, on_confirm},
{reconnect_delay, 5}
]}
]} ]}
. 머신 1에서 실행
프로듀서의 코드 :
ConnectionFactory factory = new ConnectionFactory();
factory.setHost("localhost");
Connection connection = factory.newConnection();
Channel channel = connection.createChannel();
channel.queueDeclare("TestQ", true, false, false, null);
channel.basicPublish("", "TestQ", null, "Hello World!".getBytes());
machine2에서 실행 소비자의 코드 :
ConnectionFactory factory = new ConnectionFactory();
factory.setHost("localhost");
Connection connection = factory.newConnection();
Channel channel = connection.createChannel();
channel.queueDeclare("TestQ", true, false, false, null);
QueueingConsumer consumer = new QueueingConsumer(channel);
channel.basicConsume("TestQ", true, consumer);
while (true) {
QueueingConsumer.Delivery delivery = consumer.nextDelivery();
String message = new String(delivery.getBody());
System.out.println(" [x] Received '" + message + "'");
}
rabbitmqctl의 평가를 실행 'rabbit_shovel_status : 상태().' Machine1에서 :
[{shovel_test,starting,{{2014,1,7},{9,47,38}}}]
...done.
생산자는 정상적으로 전송하지만 Machine2의 소비자로부터 절대로받지 못합니다.
어디에 문제가 있습니까? Machine1의 중개인 또는 Machine2의 중개인의 conf에 뭔가가 없습니다.
감사합니다.
'brokers'는 유효한 옵션입니다. 실제로 코드는 괜찮습니다. 서버에서 포트를 열지 않은 문제를 발견했습니다. 그것은 모든 것을 해결했습니다. –