tlapeg07
tlapeg07

Reputation: 103

RabbitMQ messages are not consummed

I would like to use RabbitMQ to send messages from a webapp backend to a second module. On my laptop, it works, but when I deploy the application on a VPS, even in dev mode, it doesn't work anymore... Could you please help me solve this out?

Current status :

If I check the queues on the VPS where both modules are installed, then, it looks ok (messages are added in the queue)

$ rabbitmqctl list_queues
Timeout: 60.0 seconds ...
Listing queues for vhost / ...
MyMessages        2

When I launch the second module, I get following log :

Waiting for a request on queue : MyMessages, hosted at localhost

Comming from the following java code :

public static void main(String[] args) throws IOException, TimeoutException {
    RabbitMQConsumer rabbitMQConsumer = new RabbitMQConsumer();
    rabbitMQConsumer.waitForRequests();
    System.out.println("Waiting for a request on queue : " + AppConfig.QUEUE_NAME + ", hosted at " + AppConfig.QUEUE_HOST);
}

public RabbitMQConsumer() throws IOException, TimeoutException {
    mapper = new ObjectMapper();
    ConnectionFactory connectionFactory = new ConnectionFactory();
    connectionFactory.setHost(AppConfig.QUEUE_HOST);
    Connection connection = connectionFactory.newConnection();
    channel = connection.createChannel();
}

public void waitForRequests() throws IOException {
    DefaultConsumer consumer = new DefaultConsumer(channel) {
        @Override
        public void handleDelivery(String consumerTag, Envelope envelope, AMQP.BasicProperties properties, byte[] body) throws IOException {
            try {
                System.out.println("Message received ! ");
                channel.basicAck(envelope.getDeliveryTag(), false);
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    };
    channel.queueDeclare(AppConfig.QUEUE_NAME, true, false, false, null);
    channel.basicConsume(AppConfig.QUEUE_NAME, consumer);
}

I think both modules are looking at the same queue, there are messages in the quue, so... to me, it looks like messages are not consummed... I've looked at the status of rabbitMQ, but I do not know how to use it :

$ invoke-rc.d rabbitmq-server status
● rabbitmq-server.service - RabbitMQ broker
   Loaded: loaded (/lib/systemd/system/rabbitmq-server.service; enabled; vendor preset: enabled)
   Active: active (running) since Sat 2018-04-07 18:24:59 CEST; 1h 38min ago
  Process: 17103 ExecStop=/usr/lib/rabbitmq/bin/rabbitmqctl shutdown (code=exited, status=0/SUCCESS)
 Main PID: 17232 (beam.smp)
   Status: "Initialized"
    Tasks: 84 (limit: 4915)
   CGroup: /system.slice/rabbitmq-server.service
           ├─17232 /usr/lib/erlang/erts-9.3/bin/beam.smp -W w -A 64 -P 1048576 -t 5000000 -stbt db -zdbbl 1280000 -K true -- -root /usr/lib/erlang -progname erl -- -home /var/lib/rabbitmq -- -pa /usr/lib/r
abbitmq/lib/rabbitmq_server-3.7.4/ebin -noshell -noinput -s rabbit boot -sname rabbit@vps5322 -boot start_sasl -kernel inet_default_connect_options [{nodelay,true}] -sasl errlog_type error -sasl sasl_err
or_logger false -rabbit lager_log_root "/var/log/rabbitmq" -rabbit lager_default_file "/var/log/rabbitmq/[email protected]" -rabbit lager_upgrade_file "/var/log/rabbitmq/rabbit@vps5322_upgrade.log" -r
abbit enabled_plugins_file "/etc/rabbitmq/enabled_plugins" -rabbit plugins_dir "/usr/lib/rabbitmq/plugins:/usr/lib/rabbitmq/lib/rabbitmq_server-3.7.4/plugins" -rabbit plugins_expand_dir "/var/lib/rabbitmq/
mnesia/rabbit@vps5322-plugins-expand" -os_mon start_cpu_sup false -os_mon start_disksup false -os_mon start_memsup false -mnesia dir "/var/lib/rabbitmq/mnesia/rabbit@vps5322" -kernel inet_dist_listen_m
in 25672 -kernel inet_dist_listen_max 25672
           ├─17319 /usr/lib/erlang/erts-9.3/bin/epmd -daemon
           ├─17453 erl_child_setup 1024
           ├─17475 inet_gethost 4
           └─17476 inet_gethost 4

Apr 07 18:24:57 vps5322 rabbitmq-server[17232]:   ##  ##
Apr 07 18:24:57 vps5322 rabbitmq-server[17232]:   ##  ##      RabbitMQ 3.7.4. Copyright (C) 2007-2018 Pivotal Software, Inc.
Apr 07 18:24:57 vps5322 rabbitmq-server[17232]:   ##########  Licensed under the MPL.  See http://www.rabbitmq.com/
Apr 07 18:24:57 vps5322 rabbitmq-server[17232]:   ######  ##
Apr 07 18:24:57 vps5322 rabbitmq-server[17232]:   ##########  Logs: /var/log/rabbitmq/[email protected]
Apr 07 18:24:57 vps5322 rabbitmq-server[17232]:                     /var/log/rabbitmq/rabbit@vps5322_upgrade.log
Apr 07 18:24:57 vps5322 rabbitmq-server[17232]:               Starting broker...
Apr 07 18:24:59 vps5322 rabbitmq-server[17232]: systemd unit for activation check: "rabbitmq-server.service"
Apr 07 18:24:59 vps5322 systemd[1]: Started RabbitMQ broker.
Apr 07 18:24:59 vps5322 rabbitmq-server[17232]:  completed with 0 plugins.

Finally, note that the webapp application is a PlayFramework app, with these dependencies :

libraryDependencies ++= Seq(
  guice,
  "com.rabbitmq" % "amqp-client" % "5.2.0"
)

Whereas the second module is a pure java code, based on maven, with the following pom :

<dependency>
    <groupId>com.rabbitmq</groupId>
    <artifactId>amqp-client</artifactId>
    <version>5.2.0</version>
</dependency>

Any idea of the problem? Thank you very much !!

Upvotes: 2

Views: 826

Answers (1)

tlapeg07
tlapeg07

Reputation: 103

Finally I've found the problem. This configuration is actually working, but I could not see it because of a crash in my own app that was not logged because of an error in my log4J configuration.

Just in case, the error I had was that a local library included in my pom with a relative path (${project.basedir}) was found by my IDE but not anymore once deployed on a VPS. To solve this, I've just moved this (hopefully) very small library directly into my project. After solving this issue, I had to reset rabbitMQ and then it was all fine :

rabbitmqctl stop_app rabbitmqctl reset rabbitmqctl start_app

Thank you very much, Regards,

Upvotes: 1

Related Questions