I have a java app which can connect and subscribe to IoT Core but disconnects if I try to publish. This same app connects, subscribes and publishes to a stand alone broker running in the cloud but will not publish to IoT Core. Additionally using the same certificate and Id I can publish using the MQTT.fx client. I have seen multiple similar questions but haven't found any solutions. Hopefully someone can help?
Code is:
public void publish(String topic,String message) {
MqttMessage sPayload = new MqttMessage(message.getBytes());
sPayload.setRetained(false);
sPayload.setQos(2);
try {
sampleClient.publish(topic, sPayload);
} catch (MqttException e) {
e.printStackTrace();
}
}
Error is:
Connection lost (32109) - java.io.EOFException
at org.eclipse.paho.client.mqttv3.internal.CommsReceiver.run(CommsReceiver.java:146)
at java.lang.Thread.run(Unknown Source)
Caused by: java.io.EOFException
at java.io.DataInputStream.readByte(Unknown Source)
at org.eclipse.paho.client.mqttv3.internal.wire.MqttInputStream.readMqttWireMessage(MqttInputStream.java:61)
at org.eclipse.paho.client.mqttv3.internal.CommsReceiver.run(CommsReceiver.java:107)
... 1 more
Policy is:
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": "iot:*",
"Resource": "*"
}
]
}