验证 AMQConnection 连接字符串而不连接?

发布于 2025-01-07 02:20:53 字数 698 浏览 3 评论 0原文

Apache Qpid Java 客户端 API 有一个 AMQConnection 类,用于建立与 Qpid 消息代理的连接。我正在使用单字符串构造函数 (AMQConnection(String connection))。我有一个实用程序方法,它首先创建连接字符串,然后将其传递给 AMQConnection 构造函数。

连接字符串的格式为 amqp://:@/?brokerlist='tcp://:'

如果向构造函数传递语法不正确的连接字符串,则会抛出 URLSyntaxException

我想将连接字符串语法检查移至实用程序方法(我认为它不应该返回损坏的信息),但我还没有找到任何验证连接字符串的方法,除非尝试建立与消息代理的连接。有什么方法可以做到这一点,还是我只需要依赖构造函数抛出的 URLSyntaxException

The Apache Qpid Java client API has an AMQConnection class that is used to make a connection to a Qpid message broker. I'm using the single-String constructor (AMQConnection(String connection)). I have a utility method that creates the connection string first, which is then passed to the AMQConnection constructor.

The connection string is of the form amqp://<username>:<password>@<clientID>/?brokerlist='tcp://<hostname>:<port>'.

If the constructor is passed a connection string with incorrect syntax, it throws a URLSyntaxException.

I would like to move the connection string syntax check to the utility method (I'm of the opinion that it shouldn't be able to return broken information), but I have not found any way of validating the connection string short of trying to set up a connection to the message broker. Is there any way of doing this, or do I just have to rely on the URLSyntaxException being thrown from the constructor?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

围归者 2025-01-14 02:20:53

您只想检查 URI 的语法是否正确吗?如果是这样,只需创建一个 URI< 的实例/code>类:

new URI("amqp://user:pwd@42/?brokerlist='tcp://example.com:80'")

当 URI 语法不正确时,该类会抛出 java.net.URISyntaxException

如果您需要检查 AMQ 特定选项的 URI,您可能需要查看 AMQ 源代码并找到一个验证/解析此选项的类。

Do you only want to check the URI for correct syntax? If so, simply create an instance of URI class:

new URI("amqp://user:pwd@42/?brokerlist='tcp://example.com:80'")

This throws an java.net.URISyntaxException when URI is not syntactically correct.

If you need to check the URI for AMQ-specific options, you might have two have a look at AMQ source code and find a class that validates/parses this.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文