我的问题是,当我想响应到达消息时,我没有从经纪人那里获得递送令牌,但消息到达了经纪人。我可以在日志中看到它。所以我的问题是如何通过发布对收到的消息进行响应?
这是我的方式,它不起作用...
public void setMqttCallback() {
mqttClient.setCallback(new MqttCallback() {
@Override
public void connectionLost(final Throwable throwable) {
System.out.println("Lost connection to Broker because of: " + throwable.getMessage());
}
@Override
public void messageArrived(final String topic, final MqttMessage mqttMessage) throws Exception {
System.out.println("Received on " + topic + ": " + new String(mqttMessage.getPayload()));
topics = new Topics();
//Answer to arriving messages (Logic)
if (topic.equals(topics.getVehicleNavLandmarkInfo(Mqtt.VIN_ID))) {
landmarks = new Landmarks();
MqttMessage message = new MqttMessage(landmarks.getLandmarks().getBytes());
message.setQos(2);
System.out.println("Sending on " + topic + ": " + landmarks.getLandmarks());
mqttClient.publish(topics.getBackendNavLandsmarks(Mqtt.VIN_ID), message);
}
if (topic.equals(topics.getVehicleNavDestination(Mqtt.VIN_ID))) {
routing = new Routing(49.0000, 8.0000, "A");
MqttMessage message = new MqttMessage(routing.getShortestPath().getBytes());
message.setQos(2);
System.out.println("Sending on " + topic + ": " + routing.getShortestPath());
mqttClient.publish(topics.getBackendNavRoute(Mqtt.VIN_ID), message);
}
}
@Override
public void deliveryComplete(final IMqttDeliveryToken iMqttDeliveryToken) {
System.out.println("Delivered Message: " + iMqttDeliveryToken.toString());
}
});
}
茅侃侃
相关分类