【发布时间】:2014-01-24 21:17:40
【问题描述】:
我正在编写一个基本示例,但无法解决。
我需要通过队列 (TestQ) 将消息从一台机器 (Machine1) 转发到另一台 (Machine2)。 生产者在 Machine1 上运行,消费者在 Machine2 上运行。
我在 Machine1 的 rabbit broker 配置中的设置:
{rabbitmq_shovel, [ {shovels, [
{shovel_test, [
{sources, [{broker, "amqp://" }]},
{destinations, [{broker, "amqp://Machine2" }]},
{queue, <<"TestQ">>},
{ack_mode, on_confirm},
{reconnect_delay, 5}
]}
]} ]}
Machine2 有一个默认配置,没有启用铲子插件。
在 Machine1 上运行的生产者代码:
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 eval 'rabbit_shovel_status:status().'在机器 1 上:
[{shovel_test,starting,{{2014,1,7},{9,47,38}}}]
...done.
生产者发送正常,但我从未在 Machine2 上收到消费者的接收。
哪里出了问题? Machine1 的 broker 或 Machine2 的 broker 的 conf 中缺少什么?
谢谢!
【问题讨论】:
标签: jms rabbitmq message-forwarding rabbitmq-shovel