diff options
| author | Rajith Muditha Attapattu <rajith@apache.org> | 2008-03-19 23:46:10 +0000 |
|---|---|---|
| committer | Rajith Muditha Attapattu <rajith@apache.org> | 2008-03-19 23:46:10 +0000 |
| commit | df0246fbcc92f9d7869f5ee00ed9335ce1c7fb4b (patch) | |
| tree | 25cf75ce8275a34f8c28776ce683dae2e730e4db /java/client/example/src | |
| parent | d40280cec3ff590facd2f46b7f5d5054fd13db89 (diff) | |
| download | qpid-python-df0246fbcc92f9d7869f5ee00ed9335ce1c7fb4b.tar.gz | |
This contains a trivial fix for QPID-863.
I also took the oportunity to organize the code a bit more.
Also removed the temp hack we used to bind a Topic to more than one routingkey to interop with the c++/python examples.
The topics can now be bound to more than one routingkey in the jndi properties file.
git-svn-id: https://svn.apache.org/repos/asf/incubator/qpid/trunk/qpid@639078 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'java/client/example/src')
2 files changed, 38 insertions, 86 deletions
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 c8e5d89099..1a3d40041d 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 @@ -5,9 +5,9 @@ * 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 @@ -17,14 +17,21 @@ */ package org.apache.qpid.example.jmsexample.pubsub; -import org.apache.qpid.jms.TopicSubscriber; +import java.util.Properties; -import javax.jms.*; -import javax.jms.Session; +import javax.jms.BytesMessage; +import javax.jms.ConnectionFactory; +import javax.jms.ExceptionListener; +import javax.jms.JMSException; import javax.jms.Message; +import javax.jms.MessageListener; +import javax.jms.Session; +import javax.jms.TextMessage; +import javax.jms.Topic; +import javax.jms.TopicConnection; +import javax.jms.TopicSession; import javax.naming.Context; import javax.naming.InitialContext; -import java.util.Properties; /** * The example creates a TopicSubscriber on the specified @@ -56,6 +63,18 @@ public class Listener listener.runTest(); } + private void createListener(Context ctx,TopicSession session,String topicName) throws Exception{ + // lookup the topic usa + Topic topic=(Topic) ctx.lookup(topicName); + // Create a Message Subscriber + System.out.println(CLASS + ": Creating a Message Subscriber for topic " + topicName); + javax.jms.TopicSubscriber messageSubscriber=session.createSubscriber(topic); + + // Set a message listener on the messageConsumer + messageSubscriber.setMessageListener(new MyMessageListener(topicName)); + + } + /** * Start the example. */ @@ -94,77 +113,10 @@ public class Listener System.out.println(CLASS + ": Creating a non-transacted, auto-acknowledged session"); TopicSession session=connection.createTopicSession(false, Session.AUTO_ACKNOWLEDGE); - // lookup the topic usa - Topic topic=(Topic) ctx.lookup("usa"); - // Create a Message Subscriber - System.out.println(CLASS + ": Creating a Message Subscriber for topic usa.#"); - javax.jms.TopicSubscriber messageSubscriber=session.createSubscriber(topic); - - // Bind each topic queue to the control queue so we know when to stop - /** - * The following line uses a temporary, experimental - * Qpid extension to add another binding to the topic's private queue. - * This extension is expected to be replaced by an alternative, - * less intrusive scheme in the very near future. - */ - ((TopicSubscriber) messageSubscriber).addBindingKey(topic, "control"); - - // Set a message listener on the messageConsumer - messageSubscriber.setMessageListener(new MyMessageListener("usa")); - - // lookup the topic europe - topic=(Topic) ctx.lookup("europe"); - // Create a Message Subscriber - System.out.println(CLASS + ": Creating a Message Subscriber for topic europe.#"); - messageSubscriber=session.createSubscriber(topic); - - // Bind each topic queue to the control queue so we know when to stop - /** - * The following line uses a temporary, experimental - * Qpid extension to add another binding to the topic's private queue. - * This extension is expected to be replaced by an alternative, - * less intrusive scheme in the very near future. - */ - ((org.apache.qpid.jms.TopicSubscriber) messageSubscriber).addBindingKey(topic, "control"); - - // Set a message listener on the messageConsumer - messageSubscriber.setMessageListener(new MyMessageListener("europe")); - - // lookup the topic news - topic=(Topic) ctx.lookup("news"); - // Create a Message Subscriber - System.out.println(CLASS + ": Creating a Message Subscriber for topic #.news"); - messageSubscriber=session.createSubscriber(topic); - - // Bind each topic queue to the control queue so we know when to stop - /** - * The following line uses a temporary, experimental - * Qpid extension to add another binding to the topic's private queue. - * This extension is expected to be replaced by an alternative, - * less intrusive scheme in the very near future. - */ - ((org.apache.qpid.jms.TopicSubscriber) messageSubscriber).addBindingKey(topic, "control"); - - // Set a message listener on the messageConsumer - messageSubscriber.setMessageListener(new MyMessageListener("news")); - - // lookup the topic weather - topic=(Topic) ctx.lookup("weather"); - // Create a Message Subscriber - System.out.println(CLASS + ": Creating a Message Subscriber for topic #.weather"); - messageSubscriber=session.createSubscriber(topic); - - // Bind each topic queue to the control queue so we know when to stop - /** - * The following line uses a temporary, experimental - * Qpid extension to add another binding to the topic's private queue. - * This extension is expected to be replaced by an alternative, - * less intrusive scheme in the very near future. - */ - ((org.apache.qpid.jms.TopicSubscriber) messageSubscriber).addBindingKey(topic, "control"); - - // Set a message listener on the messageConsumer - messageSubscriber.setMessageListener(new MyMessageListener("weather")); + createListener(ctx,session,"usa"); + createListener(ctx,session,"europe"); + createListener(ctx,session,"news"); + createListener(ctx,session,"weather"); // Now the messageConsumer is set up we can start the connection System.out.println(CLASS + ": Starting connection so TopicSubscriber can receive messages"); @@ -173,7 +125,7 @@ public class Listener // Wait for the messageConsumer to have received all the messages it needs synchronized (_lock) { - while (_finished < 3 && !_failed) + while (_finished < 4 && !_failed) { _lock.wait(); } diff --git a/java/client/example/src/main/java/org/apache/qpid/example/jmsexample/pubsub/pubsub.properties b/java/client/example/src/main/java/org/apache/qpid/example/jmsexample/pubsub/pubsub.properties index c72b0122df..dc9061866a 100644 --- a/java/client/example/src/main/java/org/apache/qpid/example/jmsexample/pubsub/pubsub.properties +++ b/java/client/example/src/main/java/org/apache/qpid/example/jmsexample/pubsub/pubsub.properties @@ -25,12 +25,12 @@ connectionfactory.qpidConnectionfactory = qpid:password=pass;username=name@tcp:l # register some topics in JNDI using the form # topic.[jndiName] = [physicalName] -topic.usa.weather = usa.weather -topic.usa.news = usa.news -topic.europe.weather = europe.weather -topic.europe.news = europe.news -topic.weather = #.weather -topic.news = #.news -topic.europe = europe.# -topic.usa = usa.# +topic.usa.weather = usa.weather,control +topic.usa.news = usa.news,control +topic.europe.weather = europe.weather,control +topic.europe.news = europe.news,control +topic.weather = #.weather,control +topic.news = #.news,control +topic.europe = europe.#,control +topic.usa = usa.#,control topic.control = control
\ No newline at end of file |
