diff options
| author | Arnaud Simon <arnaudsimon@apache.org> | 2007-11-20 12:58:41 +0000 |
|---|---|---|
| committer | Arnaud Simon <arnaudsimon@apache.org> | 2007-11-20 12:58:41 +0000 |
| commit | 4f4f52e6539e522a9d50679365fa01b9824b94af (patch) | |
| tree | b79f8f86cda0cb7dd56dfeefc58f8a42f7682f8a /java/client/example/src | |
| parent | 0ea769150a24da486aa64d68b2a598b093fb3a60 (diff) | |
| download | qpid-python-4f4f52e6539e522a9d50679365fa01b9824b94af.tar.gz | |
Changed for no looking up destinations in JNDI
git-svn-id: https://svn.apache.org/repos/asf/incubator/qpid/trunk/qpid@596647 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'java/client/example/src')
11 files changed, 64 insertions, 119 deletions
diff --git a/java/client/example/src/main/java/org/apache/qpid/example/jmsexample/BaseExample.java b/java/client/example/src/main/java/org/apache/qpid/example/jmsexample/BaseExample.java index d18b76575c..ff67cbf303 100644 --- a/java/client/example/src/main/java/org/apache/qpid/example/jmsexample/BaseExample.java +++ b/java/client/example/src/main/java/org/apache/qpid/example/jmsexample/BaseExample.java @@ -88,7 +88,7 @@ abstract public class BaseExample _defaults.put("-deliveryMode", "non-persistent"); _options.put("-numMessages", "Number of messages to process"); _defaults.put("-numMessages", String.valueOf(DEFAULT_NUMBER_MESSAGES)); - + _argProcessor = new ArgProcessor(Id, args, _options, _defaults); _argProcessor.display(); //Set the initial context factory @@ -136,7 +136,7 @@ abstract public class BaseExample * we assume that the environment is correctly set * i.e. -Djava.naming.provider.url="..//example.properties" * - * @return an initial context + * @return An initial context * @throws Exception if there is an error getting the context */ public InitialContext getInitialContext() throws Exception @@ -144,25 +144,13 @@ abstract public class BaseExample if (_initialContext == null) { Hashtable<String, String> jndiEnvironment = new Hashtable<String, String>(); - jndiEnvironment.put(Context.INITIAL_CONTEXT_FACTORY, INITIAL_CONTEXT_FACTORY_NAME); + jndiEnvironment.put(Context.INITIAL_CONTEXT_FACTORY, INITIAL_CONTEXT_FACTORY_NAME); + jndiEnvironment.put("connectionfactory.ConnectionFactory", + "qpid:password=guest;username=guest;client_id=clientid;virtualhost=test@tcp:127.0.0.1:5672"); if (getProviderURL() != null) { jndiEnvironment.put(Context.PROVIDER_URL, getProviderURL()); } - else - { - jndiEnvironment.put("connectionfactory.ConnectionFactory", - "qpid:password=guest;username=guest;client_id=clientid;virtualhost=test@tcp:127.0.0.1:5672"); - jndiEnvironment.put("queue.message_queue", "message_queue"); - jndiEnvironment.put("topic.usa.news", "usa.news"); - jndiEnvironment.put("topic.usa.weather", "usa.weather"); - jndiEnvironment.put("topic.usa", "usa.#"); - jndiEnvironment.put("topic.europe.weather", "europe.weather"); - jndiEnvironment.put("topic.europe.news", "europe.news"); - jndiEnvironment.put("topic.europe", "europe.#"); - jndiEnvironment.put("topic.news", "#.news"); - jndiEnvironment.put("topic.weather", "#.weather"); - } _initialContext = new InitialContext(jndiEnvironment); } return _initialContext; diff --git a/java/client/example/src/main/java/org/apache/qpid/example/jmsexample/direct/Consumer.java b/java/client/example/src/main/java/org/apache/qpid/example/jmsexample/direct/Consumer.java index c8bf5a43aa..be1ae972c4 100644 --- a/java/client/example/src/main/java/org/apache/qpid/example/jmsexample/direct/Consumer.java +++ b/java/client/example/src/main/java/org/apache/qpid/example/jmsexample/direct/Consumer.java @@ -69,9 +69,6 @@ public class Consumer extends BaseExample { try { - // lookup the queue - Queue destination = (Queue) getInitialContext().lookup(_queueName); - // Declare the connection Connection connection = getConnection(); @@ -96,6 +93,9 @@ public class Consumer extends BaseExample System.out.println(CLASS + ": Creating a non-transacted, auto-acknowledged session"); Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE); + // lookup the queue + Queue destination = session.createQueue(_queueName); + // Create a MessageConsumer System.out.println(CLASS + ": Creating a MessageConsumer"); MessageConsumer messageConsumer = session.createConsumer(destination); diff --git a/java/client/example/src/main/java/org/apache/qpid/example/jmsexample/direct/Listener.java b/java/client/example/src/main/java/org/apache/qpid/example/jmsexample/direct/Listener.java index 6b3f32cd85..16a4174479 100644 --- a/java/client/example/src/main/java/org/apache/qpid/example/jmsexample/direct/Listener.java +++ b/java/client/example/src/main/java/org/apache/qpid/example/jmsexample/direct/Listener.java @@ -83,9 +83,6 @@ public class Listener extends BaseExample implements MessageListener { try { - // lookup the queue - Queue destination = (Queue) getInitialContext().lookup(_queueName); - // Declare the connection Connection connection = getConnection(); @@ -111,6 +108,9 @@ public class Listener extends BaseExample implements MessageListener Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE); + // lookup the queue + Queue destination = session.createQueue(_queueName); + // Create a MessageConsumer System.out.println(CLASS + ": Creating a MessageConsumer"); diff --git a/java/client/example/src/main/java/org/apache/qpid/example/jmsexample/direct/Producer.java b/java/client/example/src/main/java/org/apache/qpid/example/jmsexample/direct/Producer.java index a00fc7286d..2304cd186c 100644 --- a/java/client/example/src/main/java/org/apache/qpid/example/jmsexample/direct/Producer.java +++ b/java/client/example/src/main/java/org/apache/qpid/example/jmsexample/direct/Producer.java @@ -61,9 +61,6 @@ public class Producer extends BaseExample { try { - // lookup the queue - Queue destination = (Queue) getInitialContext().lookup(_queueName); - // Declare the connection Connection connection = getConnection(); @@ -72,6 +69,9 @@ public class Producer extends BaseExample System.out.println(CLASS + ": Creating a non-transacted, auto-acknowledged session"); Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE); + // lookup the queue + Queue destination = session.createQueue(_queueName); + // Create a Message producer System.out.println(CLASS + ": Creating a Message PRoducer"); MessageProducer messageProducer = session.createProducer(destination); diff --git a/java/client/example/src/main/java/org/apache/qpid/example/jmsexample/examples.properties b/java/client/example/src/main/java/org/apache/qpid/example/jmsexample/examples.properties deleted file mode 100644 index fbfae5d635..0000000000 --- a/java/client/example/src/main/java/org/apache/qpid/example/jmsexample/examples.properties +++ /dev/null @@ -1,39 +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. - -## The initial context factory -java.naming.factory.initial = org.apache.qpid.jndi.PropertiesFileInitialContextFactory - -# Connection factories: -connectionfactory.ConnectionFactory = qpid:password=guest;username=guest;client_id=clientid;virtualhost=test@tcp:127.0.0.1:5672 - -# register some queues in JNDI using the form -# queue.[jndiName] = [physicalName] -queue.MY_QUEUE = MyQueue - -# register some topics in JNDI using the form -# topic.[jndiName] = [physicalName] -topic.usa.news = usa.news -topic.usa.weather = usa.weather -topic.europe.weather = europe.weather -topic.europe.news = europe.news -topic.europe = europe.# -topic.usa = usa.# -topic.news = #.news -topic.weather = #.weather - - - diff --git a/java/client/example/src/main/java/org/apache/qpid/example/jmsexample/pubsub/Listener.java b/java/client/example/src/main/java/org/apache/qpid/example/jmsexample/pubsub/Listener.java index 66c4dc7d6d..2cf04833cb 100644 --- a/java/client/example/src/main/java/org/apache/qpid/example/jmsexample/pubsub/Listener.java +++ b/java/client/example/src/main/java/org/apache/qpid/example/jmsexample/pubsub/Listener.java @@ -93,7 +93,7 @@ public class Listener extends BaseExample TopicSession session = connection.createTopicSession(false, Session.AUTO_ACKNOWLEDGE); // lookup the topics usa - Topic topic = (Topic) getInitialContext().lookup("usa"); + Topic topic = session.createTopic("usa.#"); // Create a Message Subscriber System.out.println(CLASS + ": Creating a Message Subscriber"); TopicSubscriber messageSubscriber = session.createSubscriber(topic); @@ -101,7 +101,7 @@ public class Listener extends BaseExample messageSubscriber.setMessageListener(new MyMessageListener("usa")); // lookup the topics world.usa.news - topic = (Topic) getInitialContext().lookup("europe"); + topic = session.createTopic("europe.#"); // Create a Message Subscriber System.out.println(CLASS + ": Creating a Message Subscriber"); messageSubscriber = session.createSubscriber(topic); @@ -109,7 +109,7 @@ public class Listener extends BaseExample messageSubscriber.setMessageListener(new MyMessageListener("europe")); // lookup the topics world.europw - topic = (Topic) getInitialContext().lookup("news"); + topic = session.createTopic("#.news"); // Create a Message Subscriber System.out.println(CLASS + ": Creating a Message Subscriber"); messageSubscriber = session.createSubscriber(topic); @@ -117,7 +117,7 @@ public class Listener extends BaseExample messageSubscriber.setMessageListener(new MyMessageListener("news")); // lookup the topics world.europw - topic = (Topic) getInitialContext().lookup("weather"); + topic = session.createTopic("#.weather"); // Create a Message Subscriber System.out.println(CLASS + ": Creating a Message Subscriber"); messageSubscriber = session.createSubscriber(topic); diff --git a/java/client/example/src/main/java/org/apache/qpid/example/jmsexample/pubsub/Publisher.java b/java/client/example/src/main/java/org/apache/qpid/example/jmsexample/pubsub/Publisher.java index 47fdb6a110..27252983e5 100644 --- a/java/client/example/src/main/java/org/apache/qpid/example/jmsexample/pubsub/Publisher.java +++ b/java/client/example/src/main/java/org/apache/qpid/example/jmsexample/pubsub/Publisher.java @@ -71,7 +71,7 @@ public class Publisher extends BaseExample message = session.createTextMessage(); // lookup the topics .usa.weather - Topic topic = (Topic) getInitialContext().lookup("usa.weather"); + Topic topic = session.createTopic("usa.weather"); message.setStringProperty("topicName", "usa.weather"); // Create a Message Publisher System.out.println(CLASS + ": Creating a Message Publisherr"); @@ -79,7 +79,7 @@ public class Publisher extends BaseExample publishMessages(message, messagePublisher); // lookup the topics usa.news - topic = (Topic) getInitialContext().lookup("usa.news"); + topic = session.createTopic("usa.news"); message.setStringProperty("topicName", "usa.news"); // Create a Message Publisher System.out.println(CLASS + ": Creating a Message Publisherr"); @@ -87,7 +87,7 @@ public class Publisher extends BaseExample publishMessages(message, messagePublisher); // lookup the topics europe.weather - topic = (Topic) getInitialContext().lookup("europe.weather"); + topic = session.createTopic("europe.weather"); message.setStringProperty("topicName", "europe.weather"); // Create a Message Publisher System.out.println(CLASS + ": Creating a Message Publisherr"); @@ -95,7 +95,7 @@ public class Publisher extends BaseExample publishMessages(message, messagePublisher); // lookup the topics europe.news - topic = (Topic) getInitialContext().lookup("europe.news"); + topic = session.createTopic("europe.news"); message.setStringProperty("topicName", "europe.news"); // Create a Message Publisher System.out.println(CLASS + ": Creating a Message Publisherr"); @@ -104,7 +104,7 @@ public class Publisher extends BaseExample // send the final message message.setText("That's all, folks!"); - topic = (Topic) getInitialContext().lookup("news"); + topic = session.createTopic("#.news"); message.setStringProperty("topicName", "news"); // Create a Message Publisher System.out.println(CLASS + ": Creating a Message Publisherr"); @@ -112,7 +112,7 @@ public class Publisher extends BaseExample messagePublisher .send(message, getDeliveryMode(), Message.DEFAULT_PRIORITY, Message.DEFAULT_TIME_TO_LIVE); - topic = (Topic) getInitialContext().lookup("weather"); + topic = session.createTopic("#.weather"); message.setStringProperty("topicName", "weather"); // Create a Message Publisher System.out.println(CLASS + ": Creating a Message Publisherr"); @@ -120,7 +120,7 @@ public class Publisher extends BaseExample messagePublisher .send(message, getDeliveryMode(), Message.DEFAULT_PRIORITY, Message.DEFAULT_TIME_TO_LIVE); - topic = (Topic) getInitialContext().lookup("europe"); + topic = session.createTopic("europe.#"); message.setStringProperty("topicName", "europe"); // Create a Message Publisher System.out.println(CLASS + ": Creating a Message Publisherr"); @@ -128,7 +128,7 @@ public class Publisher extends BaseExample messagePublisher .send(message, getDeliveryMode(), Message.DEFAULT_PRIORITY, Message.DEFAULT_TIME_TO_LIVE); - topic = (Topic) getInitialContext().lookup("usa"); + topic = session.createTopic("usa.#"); message.setStringProperty("topicName", "usa"); // Create a Message Publisher System.out.println(CLASS + ": Creating a Message Publisherr"); diff --git a/java/client/example/src/main/java/org/apache/qpid/example/jmsexample/requestResponse/MessageMirror.java b/java/client/example/src/main/java/org/apache/qpid/example/jmsexample/requestResponse/MessageMirror.java index f1930e0b9a..7d0523b161 100644 --- a/java/client/example/src/main/java/org/apache/qpid/example/jmsexample/requestResponse/MessageMirror.java +++ b/java/client/example/src/main/java/org/apache/qpid/example/jmsexample/requestResponse/MessageMirror.java @@ -29,7 +29,6 @@ import javax.jms.*; * Destination which is used to synchronously consume messages. If a * received message has a ReplyTo header then a new response message is sent * to that specified destination. - * */ public class MessageMirror extends BaseExample { @@ -44,24 +43,26 @@ public class MessageMirror extends BaseExample /** * Create a MessageMirror client. + * * @param args Command line arguments. */ public MessageMirror(String[] args) { super(CLASS, args); _destinationType = _argProcessor.getStringArgument("-destinationType"); - _destinationName = _argProcessor.getStringArgument("-destinationName"); + _destinationName = _argProcessor.getStringArgument("-destinationName"); } /** * Run the message mirror example. + * * @param args Command line arguments. */ public static void main(String[] args) { _options.put("-destinationType", "Destination Type: queue/topic"); _defaults.put("-destinationType", "queue"); - _options.put("-destinationName", "Destination Name"); + _options.put("-destinationName", "Destination Name"); _defaults.put("-destinationName", "message_queue"); MessageMirror messageMirror = new MessageMirror(args); messageMirror.runTest(); @@ -74,27 +75,13 @@ public class MessageMirror extends BaseExample { try { - Destination destination; - - if (_destinationType.equals("queue")) - { - // Lookup the queue - System.out.println(CLASS + ": Looking up queue with name: " + _destinationName); - destination = (Queue) getInitialContext().lookup(_destinationName); - } - else - { - // Lookup the topic - System.out.println(CLASS + ": Looking up topic with name: " + _destinationName); - destination = (Topic) getInitialContext().lookup(_destinationName); - } - // Declare the connection Connection connection = getConnection(); // As this application is using a MessageConsumer we need to set an ExceptionListener on the connection // so that errors raised within the JMS client library can be reported to the application - System.out.println(CLASS + ": Setting an ExceptionListener on the connection as sample uses a MessageConsumer"); + System.out.println( + CLASS + ": Setting an ExceptionListener on the connection as sample uses a MessageConsumer"); connection.setExceptionListener(new ExceptionListener() { @@ -114,6 +101,21 @@ public class MessageMirror extends BaseExample Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE); + Destination destination; + + if (_destinationType.equals("queue")) + { + // Lookup the queue + System.out.println(CLASS + ": Looking up queue with name: " + _destinationName); + destination = session.createQueue(_destinationName); + } + else + { + // Lookup the topic + System.out.println(CLASS + ": Looking up topic with name: " + _destinationName); + destination = session.createTopic(_destinationName); + } + // Create a MessageConsumer System.out.println(CLASS + ": Creating a MessageConsumer"); MessageConsumer messageConsumer = session.createConsumer(destination); @@ -145,25 +147,26 @@ public class MessageMirror extends BaseExample if (requestMessage instanceof TextMessage) { - if (((TextMessage) requestMessage).getText().equals("That's all, folks!")) + if (((TextMessage) requestMessage).getText().equals("That's all, folks!")) { System.out.println("Received final message for " + destination); end = true; } - System.out.println("\tContents = " + ((TextMessage)requestMessage).getText()); + System.out.println("\tContents = " + ((TextMessage) requestMessage).getText()); } // Now bounce the message if a ReplyTo header was set. if (requestMessage.getJMSReplyTo() != null) { - System.out.println("Activating response queue listener for: " + destination); - responseMessage = session.createTextMessage("Activating response queue listener for: " + destination); + System.out.println("Activating response queue listener for: " + destination); + responseMessage = + session.createTextMessage("Activating response queue listener for: " + destination); String correlationID = requestMessage.getJMSCorrelationID(); if (correlationID != null) { responseMessage.setJMSCorrelationID(correlationID); } - messageProducer = session.createProducer(requestMessage.getJMSReplyTo()) ; + messageProducer = session.createProducer(requestMessage.getJMSReplyTo()); messageProducer.send(responseMessage); } System.out.println(); diff --git a/java/client/example/src/main/java/org/apache/qpid/example/jmsexample/requestResponse/P2PRequestor.java b/java/client/example/src/main/java/org/apache/qpid/example/jmsexample/requestResponse/P2PRequestor.java index bab1483eff..fbc3d1c460 100644 --- a/java/client/example/src/main/java/org/apache/qpid/example/jmsexample/requestResponse/P2PRequestor.java +++ b/java/client/example/src/main/java/org/apache/qpid/example/jmsexample/requestResponse/P2PRequestor.java @@ -93,7 +93,7 @@ public class P2PRequestor extends BaseExample // Lookup the destination System.out.println(CLASS + ": Looking up queue with name: " + _queueName); - Queue destination = (Queue) getInitialContext().lookup(_queueName); + Queue destination = session.createQueue(_queueName); // Create a QueueRequestor System.out.println(CLASS + ": Creating a QueueRequestor"); diff --git a/java/client/example/src/main/java/org/apache/qpid/example/jmsexample/requestResponse/PubSubRequestor.java b/java/client/example/src/main/java/org/apache/qpid/example/jmsexample/requestResponse/PubSubRequestor.java index 1faa909cc2..6cc49f757d 100644 --- a/java/client/example/src/main/java/org/apache/qpid/example/jmsexample/requestResponse/PubSubRequestor.java +++ b/java/client/example/src/main/java/org/apache/qpid/example/jmsexample/requestResponse/PubSubRequestor.java @@ -93,7 +93,7 @@ public class PubSubRequestor extends BaseExample // Lookup the destination System.out.println(CLASS + ": Looking up topic with name: " + _topicName); - Topic destination = (Topic) getInitialContext().lookup(_topicName); + Topic destination = session.createTopic(_topicName); // Create a TopicRequestor System.out.println(CLASS + ": Creating a TopicRequestor"); diff --git a/java/client/example/src/main/java/org/apache/qpid/example/jmsexample/transacted/QueueToTopic.java b/java/client/example/src/main/java/org/apache/qpid/example/jmsexample/transacted/QueueToTopic.java index e76d239142..20961e40ea 100644 --- a/java/client/example/src/main/java/org/apache/qpid/example/jmsexample/transacted/QueueToTopic.java +++ b/java/client/example/src/main/java/org/apache/qpid/example/jmsexample/transacted/QueueToTopic.java @@ -89,16 +89,7 @@ public class QueueToTopic extends BaseExample { try { - - // Lookup the queue - System.out.println(CLASS + ": Looking up queue with name: " + _queueName); - Queue queue = (Queue) getInitialContext().lookup(_queueName); - - // Lookup the topic - System.out.println(CLASS + ": Looking up topic with name: " + _topicName); - Topic topic = (Topic) getInitialContext().lookup(_topicName); - - // Declare the connection + // Declare the connection Connection connection = getConnection(); // As this application is using a MessageConsumer we need to set an ExceptionListener on the connection @@ -112,12 +103,6 @@ public class QueueToTopic extends BaseExample { // The connection may have broken invoke reconnect code if available. System.err.println(CLASS + ": The sample received an exception through the ExceptionListener"); - System.err.println( - CLASS + ": If this was a real application it should now go through reconnect code"); - System.err.println(); - System.err.println("Exception: " + jmse); - System.err.println(); - System.err.println("Now exiting."); System.exit(0); } }); @@ -133,6 +118,14 @@ public class QueueToTopic extends BaseExample System.out.println(CLASS + ": Creating a non-transacted, auto-acknowledged session"); Session nonTransactedSession = connection.createSession(false, Session.AUTO_ACKNOWLEDGE); + // Lookup the queue + System.out.println(CLASS + ": Looking up queue with name: " + _queueName); + Queue queue = nonTransactedSession.createQueue(_queueName); + + // Lookup the topic + System.out.println(CLASS + ": Looking up topic with name: " + _topicName); + Topic topic = nonTransactedSession.createTopic(_topicName); + // Make sure that the queue is empty System.out.print(CLASS + ": Purging messages from queue..."); MessageConsumer queueMessageConsumer = nonTransactedSession.createConsumer(queue); |
