in mqtt-client/src/main/java/com/aws/sample/amazonmq/MQTTClient.java [101:125]
private static void receiveMessages(final MqttClient client, final MqttConnectOptions options,final String destination) throws Exception {
new Thread(new Runnable() {
public void run() {
try {
client.setCallback(new MqttCallback() {
public void connectionLost(Throwable cause) {
}
public void messageArrived(String topic, MqttMessage message) throws Exception {
System.out.println(String.format("%s - Receiver: received '%s'", df.format(new Date()), new String(message.getPayload())));
}
public void deliveryComplete(IMqttDeliveryToken token) {
}
});
client.connect(options);
System.out.println(String.format("Successfully connected to %s", client.getServerURI()));
client.subscribe(destination);
} catch (Exception e) {
throw new RuntimeException(e);
}
}
}).start();
}