Virtual Host is not set when calling setUri() from ConnectionFactory when URI as a trailing slash #1977
-
Describe the bugWe noticed that when using Config:
Reproduction stepsTo reproduce this bug you can simply use the client like this class App {
public static void main(String[] args) {
String s = "amqp://guest:guest@localhost:5672/";
try {
ConnectionFactory factory = new ConnectionFactory();
factory.setUri(s);
// you can uncomment the line below to check virtualhost before it crashes.
//System.out.println(factory.getVirtualHost());
Connection connection = factory.newConnection();
// .... rest of code
} catch (Exception e) {
e.printStackTrace();
}
}
}When running the code we get the following stack trace: java.io.IOException
at com.rabbitmq.client.impl.AMQChannel.wrap(AMQChannel.java:140)
at com.rabbitmq.client.impl.AMQChannel.wrap(AMQChannel.java:136)
at com.rabbitmq.client.impl.AMQChannel.exnWrappingRpc(AMQChannel.java:158)
at com.rabbitmq.client.impl.AMQConnection.start(AMQConnection.java:459)
at com.rabbitmq.client.impl.recovery.RecoveryAwareAMQConnectionFactory.newConnection(RecoveryAwareAMQConnectionFactory.java:71)
at com.rabbitmq.client.impl.recovery.AutorecoveringConnection.init(AutorecoveringConnection.java:165)
at com.rabbitmq.client.ConnectionFactory.newConnection(ConnectionFactory.java:1350)
at com.rabbitmq.client.ConnectionFactory.newConnection(ConnectionFactory.java:1299)
at com.rabbitmq.client.ConnectionFactory.newConnection(ConnectionFactory.java:1254)
at com.rabbitmq.client.ConnectionFactory.newConnection(ConnectionFactory.java:1629)
at com.debbech.test.App.main(App.java:30)
Caused by: com.rabbitmq.client.ShutdownSignalException: connection error; protocol method: #method<connection.close>(reply-code=530, reply-text=NOT_ALLOWED - vhost not found, class-id=10, method-id=40)
at com.rabbitmq.utility.ValueOrException.getValue(ValueOrException.java:66)
at com.rabbitmq.utility.BlockingValueOrException.uninterruptibleGetValue(BlockingValueOrException.java:36)
at com.rabbitmq.client.impl.AMQChannel$BlockingRpcContinuation.getReply(AMQChannel.java:552)
at com.rabbitmq.client.impl.AMQChannel.privateRpc(AMQChannel.java:316)
at com.rabbitmq.client.impl.AMQChannel.exnWrappingRpc(AMQChannel.java:152)
... 8 moreAnd the RabbitMQ server logs show this: 2026-06-01 22:26:13.964685+00:00 [info] <0.672.0> accepting AMQP connection 172.17.0.1:42988 -> 172.17.0.2:5672
2026-06-01 22:26:13.982722+00:00 [error] <0.672.0> Error on AMQP connection <0.672.0> (172.17.0.1:42988 -> 172.17.0.2:5672, user: 'guest', state: opening):
2026-06-01 22:26:13.982722+00:00 [error] <0.672.0> vhost not found
2026-06-01 22:26:13.983938+00:00 [info] <0.672.0> closing AMQP connection (172.17.0.1:42988 -> 172.17.0.2:5672, vhost: 'none', user: 'guest', duration: '33ms')
2026-06-01 22:26:13.984865+00:00 [info] <0.681.0> accepting AMQP connection 172.17.0.1:42994 -> 172.17.0.2:5672
2026-06-01 22:26:13.986469+00:00 [error] <0.681.0> Error on AMQP connection <0.681.0> (172.17.0.1:42994 -> 172.17.0.2:5672, user: 'guest', state: opening):
2026-06-01 22:26:13.986469+00:00 [error] <0.681.0> vhost not found
2026-06-01 22:26:13.986839+00:00 [info] <0.681.0> closing AMQP connection (172.17.0.1:42994 -> 172.17.0.2:5672, vhost: 'none', user: 'guest', duration: '2ms')Expected behaviorThe Additional contextNo response |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
|
The current behavior does follow the AMQP URI spec, though it may not be very intuitive. As soon as you have a trailing In your case, this should be the URI string: |
Beta Was this translation helpful? Give feedback.
The current behavior does follow the AMQP URI spec, though it may not be very intuitive. As soon as you have a trailing
/, the spec says a virtual host must be present.In your case, this should be the URI string: