1
votes

When I attemp to connect my mqtt java client to any mqtt broker, I get a java.lang.IllegalArgumentException: Invalid connect parameters: {wireFormat.host=localhost} . I want to run a local client and a local server, but my future goal is do it better with a remote broker.

I am using the activemq-client 1.15 library and the activemq-mqtt 1.15.9 library (to support MQTT transport protocol). Now I atempt to run it in eclipse with java8.

My configuration is the next one:


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

I have other clients reading the same broker successfully, I think that the problem is in this client.

Now, always get a exception:


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

If I use a tcp url like amqcf.setBrokerURL("mqtt://localhost:1883");

I get other exception in the same point:

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


The broker has the default ports, and the mqtt transport is enabled. I have a python script that use mqtt with paho.

Can you help me? Thanks!

1
I think the url should start with tcp not mqtt. Have you tried that? - JWo
@JWo Can I connect to the port 1883 (mqtt in broker) with tcp uri ? (I'm new in this field haha) - Antonio Miranda
When I connect to a mqtt broker I use something like tcp://example.com. That might be unnecessary with your library. I don't know that library. Just try it one time with "tcp://localhost" and one time just with "localhost". Port 1883 is the default mqtt port. I guess you don't have to add it to your broker url. - JWo
Thanks, I try it and edit the question. The protocol (tcp or mqtt) is mandatory in this library - Antonio Miranda

1 Answers

1
votes

The ActiveMQ JMS client library is an Openwire protocol based client and will not work on an MQTT based transport connector. You must connect the JMS client to validly configured Openwire transport connector endpoint on the broker, usually on port 61616.

To connect to the MQTT connector you need to use an MQTT client such as the Eclipse Paho Java MQTT client.