in mqtt-client/src/main/java/com/aws/sample/amazonmq/MQTTClient.java [79:99]
private static void sendMessages(MqttClient client, MqttConnectOptions options, String destination, String name, int interval, WrapInt count) throws Exception {
client.connect(options);
System.out.println(String.format("Successfully connected to %s", client.getServerURI()));
while (true) {
count.v++;
String message = String.format("[topic://%s] [%s] Message number %s", destination.replace('/', '.'), name, count.v);
client.publish(destination, message.getBytes(StandardCharsets.UTF_8), 1, false);
if (interval > 0) {
System.out.println(String.format("%s - Sender: sent '%s'", df.format(new Date()), message));
try {
Thread.sleep(interval);
} catch (InterruptedException e) {
System.out.println(String.format("Error: %s", e.getMessage()));
System.exit(1);
}
}
}
}