RabbitMQ Shovel basic example

6.4k Views Asked by At

I am working on a basic example and am not able to work it out.

I need to forward messages from one machine (Machine1) to another (Machine2) via a queue (TestQ). Producer is running on the Machine1 and a consumer on the Machine2.

My settings in the Machine1's rabbit broker config:

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

Machine2 has a default config and no shovel plugin enabled.

Producer's code running on the 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());

Consumer's code running on the 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 + "'");
}

Executing rabbitmqctl eval 'rabbit_shovel_status:status().' on the Machine1:

[{shovel_test,starting,{{2014,1,7},{9,47,38}}}]
...done.

Producer sends ok, but I never get a receive from the consumer on the Machine2.

Where is a problem? Something is missing in the conf of Machine1's broker, or Machine2's broker?

Thank you!

1

There are 1 best solutions below

1
ldx On

The status of your shovel should be running, not starting. If it stays in the starting phase, that means it can't start up correctly (e.g. can't connect to the destination broker).

One problem I spotted is that you used broker instead of brokers for specifying the list of sources. Try this:

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