如何使用Java RabbitMQ并设置URI服务器? [英] How to use Java RabbitMQ and set URI server?

查看:774
本文介绍了如何使用Java RabbitMQ并设置URI服务器?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用RabbitMQ Java API连接到RabbitMQ服务器.我想使用ConnectionFactory.setUri(...)配置要使用的服务器.它似乎在破坏虚拟主机.

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();
    }
}

使用上面的代码,配置的虚拟主机为空.似乎没有办法使用URI将虚拟主机配置为/.

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?

推荐答案

我最终没有使用setUri而是设置了各个URI组件来解决了这个问题.

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

这篇关于如何使用Java RabbitMQ并设置URI服务器?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆