TimeoutException (connection_closed_abruptly) when doing RabbitMQ Tutorial 1 for Java

1,164 views
Skip to first unread message

Sulaiman Rafiq

unread,
Oct 25, 2015, 5:29:26 PM10/25/15
to rabbitmq-users
Hi,

Tearing my hair out at this one, I can't figure out what I am missing :) New to rabbitMQ so trying to work through the tutorials. Unfortunately, I keep getting the the following exception:

Exception in thread "main" java.util.concurrent.TimeoutException
at com.rabbitmq.utility.BlockingCell.get(BlockingCell.java:77)
at com.rabbitmq.utility.BlockingCell.uninterruptibleGet(BlockingCell.java:111)
at com.rabbitmq.utility.BlockingValueOrException.uninterruptibleGetValue(BlockingValueOrException.java:37)
at com.rabbitmq.client.impl.AMQChannel$BlockingRpcContinuation.getReply(AMQChannel.java:367)
at com.rabbitmq.client.impl.AMQConnection.start(AMQConnection.java:293)
at com.rabbitmq.client.ConnectionFactory.newConnection(ConnectionFactory.java:648)
at com.rabbitmq.client.ConnectionFactory.newConnection(ConnectionFactory.java:678)

I have installed rabbitmq using homebrew on a macbook, running El Capitan. I can get to the management console (http://localhost:15672/#/)  fine in the browser without any problems. Looking at the report, rabbitmq is running on port 5672. I can telnet to this, no problems.

Below is the code I have written:

import com.rabbitmq.client.Channel;
import com.rabbitmq.client.Connection;
import com.rabbitmq.client.ConnectionFactory;

public class MainApp {

    private static final String QUEUE_NAME = "test_queue";

    public static void main(String[] args) throws Exception {
        final ConnectionFactory connectionFactory = new ConnectionFactory();
        connectionFactory.setConnectionTimeout(5000);
        connectionFactory.setUsername("guest");
        connectionFactory.setPassword("guest");
        connectionFactory.setHost("localhost");
        connectionFactory.setPort(5672);
        connectionFactory.setVirtualHost("rabbit@localhost");

        final Connection connection = connectionFactory.newConnection();
        final Channel channel = connection.createChannel();

        channel.queueDeclare(QUEUE_NAME, false, false, false, null);
        String message = "Hello World!";
        channel.basicPublish("", QUEUE_NAME, null, message.getBytes());

        channel.close();
        connection.close();
    }
}

With the rabbitmq-server running and the above code executed I see the TimeoutException. I have looked at the logs and interestingly see the following error:

=INFO REPORT==== 25-Oct-2015::21:13:28 ===

accepting AMQP connection <0.903.0> (127.0.0.1:50462 -> 127.0.0.1:5672)


=WARNING REPORT==== 25-Oct-2015::21:13:36 ===

closing AMQP connection <0.903.0> (127.0.0.1:50462 -> 127.0.0.1:5672):

connection_closed_abruptly



Can anyone please help in diagnosing this issue? There is a lot I want to do with RabbitMQ but can't get pass this first hurdle of connecting! Appreciate any help offered :)

Thanks
Sully


Michael Klishin

unread,
Oct 25, 2015, 5:32:08 PM10/25/15
to rabbitm...@googlegroups.com, Sulaiman Rafiq
On 26 October 2015 at 06:29:28, Sulaiman Rafiq (sulaima...@gmail.com) wrote:
> =WARNING REPORT==== 25-Oct-2015::21:13:36 ===
>
>
> closing AMQP connection <0.903.0> (127.0.0.1:50462 -> 127.0.0.1:5672):
>
>
> connection_closed_abruptly

This means that client closed TCP connection without closing AMQP 0-9-1 connection.
And on the client end, it didn’t finish connection negotiation in 5 seconds.

What else do you see in the log files (there are 2, regular and SASL) 
--
MK

Staff Software Engineer, Pivotal/RabbitMQ


Sulaiman Rafiq

unread,
Oct 25, 2015, 5:38:09 PM10/25/15
to rabbitmq-users, sulaima...@gmail.com
Nothing in the SASL log. Clearing down the log files and starting a clean instance of the rabbit server locally, below are all the log statements from the regular file:

=INFO REPORT==== 25-Oct-2015::21:35:52 ===

msg_store_transient: using rabbit_msg_store_ets_index to provide index


=INFO REPORT==== 25-Oct-2015::21:35:52 ===

msg_store_persistent: using rabbit_msg_store_ets_index to provide index


=WARNING REPORT==== 25-Oct-2015::21:35:52 ===

msg_store_persistent: rebuilding indices from scratch


=INFO REPORT==== 25-Oct-2015::21:36:00 ===

started TCP Listener on 127.0.0.1:5672


=INFO REPORT==== 25-Oct-2015::21:36:00 ===

rabbit_stomp: default user 'guest' enabled


=INFO REPORT==== 25-Oct-2015::21:36:00 ===

started STOMP TCP Listener on [::]:61613


=INFO REPORT==== 25-Oct-2015::21:36:08 ===

started MQTT TCP Listener on [::]:1883


=INFO REPORT==== 25-Oct-2015::21:36:16 ===

Management plugin started. Port: 15672


=INFO REPORT==== 25-Oct-2015::21:36:16 ===

Statistics database started.


=INFO REPORT==== 25-Oct-2015::21:36:16 ===

Server startup complete; 10 plugins started.

 * rabbitmq_management_visualiser

 * rabbitmq_management

 * rabbitmq_web_dispatch

 * webmachine

 * mochiweb

 * rabbitmq_mqtt

 * rabbitmq_stomp

 * rabbitmq_management_agent

 * rabbitmq_amqp1_0

 * amqp_client


=INFO REPORT==== 25-Oct-2015::21:36:27 ===

accepting AMQP connection <0.316.0> (127.0.0.1:50780 -> 127.0.0.1:5672)


=WARNING REPORT==== 25-Oct-2015::21:36:35 ===

closing AMQP connection <0.316.0> (127.0.0.1:50780 -> 127.0.0.1:5672):

connection_closed_abruptly

(END)

Sulaiman Rafiq

unread,
Oct 25, 2015, 5:42:11 PM10/25/15
to rabbitmq-users, sulaima...@gmail.com
FYI, I am using the latest amqp client (3.5.6) which has come out this month.

Michael Klishin

unread,
Oct 25, 2015, 6:08:10 PM10/25/15
to rabbitm...@googlegroups.com
While this should not cause a connection
negotiation in theory, this vhost is both
non-standardly named and certainly does not exist by default in our tutorials.

Default vhost is named / but it can be
any ASCII string (e.g. myproject_development).

Can you try with all defaults on ConnectionFactory?

> On 26 oct 2015, at 6:29, Sulaiman Rafiq <sulaima...@gmail.com> wrote:
>
> connectionFactory.setVirtualHost("rabbit@localhost");

Sulaiman Rafiq

unread,
Oct 25, 2015, 6:26:11 PM10/25/15
to rabbitmq-users
Hi Michael,

Stripped the code back to the following:

final ConnectionFactory connectionFactory = new ConnectionFactory();
final Connection connection = connectionFactory.newConnection();
final Channel channel = connection.createChannel();

channel.queueDeclare(QUEUE_NAME, false, false, false, null);
String message = "Hello World!";
channel.basicPublish("", QUEUE_NAME, null, message.getBytes());

channel.close();
connection.close();

Same error :( I've tried downgrading my amqp client but that made no difference. Could it be to do with the installation of rabbitmq? Maybe something went awry?

Michael Klishin

unread,
Oct 25, 2015, 6:29:04 PM10/25/15
to rabbitm...@googlegroups.com, Sulaiman Rafiq
On 26 October 2015 at 07:26:13, Sulaiman Rafiq (sulaima...@gmail.com) wrote:
> Same error :( I've tried downgrading my amqp client but that
> made no difference. Could it be to do with the installation of
> rabbitmq? Maybe something went awry?

I don’t remember ever seeing a connection negotiation timeout with nothing in the logs and succeeding TCP connection.

I recommend two things:

 * Try standalone RabbitMQ build *without* Homebrew (simply download it from rabbitmq.com, unarchive and run with ./sbin/rabbitmq-server)
 * If the issue persists, use Wireshark to see what’s going on the wire (and post a capture here): https://www.rabbitmq.com/amqp-wireshark.html 

Sulaiman Rafiq

unread,
Oct 25, 2015, 6:38:04 PM10/25/15
to rabbitmq-users, sulaima...@gmail.com
Just tried a standalone installation (dropped it in the /tmp/ directory). The same error and log messages appear. Will hook up wireshark and see what it reveals.

Sulaiman Rafiq

unread,
Oct 25, 2015, 6:50:18 PM10/25/15
to rabbitmq-users, sulaima...@gmail.com
Couple of interesting things. Turning off my wifi (to have less noise in my wireshark capture) resulted in a different error being shown when I ran the code. 

Exception in thread "main" java.io.IOException
at com.rabbitmq.client.impl.AMQChannel.wrap(AMQChannel.java:106)
at com.rabbitmq.client.impl.AMQChannel.wrap(AMQChannel.java:102)
at com.rabbitmq.client.impl.AMQConnection.start(AMQConnection.java:350)
at com.rabbitmq.client.ConnectionFactory.newConnection(ConnectionFactory.java:621)
at com.rabbitmq.client.ConnectionFactory.newConnection(ConnectionFactory.java:648)
at Main.main(Main.java:14)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:497)
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:140)
Caused by: com.rabbitmq.client.ShutdownSignalException: connection error
at com.rabbitmq.utility.ValueOrException.getValue(ValueOrException.java:67)
at com.rabbitmq.utility.BlockingValueOrException.uninterruptibleGetValue(BlockingValueOrException.java:37)
at com.rabbitmq.client.impl.AMQChannel$BlockingRpcContinuation.getReply(AMQChannel.java:367)
at com.rabbitmq.client.impl.AMQConnection.start(AMQConnection.java:293)
... 8 more
Caused by: java.io.EOFException
at java.io.DataInputStream.readUnsignedByte(DataInputStream.java:290)
at com.rabbitmq.client.impl.Frame.readFrom(Frame.java:95)
at com.rabbitmq.client.impl.SocketFrameHandler.readFrame(SocketFrameHandler.java:139)
at com.rabbitmq.client.impl.AMQConnection$MainLoop.run(AMQConnection.java:536)
at java.lang.Thread.run(Thread.java:745)

A red herring or a possible issue?

Michael Klishin

unread,
Oct 25, 2015, 8:13:16 PM10/25/15
to rabbitm...@googlegroups.com, sulaima...@gmail.com
I/O exceptions can mean a lot different things but this is a TCP connection loss.

See server logs for possible clues.
--
You received this message because you are subscribed to the Google Groups "rabbitmq-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rabbitmq-user...@googlegroups.com.
To post to this group, send email to rabbitm...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Noel da Costa

unread,
Mar 22, 2017, 4:06:06 AM3/22/17
to rabbitmq-users, sulaima...@gmail.com
Hi Sulaiman,

Did you ever solve this problem? I'm getting the same error (connection_closed_abruptly).

Michael Klishin

unread,
Mar 22, 2017, 4:44:35 AM3/22/17
to rabbitm...@googlegroups.com, Sulaiman Rafiq
Please start new threads for new questions.

`connection_closed_abruptly` means that as far as RabbitMQ is concerned, a client or proxy or load balancer
closed TCP connection without closing AMQP 0-9-1 (or STOMP, or …) connection first.

It could be due to applications naturally terminating (e.g. scripts), load balancers closing what they believe
to be inactive TCP connections (see http://www.rabbitmq.com/heartbeats.html), applications failing,
and so on. It is harmless as far as RabbitMQ is concerned but can be an indicator of something worth investigating.

--
You received this message because you are subscribed to the Google Groups "rabbitmq-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rabbitmq-users+unsubscribe@googlegroups.com.
To post to this group, send email to rabbitmq-users@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

Noel da Costa

unread,
Apr 17, 2017, 8:36:23 AM4/17/17
to rabbitm...@googlegroups.com
Hi,

I’m having an issue with the RabbitMQ web monitor application where – it works in the sense that I can browse to it and login but it doesn’t work in the sense that it doesn't register any queues / messages even though RabbitMQ is working.

The graph is set to update every few seconds and it shows the last minute of activity but no queues ever show, nor do messages or channels. This is despite the fact that the underlying RabbitMQ implementation is actually working and happily sending messages etc.

How can I debug this?
What could the issue be?


Kind Regards,
Noel

Michael Klishin

unread,
Apr 17, 2017, 10:05:44 AM4/17/17
to rabbitm...@googlegroups.com
Check what vhosts your user has access to and which one is selected in the top right corner.

If this is on a local or development machine then try with a user tagged with the administrator tag first.

--
You received this message because you are subscribed to the Google Groups "rabbitmq-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rabbitmq-user...@googlegroups.com.
To post to this group, send an email to rabbitm...@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.
--
Staff Software Engineer, Pivotal/RabbitMQ

Rodrigo Vale

unread,
Dec 8, 2022, 11:52:28 PM12/8/22
to rabbitmq-users
Same error here, but the request does work with wget as shown below
wget --user guest --password guest http://192.168.86.25:15672/api/exchanges/%2F/amq.default/publish --post-file=payload.json 

payload.json
{
 "vhost": "/",
 "name": "amq.default",
 "properties": {
   "delivery_mode": 1,
   "headers": {}
 },
 "routing_key": "BodyBuilder",
 "delivery_mode": "1",
 "payload": "hello3",
 "payload_encoding": "string",
 "headers": {},
 "props": {}
}

Java Code with java.util.concurrent.TimeoutException on the red line below

        ConnectionFactory factory = new ConnectionFactory();
        factory.setHost("192.168.86.25");
        factory.setPort(15672);
        factory.setUsername("guest");
        factory.setPassword("guest");
        Connection connection;
        try {
            connection = factory.newConnection();

            Channel channel = connection.createChannel();

            channel.queueDeclare(QUEUE_NAME, false, false, false, null);
            String message = "Hello World!";
            channel.basicPublish("", QUEUE_NAME, null,
                    message.getBytes(StandardCharsets.UTF_8));
            System.out.println(" [x] Sent '" + message + "'");
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
            System.out.println(e.getMessage());            
        } catch (TimeoutException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
            System.out.println(e.getMessage());
        }

Using Maven
<dependencies>  
<!-- https://mvnrepository.com/artifact/com.rabbitmq/amqp-client -->
<dependency>
    <groupId>com.rabbitmq</groupId>
    <artifactId>amqp-client</artifactId>
    <version>5.16.0</version>
</dependency>
</dependencies> 

Rodrigo Vale

unread,
Dec 9, 2022, 1:22:59 AM12/9/22
to rabbitm...@googlegroups.com
I was able to publish a message from Java using HTTP request as defined in wget, still no luck with connection = factory.newConnection();

Rodrigo Vale


Arnaud Cogoluègnes

unread,
Dec 9, 2022, 3:10:55 AM12/9/22
to rabbitmq-users
Anything in the broker logs?
Reply all
Reply to author
Forward
0 new messages