当我尝试将mqtt java客户端连接到任何mqtt代理时,我得到java.lang.IllegalArgumentException: Invalid connect parameters: {wireFormat.host=localhost}
。
我想运行一个本地客户端和一个本地服务器,但是我的未来目标是使用远程代理做得更好。
我正在使用activemq-client 1.15库和activemq-mqtt 1.15.9库(以支持MQTT传输协议)。现在,我试图用Java8在Eclipse中运行它。
我的配置是下一个:
ActiveMQConnectionFactory amqcf=new ActiveMQConnectionFactory();
amqcf.setClientID("Test-main");
amqcf.setWatchTopicAdvisories(false);
amqcf.setUserName("test");
amqcf.setPassword("test");
amqcf.setBrokerURL("mqtt://localhost:1883");
connection = connectionFactory.createConnection(); //here break
我有其他客户成功读取同一经纪人,我认为问题出在此客户中。
现在,总是得到一个例外:
Exception in thread "main" javax.jms.JMSException: Could not create Transport. Reason: java.lang.IllegalArgumentException: Invalid connect parameters: {wireFormat.host=localhost}
at org.apache.activemq.util.JMSExceptionSupport.create(JMSExceptionSupport.java:36)
at org.apache.activemq.ActiveMQConnectionFactory.createTransport(ActiveMQConnectionFactory.java:333)
at org.apache.activemq.ActiveMQConnectionFactory.createActiveMQConnection(ActiveMQConnectionFactory.java:346)
at org.apache.activemq.ActiveMQConnectionFactory.createActiveMQConnection(ActiveMQConnectionFactory.java:304)
at org.apache.activemq.ActiveMQConnectionFactory.createConnection(ActiveMQConnectionFactory.java:244)
at simpleactivemqtt.main.start(main.java:60)
at simpleactivemqtt.main.main(main.java:86)
Caused by: java.lang.IllegalArgumentException: Invalid connect parameters: {wireFormat.host=localhost}
at org.apache.activemq.transport.TransportFactory.doConnect(TransportFactory.java:130)
at org.apache.activemq.transport.TransportFactory.connect(TransportFactory.java:69)
at org.apache.activemq.ActiveMQConnectionFactory.createTransport(ActiveMQConnectionFactory.java:331)
... 5 more
如果我使用类似amqcf.setBrokerURL("mqtt://localhost:1883");
的tcp网址
我在同一点遇到其他异常:
Exception in thread "main" javax.jms.JMSException: Disposed due to prior exception
at org.apache.activemq.util.JMSExceptionSupport.create(JMSExceptionSupport.java:72)
at org.apache.activemq.ActiveMQConnection.syncSendPacket(ActiveMQConnection.java:1421)
at org.apache.activemq.ActiveMQConnection.ensureConnectionInfoSent(ActiveMQConnection.java:1486)
at org.apache.activemq.ActiveMQConnection.start(ActiveMQConnection.java:527)
at simpleactivemqtt.main.start(main.java:59)
at simpleactivemqtt.main.main(main.java:84)
Caused by: org.apache.activemq.transport.TransportDisposedIOException: Disposed due to prior exception
at org.apache.activemq.transport.ResponseCorrelator.onException(ResponseCorrelator.java:125)
at org.apache.activemq.transport.TransportFilter.onException(TransportFilter.java:114)
at org.apache.activemq.transport.TransportFilter.onException(TransportFilter.java:114)
at org.apache.activemq.transport.WireFormatNegotiator.onException(WireFormatNegotiator.java:173)
at org.apache.activemq.transport.AbstractInactivityMonitor.onException(AbstractInactivityMonitor.java:345)
at org.apache.activemq.transport.TransportSupport.onException(TransportSupport.java:96)
at org.apache.activemq.transport.tcp.TcpTransport.run(TcpTransport.java:219)
at java.lang.Thread.run(Thread.java:748)
Caused by: java.io.EOFException
at java.io.DataInputStream.readInt(DataInputStream.java:392)
at org.apache.activemq.openwire.OpenWireFormat.unmarshal(OpenWireFormat.java:268)
at org.apache.activemq.transport.tcp.TcpTransport.readCommand(TcpTransport.java:240)
at org.apache.activemq.transport.tcp.TcpTransport.doRun(TcpTransport.java:232)
at org.apache.activemq.transport.tcp.TcpTransport.run(TcpTransport.java:215)
... 1 more
代理具有默认端口,并且启用了mqtt传输。我有一个将mqtt与paho结合使用的python脚本。
你能帮我吗? 谢谢!
答案 0 :(得分:1)
ActiveMQ JMS客户端库是基于Openwire协议的客户端,不适用于基于MQTT的传输连接器。您必须将JMS客户端连接到代理上有效配置的Openwire传输连接器端点,通常在端口61616上。
要连接到MQTT连接器,您需要使用MQTT客户端,例如Eclipse Paho Java MQTT client。