Skip to content

Instantly share code, notes, and snippets.

@geoffhendrey
Created October 9, 2015 18:40
Show Gist options
  • Save geoffhendrey/3afa9aed1458964664f6 to your computer and use it in GitHub Desktop.
Save geoffhendrey/3afa9aed1458964664f6 to your computer and use it in GitHub Desktop.
long count = 1;
System.out.println("Waiting for messages...");
while (true) {
Message msg = consumer.receive();
if (msg instanceof TextMessage) {
String body = ((TextMessage) msg).getText();
if ("SHUTDOWN".equals(body)) {
long diff = System.currentTimeMillis() - start;
System.out.println(String.format("Received %d in %.2f seconds", count, (1.0 * diff / 1000.0)));
connection.close();
try {
Thread.sleep(10);
} catch (Exception e) {}
System.exit(1);
} else {
try {
if (count != msg.getIntProperty("id")) {
System.out.println("count: "+count + " mismatch: " + count + "!=" + msg.getIntProperty("id"));
}else{
System.out.println("count: "+count + " match: " + count + "==" + msg.getIntProperty("id"));
}
} catch (NumberFormatException ignore) {
}
if (count == 1) {
start = System.currentTimeMillis();
} else if (count % 1000 == 0) {
System.out.println(String.format("Received %d messages.", count));
}
count++; //<----ARGHHHHHHHHHHHH
}
} else {
System.out.println("Unexpected message type: " + msg.getClass());
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment