eclipse / paho.mqtt.javascript

paho.mqtt.javascript
Other
1.14k stars 468 forks source link

MQTT with Spark #183

Open george175 opened 5 years ago

george175 commented 5 years ago

Hi,

I am using Eclipse-PAHO to subscribe to MQTT ActiveMQ over websocket. The issue I am having is that the Queue publisher only speaks SPARK and not text/json format.

I am getting an error when onMessageArrived(message) method is executed. The error is the following, it's coming in the payload:

AMQJS0009E Malformed UTF data:f9 -54

Is there a way to receive SPARK encoded messages?

icraggs commented 5 years ago

Do you have some output from the JavaScript console to narrow down where that error is coming from?

The topic string should be UTF-8, but the message payload shouldn't have to be.

george175 commented 5 years ago

I am not seeing a console error. but I tried to debug it, this is the error detail (from the catch block , like 1340 in mqttws3.1.js)

message: "AMQJS0009E Malformed UTF data:f9 -54 ." stack:

"Error: AMQJS0009E Malformed UTF data:f9 -54 . at parseUTF8 (file:///C:/George/Workspace/eclipse/DSCarpetCut/WebContent/include/mqttws31.js:639:12) at Message._getPayloadString (file:///C:/George/Workspace/eclipse/DSCarpetCut/WebContent/include/mqttws31.js:2074:12) at Message.get payloadString [as payloadString] (file:///C:/George/Workspace/eclipse/DSCarpetCut/WebContent/include/mqttws31.js:2122:37) at ClientImpl.onMessageArrived (file:///C:/George/Workspace/eclipse/DSCarpetCut/WebContent/test/TestAmq.html:163:43) at ClientImpl.Paho.MQTT.ClientImpl._receiveMessage (file:///C:/George/Workspace/eclipse/DSCarpetCut/WebContent/include/mqttws31.js:1399:9) at ClientImpl.Paho.MQTT.ClientImpl._receivePublish (file:///C:/George/Workspace/eclipse/DSCarpetCut/WebContent/include/mqttws31.js:1374:10) at ClientImpl.Paho.MQTT.ClientImpl._handleMessage (file:///C:/George/Workspace/eclipse/DSCarpetCut/WebContent/include/mqttws31.js:1250:10) at ClientImpl.Paho.MQTT.ClientImpl._on_socket_message (file:///C:/George/Workspace/eclipse/DSCarpetCut/WebContent/include/mqttws31.js:1151:12) at WebSocket. (file:///C:/George/Workspace/eclipse/DSCarpetCut/WebContent/include/mqttws31.js:157:13)"

I hope this helps

icraggs commented 5 years ago

Where did you get this client code from please? I think the file name mqttws31.js is a really old version.

george175 commented 5 years ago

I got it from this page:

I am using this CDN

which I found on this page:

https://www.eclipse.org/paho/clients/js/

is this not the right place?

icraggs commented 5 years ago

Thanks for pointing that out! The web site needs updating, evidently, and cloudflare. I'm seeing if I can get that updated.

In the meantime, you can get the 1.1 version from this repo: https://github.com/eclipse/paho.mqtt.javascript/releases/tag/v1.1.0 or https://www.npmjs.com/package/paho-mqtt

george175 commented 5 years ago

when I replaced the file with the one you mentioned, it's not connecting anymore. When I click connect, the whole page refreshes instead of connecting.

I think this line is what causes it

console.log("connecting to "+ host +" "+ port +"clean session="+clean_sessions); mqtt = new Paho.MQTT.Client(host,port, "myClient");

are there any changes in the api between the previous version and this one ?