Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use Java RabbitMQ and set URI server?

I'm using the RabbitMQ Java API to connect to a RabbitMQ server. I want to use ConnectionFactory.setUri(...) to configure which server to use. It appears to munge the virtual host.

There's a default virtual host named /.

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

import java.net.URI;

public class Worker {

    public static void main(String[] argv) throws Exception {

        ConnectionFactory factory = new ConnectionFactory();
        final URI uri = URI.create("amqp://guest:guest@localhost:5672/");
        factory.setUri(uri);
        final Connection connection = factory.newConnection();
        final Channel channel = connection.createChannel();
    }
}

Using the above code, the configured virtual host is empty. There doesn't seem to be a way, using the URI, to configure the virtual host to be /.

Is there a way to do this?

like image 516
oconnor0 Avatar asked Dec 09 '22 14:12

oconnor0


1 Answers

I ended up solving this by not using setUri but rather setting the individual URI components.

like image 116
oconnor0 Avatar answered Jan 01 '23 23:01

oconnor0