验证 AMQConnection 连接字符串而不连接?
Apache Qpid Java 客户端 API 有一个 AMQConnection 类,用于建立与 Qpid 消息代理的连接。我正在使用单字符串构造函数 (AMQConnection(String connection)
)。我有一个实用程序方法,它首先创建连接字符串,然后将其传递给 AMQConnection 构造函数。
连接字符串的格式为 amqp://
。
如果向构造函数传递语法不正确的连接字符串,则会抛出 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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您只想检查 URI 的语法是否正确吗?如果是这样,只需创建一个
URI< 的实例/code>
类:
当 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: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.