javax.jms.JMSException: 无法发送到未连接的传输

javax.jms.JMSException: Cannot send to a non-connected transport

我正在使用 qpid-jms-client.jar 库与代理建立连接。

我的代码是::

Properties properties = new Properties();
properties.load(this.getClass().getResourceAsStream("jndi.properties"));
Context context = new InitialContext(properties);

System.setProperty("javax.net.ssl.trustStore", "C:/Users/xxxxx/qpid.jks");
System.setProperty("javax.net.ssl.trustStorePassword", "test123");

ConnectionFactory factory = (ConnectionFactory) context.lookup("myFactoryLookup");
Destination queue = (Destination) context.lookup("myQueueLookup");
Connection connection = factory.createConnection("<my-username>", "<my-password>");
connection.setExceptionListener(new MyExceptionListener());
connection.start();

我的 jndi.properties 文件是 ::

java.naming.factory.initial=org.apache.qpid.jms.jndi.JmsInitialContextFactory
connectionfactory.myFactoryLookup=amqps://esesslx0100.se:9443
queue.myQueueLookup=emft_input
topic.myTopicLookup=topic
destination.topicExchange=amq.topic
jms.user=test

现在上面的代码给出了错误::

Connection ExceptionListener fired, exiting.
javax.jms.JMSException: Cannot send to a non-connected transport.
    at org.apache.qpid.jms.exceptions.JmsExceptionSupport.create(JmsExceptionSupport.java:66)
    at org.apache.qpid.jms.exceptions.JmsExceptionSupport.create(JmsExceptionSupport.java:88)
    at org.apache.qpid.jms.JmsConnection.onAsyncException(JmsConnection.java:1188)
    at org.apache.qpid.jms.JmsConnection.onConnectionFailure(JmsConnection.java:1104)
    at org.apache.qpid.jms.provider.amqp.AmqpProvider.fireProviderException(AmqpProvider.java:847)
    at org.apache.qpid.jms.provider.amqp.AmqpProvider.pumpToProtonTransport(AmqpProvider.java:820)
    at org.apache.qpid.jms.provider.amqp.AmqpProvider.access0(AmqpProvider.java:90)
    at org.apache.qpid.jms.provider.amqp.AmqpProvider.run(AmqpProvider.java:683)
    at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
    at java.util.concurrent.FutureTask.run(FutureTask.java:266)
    at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access1(ScheduledThreadPoolExecutor.java:180)
    at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:293)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
    at java.lang.Thread.run(Thread.java:745)
Caused by: java.io.IOException: Cannot send to a non-connected transport.
    at org.apache.qpid.jms.transports.netty.NettyTcpTransport.checkConnected(NettyTcpTransport.java:279)
    at org.apache.qpid.jms.transports.netty.NettyTcpTransport.allocateSendBuffer(NettyTcpTransport.java:176)
    at org.apache.qpid.jms.provider.amqp.AmqpProvider.pumpToProtonTransport(AmqpProvider.java:806)
    ... 9 more

由于代理配置了 SaSL,我也提供了我的用户名和密码。我目前不知道为什么会出现此错误。我在互联网上四处查看,但没有明确的解释为什么它会出现在 qpid 上。任何想法为什么会发生此错误?

我的 trustStore 文件是正确的,因为我已经使用它验证了 SSL 连接。

这一行显示了你的错误:

Caused by: java.io.IOException: Cannot send to a non-connected transport.

那是说你的连接配置不正确。我看到的一件事是您没有引用 属性 文件中的属性。例如, 这个:

ConnectionFactory factory = (ConnectionFactory) context.lookup("myFactoryLookup");
Destination queue = (Destination) context.lookup("myQueueLookup");

大概应该是这样的:

ConnectionFactory factory = (ConnectionFactory) context.lookup("connectionfactory.myFactoryLookup");
Destination queue = (Destination) context.lookup("queue.myQueueLookup");

打开客户端日志记录可能会提供更多 trace/debug 信息。 'regular logging' 和 'protocol trace logging'(如果它能做到这一点)都可能有用。有关详细信息,请参阅 http://qpid.apache.org/releases/qpid-jms-0.22.0/docs/index.html#logging

对于这里的问题,似乎 TCP 连接正在被切断,服务器日志也可能有助于给出原因。

你这里没有提到你使用的是哪个服务器,但是在其他相关问题中提到了ActiveMQ和RabbitMQ。目前还不清楚连接有多远,但如果服务器是 RabbitMQ,一种可能的解释也可能是:https://github.com/rabbitmq/rabbitmq-amqp1.0/issues/47. As mentioned in another answer, this may not matter due to other issues, e.g. I didn't have much success using the JMS client or some other AMQP 1.0 clients against RabbitMQ previously due to an issue I reported which stops them in their tracks when creating consumers and producers: https://github.com/rabbitmq/rabbitmq-amqp1.0/issues/34

感谢您的所有回复。在我的例子中,我使用的所有 libraries/configurations 确实是正确的。我联系了管理经纪人的团队。原来我试图联系的用户有一些权限问题。一旦他们授予我的用户正确的权限,我就能够成功建立连接并发送和接收消息。

就我而言,当我收到此错误时,这仅仅是因为当我在办公室时,当我以编程方式执行时,我们公司的代理正在过滤此流量。使用 Service Bus Explorer 仍然有效,因为它必须选择添加代理的机器设置。

我们使用的是公共托管的服务总线,所以我在没有代理的情况下从我的家庭网络尝试,一切都按预期工作。使用 Wireshark 或类似程序可能有助于更快地识别这一点。希望这对某人有所帮助。