rename examples to avoid confusion with older client examples
Project: http://git-wip-us.apache.org/repos/asf/qpid-jms/repo Commit: http://git-wip-us.apache.org/repos/asf/qpid-jms/commit/6eeff401 Tree: http://git-wip-us.apache.org/repos/asf/qpid-jms/tree/6eeff401 Diff: http://git-wip-us.apache.org/repos/asf/qpid-jms/diff/6eeff401 Branch: refs/heads/master Commit: 6eeff401426e1141c2b1e8056d5e18004dda20fe Parents: f92d4fd Author: Robert Gemmell <[email protected]> Authored: Tue Feb 3 12:34:11 2015 +0000 Committer: Robert Gemmell <[email protected]> Committed: Tue Feb 3 12:36:09 2015 +0000 ---------------------------------------------------------------------- qpid-jms-examples/README.txt | 4 +- .../java/org/apache/qpid/jms/example/Drain.java | 113 ------------------- .../org/apache/qpid/jms/example/Receiver.java | 113 +++++++++++++++++++ .../org/apache/qpid/jms/example/Sender.java | 106 +++++++++++++++++ .../java/org/apache/qpid/jms/example/Spout.java | 106 ----------------- 5 files changed, 221 insertions(+), 221 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/qpid-jms/blob/6eeff401/qpid-jms-examples/README.txt ---------------------------------------------------------------------- diff --git a/qpid-jms-examples/README.txt b/qpid-jms-examples/README.txt index aba0a6d..c3cf944 100644 --- a/qpid-jms-examples/README.txt +++ b/qpid-jms-examples/README.txt @@ -9,9 +9,9 @@ alongside their output: Now you can run the examples using commands of the format: - java -cp "target/classes/:target/dependency/*" org.apache.qpid.jms.example.Drain + java -cp "target/classes/:target/dependency/*" org.apache.qpid.jms.example.Sender NOTE: The earlier build command will cause Maven to resolve the client artifact dependencies against its local and remote repositories. If you wish to use a -locally-built client, ensure to install it in your local maven repo first. +locally-built client, ensure to "mvn install" it in your local repo first. http://git-wip-us.apache.org/repos/asf/qpid-jms/blob/6eeff401/qpid-jms-examples/src/main/java/org/apache/qpid/jms/example/Drain.java ---------------------------------------------------------------------- diff --git a/qpid-jms-examples/src/main/java/org/apache/qpid/jms/example/Drain.java b/qpid-jms-examples/src/main/java/org/apache/qpid/jms/example/Drain.java deleted file mode 100644 index 6754aea..0000000 --- a/qpid-jms-examples/src/main/java/org/apache/qpid/jms/example/Drain.java +++ /dev/null @@ -1,113 +0,0 @@ -/* - * - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - * - */ -package org.apache.qpid.jms.example; - -import java.util.Properties; - -import javax.jms.Connection; -import javax.jms.ConnectionFactory; -import javax.jms.Destination; -import javax.jms.ExceptionListener; -import javax.jms.JMSException; -import javax.jms.MessageConsumer; -import javax.jms.Session; -import javax.jms.TextMessage; -import javax.naming.Context; -import javax.naming.InitialContext; - -public class Drain { - private static final String USER = "guest"; - private static final String PASSWORD = "guest"; - private static final int DEFAULT_COUNT = 10; - - public static void main(String[] args) throws Exception { - int count = DEFAULT_COUNT; - if (args.length == 0) { - System.out.println("Consuming up to " + count + " messages."); - System.out.println("Specify a message count as the program argument if you wish to consume a different amount."); - } else { - count = Integer.parseInt(args[0]); - System.out.println("Consuming up to " + count + " messages."); - } - - try { - // JNDI information can be configured by including an file named jndi.properties - // on the classpath, containing the "java.naming.factory.initial" configuration - // and properties configuring required ConnectionFactory and Destination objects. - // The below is an alternative approach being used only for the examples. - Properties env = new Properties(); - env.put(Context.INITIAL_CONTEXT_FACTORY, "org.apache.qpid.jms.jndi.JmsInitialContextFactory"); - env.put(Context.PROVIDER_URL, ClassLoader.getSystemResource("org/apache/qpid/jms/example/example-jndi.properties").toExternalForm()); - - Context context = new InitialContext(env); - - ConnectionFactory factory = (ConnectionFactory) context.lookup("myFactoryLookup"); - Destination queue = (Destination) context.lookup("myQueueLookup"); - - Connection connection = factory.createConnection(USER, PASSWORD); - connection.setExceptionListener(new MyExceptionListener()); - connection.start(); - - Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE); - - MessageConsumer messageConsumer = session.createConsumer(queue); - - long start = System.currentTimeMillis(); - - int actualCount = 0; - boolean deductTimeout = false; - int timeout = 1000; - for (int i = 1; i <= count; i++, actualCount++) { - TextMessage message = (TextMessage) messageConsumer.receive(timeout); - if (message == null) { - System.out.println("Message " + i + " not received within timeout, stopping."); - deductTimeout = true; - break; - } - if (i % 100 == 0) { - System.out.println("Got message " + i + ":" + message.getText()); - } - } - - long finish = System.currentTimeMillis(); - long taken = finish - start; - if (deductTimeout) { - taken -= timeout; - } - System.out.println("Received " + actualCount + " messages in " + taken + "ms"); - - connection.close(); - } catch (Exception exp) { - System.out.println("Caught exception, exiting."); - exp.printStackTrace(System.out); - System.exit(1); - } - } - - private static class MyExceptionListener implements ExceptionListener { - @Override - public void onException(JMSException exception) { - System.out.println("Connection ExceptionListener fired, exiting."); - exception.printStackTrace(System.out); - System.exit(1); - } - } -} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/qpid-jms/blob/6eeff401/qpid-jms-examples/src/main/java/org/apache/qpid/jms/example/Receiver.java ---------------------------------------------------------------------- diff --git a/qpid-jms-examples/src/main/java/org/apache/qpid/jms/example/Receiver.java b/qpid-jms-examples/src/main/java/org/apache/qpid/jms/example/Receiver.java new file mode 100644 index 0000000..023b8fe --- /dev/null +++ b/qpid-jms-examples/src/main/java/org/apache/qpid/jms/example/Receiver.java @@ -0,0 +1,113 @@ +/* + * + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + * + */ +package org.apache.qpid.jms.example; + +import java.util.Properties; + +import javax.jms.Connection; +import javax.jms.ConnectionFactory; +import javax.jms.Destination; +import javax.jms.ExceptionListener; +import javax.jms.JMSException; +import javax.jms.MessageConsumer; +import javax.jms.Session; +import javax.jms.TextMessage; +import javax.naming.Context; +import javax.naming.InitialContext; + +public class Receiver { + private static final String USER = "guest"; + private static final String PASSWORD = "guest"; + private static final int DEFAULT_COUNT = 10; + + public static void main(String[] args) throws Exception { + int count = DEFAULT_COUNT; + if (args.length == 0) { + System.out.println("Consuming up to " + count + " messages."); + System.out.println("Specify a message count as the program argument if you wish to consume a different amount."); + } else { + count = Integer.parseInt(args[0]); + System.out.println("Consuming up to " + count + " messages."); + } + + try { + // JNDI information can be configured by including an file named jndi.properties + // on the classpath, containing the "java.naming.factory.initial" configuration + // and properties configuring required ConnectionFactory and Destination objects. + // The below is an alternative approach being used only for the examples. + Properties env = new Properties(); + env.put(Context.INITIAL_CONTEXT_FACTORY, "org.apache.qpid.jms.jndi.JmsInitialContextFactory"); + env.put(Context.PROVIDER_URL, ClassLoader.getSystemResource("org/apache/qpid/jms/example/example-jndi.properties").toExternalForm()); + + Context context = new InitialContext(env); + + ConnectionFactory factory = (ConnectionFactory) context.lookup("myFactoryLookup"); + Destination queue = (Destination) context.lookup("myQueueLookup"); + + Connection connection = factory.createConnection(USER, PASSWORD); + connection.setExceptionListener(new MyExceptionListener()); + connection.start(); + + Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE); + + MessageConsumer messageConsumer = session.createConsumer(queue); + + long start = System.currentTimeMillis(); + + int actualCount = 0; + boolean deductTimeout = false; + int timeout = 1000; + for (int i = 1; i <= count; i++, actualCount++) { + TextMessage message = (TextMessage) messageConsumer.receive(timeout); + if (message == null) { + System.out.println("Message " + i + " not received within timeout, stopping."); + deductTimeout = true; + break; + } + if (i % 100 == 0) { + System.out.println("Got message " + i + ":" + message.getText()); + } + } + + long finish = System.currentTimeMillis(); + long taken = finish - start; + if (deductTimeout) { + taken -= timeout; + } + System.out.println("Received " + actualCount + " messages in " + taken + "ms"); + + connection.close(); + } catch (Exception exp) { + System.out.println("Caught exception, exiting."); + exp.printStackTrace(System.out); + System.exit(1); + } + } + + private static class MyExceptionListener implements ExceptionListener { + @Override + public void onException(JMSException exception) { + System.out.println("Connection ExceptionListener fired, exiting."); + exception.printStackTrace(System.out); + System.exit(1); + } + } +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/qpid-jms/blob/6eeff401/qpid-jms-examples/src/main/java/org/apache/qpid/jms/example/Sender.java ---------------------------------------------------------------------- diff --git a/qpid-jms-examples/src/main/java/org/apache/qpid/jms/example/Sender.java b/qpid-jms-examples/src/main/java/org/apache/qpid/jms/example/Sender.java new file mode 100644 index 0000000..a7766c3 --- /dev/null +++ b/qpid-jms-examples/src/main/java/org/apache/qpid/jms/example/Sender.java @@ -0,0 +1,106 @@ +/* + * + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + * + */ +package org.apache.qpid.jms.example; + +import java.util.Properties; + +import javax.jms.Connection; +import javax.jms.ConnectionFactory; +import javax.jms.DeliveryMode; +import javax.jms.Destination; +import javax.jms.ExceptionListener; +import javax.jms.JMSException; +import javax.jms.Message; +import javax.jms.MessageProducer; +import javax.jms.Session; +import javax.jms.TextMessage; +import javax.naming.Context; +import javax.naming.InitialContext; + +public class Sender { + private static final String USER = "guest"; + private static final String PASSWORD = "guest"; + private static final int DEFAULT_COUNT = 10; + private static final int DELIVERY_MODE = DeliveryMode.NON_PERSISTENT; + + public static void main(String[] args) throws Exception { + int count = DEFAULT_COUNT; + if (args.length == 0) { + System.out.println("Sending up to " + count + " messages."); + System.out.println("Specify a message count as the program argument if you wish to send a different amount."); + } else { + count = Integer.parseInt(args[0]); + System.out.println("Sending up to " + count + " messages."); + } + + try { + // JNDI information can be configured by including an file named jndi.properties + // on the classpath, containing the "java.naming.factory.initial" configuration + // and properties configuring required ConnectionFactory and Destination objects. + // The below is an alternative approach being used only for the examples. + Properties env = new Properties(); + env.put(Context.INITIAL_CONTEXT_FACTORY, "org.apache.qpid.jms.jndi.JmsInitialContextFactory"); + env.put(Context.PROVIDER_URL, ClassLoader.getSystemResource("org/apache/qpid/jms/example/example-jndi.properties").toExternalForm()); + + Context context = new InitialContext(env); + + ConnectionFactory factory = (ConnectionFactory) context.lookup("myFactoryLookup"); + Destination queue = (Destination) context.lookup("myQueueLookup"); + + Connection connection = factory.createConnection(USER, PASSWORD); + connection.setExceptionListener(new MyExceptionListener()); + connection.start(); + + Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE); + + MessageProducer messageProducer = session.createProducer(queue); + + long start = System.currentTimeMillis(); + for (int i = 1; i <= count; i++) { + TextMessage message = session.createTextMessage("Hello world!"); + messageProducer.send(message, DELIVERY_MODE, Message.DEFAULT_PRIORITY, Message.DEFAULT_TIME_TO_LIVE); + + if (i % 100 == 0) { + System.out.println("Sent message " + i + ":" + message.getText()); + } + } + + long finish = System.currentTimeMillis(); + long taken = finish - start; + System.out.println("Sent " + count + " messages in " + taken + "ms"); + + connection.close(); + } catch (Exception exp) { + System.out.println("Caught exception, exiting."); + exp.printStackTrace(System.out); + System.exit(1); + } + } + + private static class MyExceptionListener implements ExceptionListener { + @Override + public void onException(JMSException exception) { + System.out.println("Connection ExceptionListener fired, exiting."); + exception.printStackTrace(System.out); + System.exit(1); + } + } +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/qpid-jms/blob/6eeff401/qpid-jms-examples/src/main/java/org/apache/qpid/jms/example/Spout.java ---------------------------------------------------------------------- diff --git a/qpid-jms-examples/src/main/java/org/apache/qpid/jms/example/Spout.java b/qpid-jms-examples/src/main/java/org/apache/qpid/jms/example/Spout.java deleted file mode 100644 index 57899a0..0000000 --- a/qpid-jms-examples/src/main/java/org/apache/qpid/jms/example/Spout.java +++ /dev/null @@ -1,106 +0,0 @@ -/* - * - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - * - */ -package org.apache.qpid.jms.example; - -import java.util.Properties; - -import javax.jms.Connection; -import javax.jms.ConnectionFactory; -import javax.jms.DeliveryMode; -import javax.jms.Destination; -import javax.jms.ExceptionListener; -import javax.jms.JMSException; -import javax.jms.Message; -import javax.jms.MessageProducer; -import javax.jms.Session; -import javax.jms.TextMessage; -import javax.naming.Context; -import javax.naming.InitialContext; - -public class Spout { - private static final String USER = "guest"; - private static final String PASSWORD = "guest"; - private static final int DEFAULT_COUNT = 10; - private static final int DELIVERY_MODE = DeliveryMode.NON_PERSISTENT; - - public static void main(String[] args) throws Exception { - int count = DEFAULT_COUNT; - if (args.length == 0) { - System.out.println("Sending up to " + count + " messages."); - System.out.println("Specify a message count as the program argument if you wish to send a different amount."); - } else { - count = Integer.parseInt(args[0]); - System.out.println("Sending up to " + count + " messages."); - } - - try { - // JNDI information can be configured by including an file named jndi.properties - // on the classpath, containing the "java.naming.factory.initial" configuration - // and properties configuring required ConnectionFactory and Destination objects. - // The below is an alternative approach being used only for the examples. - Properties env = new Properties(); - env.put(Context.INITIAL_CONTEXT_FACTORY, "org.apache.qpid.jms.jndi.JmsInitialContextFactory"); - env.put(Context.PROVIDER_URL, ClassLoader.getSystemResource("org/apache/qpid/jms/example/example-jndi.properties").toExternalForm()); - - Context context = new InitialContext(env); - - ConnectionFactory factory = (ConnectionFactory) context.lookup("myFactoryLookup"); - Destination queue = (Destination) context.lookup("myQueueLookup"); - - Connection connection = factory.createConnection(USER, PASSWORD); - connection.setExceptionListener(new MyExceptionListener()); - connection.start(); - - Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE); - - MessageProducer messageProducer = session.createProducer(queue); - - long start = System.currentTimeMillis(); - for (int i = 1; i <= count; i++) { - TextMessage message = session.createTextMessage("Hello world!"); - messageProducer.send(message, DELIVERY_MODE, Message.DEFAULT_PRIORITY, Message.DEFAULT_TIME_TO_LIVE); - - if (i % 100 == 0) { - System.out.println("Sent message " + i + ":" + message.getText()); - } - } - - long finish = System.currentTimeMillis(); - long taken = finish - start; - System.out.println("Sent " + count + " messages in " + taken + "ms"); - - connection.close(); - } catch (Exception exp) { - System.out.println("Caught exception, exiting."); - exp.printStackTrace(System.out); - System.exit(1); - } - } - - private static class MyExceptionListener implements ExceptionListener { - @Override - public void onException(JMSException exception) { - System.out.println("Connection ExceptionListener fired, exiting."); - exception.printStackTrace(System.out); - System.exit(1); - } - } -} \ No newline at end of file --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
