paho.mqtt.javascript
paho.mqtt.javascript copied to clipboard
onMessageArrived callback is not initiating - Message is not receiving
I am trying subscribe to a topic on the Adafruit IO. I am getting subscribe success callback but not receiving any messages from the broker.
client = new Paho.MQTT.Client("io.adafruit.com",443,"anil");
client.onConnectionLost = onConnectionLost;
client.onMessageArrived = function (message){
console.log("onMessageArrived:"+message.payloadString);
}
//connect to the client
client.connect({onSuccess : subscribeFcn,
userName : "anilkunchalaece",
password : "..",
useSSL : true})
function subscribeFcn(){
console.log("connection is done. Now subscribing");
client.subscribe("anilkunchalaece/feeds/data",{"onSuccess":subscribeSucessFcn,"onFailure":subscribeFailureFcn,qos:0});
}
function subscribeSucessFcn(){
console.log("sunscribe Sucees");
}
function subscribeFailureFcn(){
console.log("subscription is failed");
}
function onConnectionLost(){
console.log("lost the Connection");
}

anybody have any idea onMessageArrived callback is not invoking ?
Hi @anilkunchalaece,
The code looks ok to me, can you confirm that messages are being sent correctly to that topic?
You could also try using the Javascript client utility here: https://www.eclipse.org/paho/clients/js/utility/
Hi @jpwsutton Thanks for Quick Reply
the topic is correct. i am able to publish to the same topic.. but not receiving any messages while subscribing.
Javascript client utility giving me the error Failed to connect: AMQJS0007E Socket error:undefined.
Looks like you're using the wrong path, you want the path to be /mqtt.
I've tested this myself to make sure it works.
