【问题标题】:RabbitMQ Shovel basic exampleRabbitMQ Shovel 基本示例
【发布时间】: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


    【解决方案1】:

    你的铲子的状态应该是running,而不是starting。如果它停留在starting 阶段,则意味着它无法正确启动(例如,无法连接到目标代理)。

    我发现的一个问题是您使用broker 而不是brokers 来指定源列表。试试这个:

    {rabbitmq_shovel,
     [{shovels, [{shovel_test,
                  [{sources, [{brokers, ["amqp://"]}]},
                   {destinations, [{broker, "amqp://Machine2"}]},
                   {queue, <<"TestQ">>},
                   {ack_mode, on_confirm},
                   {reconnect_delay, 5}
                  ]}
                ]}
     ]}.
    

    【讨论】:

    • brokers 是一个有效的选项,实际上代码是好的,我发现服务器上没有打开端口的问题。这解决了一切。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-07-11
    • 2015-08-15
    • 2021-05-04
    • 2010-10-10
    • 1970-01-01
    相关资源
    最近更新 更多