Added message to the example message subscriber to clarify why it run, then quit
Project: http://git-wip-us.apache.org/repos/asf/brooklyn-library/repo Commit: http://git-wip-us.apache.org/repos/asf/brooklyn-library/commit/f7cdb81e Tree: http://git-wip-us.apache.org/repos/asf/brooklyn-library/tree/f7cdb81e Diff: http://git-wip-us.apache.org/repos/asf/brooklyn-library/diff/f7cdb81e Branch: refs/heads/0.6.0 Commit: f7cdb81eebbcd36ffeee9ca028015e553da96a7e Parents: eaf79d6 Author: Martin Harris <[email protected]> Authored: Fri Nov 1 16:49:08 2013 +0000 Committer: Martin Harris <[email protected]> Committed: Fri Nov 1 16:49:08 2013 +0000 ---------------------------------------------------------------------- .../src/main/java/brooklyn/demo/Subscribe.java | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/brooklyn-library/blob/f7cdb81e/examples/simple-messaging-pubsub/src/main/java/brooklyn/demo/Subscribe.java ---------------------------------------------------------------------- diff --git a/examples/simple-messaging-pubsub/src/main/java/brooklyn/demo/Subscribe.java b/examples/simple-messaging-pubsub/src/main/java/brooklyn/demo/Subscribe.java index 51ce0c7..877efcf 100644 --- a/examples/simple-messaging-pubsub/src/main/java/brooklyn/demo/Subscribe.java +++ b/examples/simple-messaging-pubsub/src/main/java/brooklyn/demo/Subscribe.java @@ -15,7 +15,9 @@ import com.google.common.base.Throwables; /** Receives messages from a queue on a Qpid broker at a given URL. */ public class Subscribe { public static final String QUEUE = "'amq.direct'/'testQueue'; { node: { type: queue } }"; - + private static final long MESSAGE_TIMEOUT_MILLIS = 15000L; + private static final int MESSAGE_COUNT = 100; + public static void main(String...argv) throws Exception { Preconditions.checkElementIndex(0, argv.length, "Must specify broker URL"); String url = argv[0]; @@ -30,15 +32,16 @@ public class Subscribe { connection.start(); Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE); + System.out.printf("Waiting up to %s milliseconds to receive %s messages\n", MESSAGE_TIMEOUT_MILLIS, MESSAGE_COUNT); try { // Create a producer for the queue Queue destination = session.createQueue(QUEUE); MessageConsumer messageConsumer = session.createConsumer(destination); // Try and receive 100 messages - int n = 100; + int n = MESSAGE_COUNT; do { - TextMessage msg = (TextMessage) messageConsumer.receive(15000L); + TextMessage msg = (TextMessage) messageConsumer.receive(MESSAGE_TIMEOUT_MILLIS); if (msg == null) break; System.out.printf("Got message: '%s'\n", msg.getText()); } while (n --> 0);
