summaryrefslogtreecommitdiff
path: root/java/client/example/src
diff options
context:
space:
mode:
authorArnaud Simon <arnaudsimon@apache.org>2008-01-16 14:45:42 +0000
committerArnaud Simon <arnaudsimon@apache.org>2008-01-16 14:45:42 +0000
commit4441461688a301e03e8ed2f69484ae8f0b2c14b7 (patch)
tree5fff021e42d241085a9e407f7a8403e90d49d3bd /java/client/example/src
parentefb77b446040b4bd475fc17f7a7a122a23713f1a (diff)
downloadqpid-python-4441461688a301e03e8ed2f69484ae8f0b2c14b7.tar.gz
Changed for using JNDI destinations and log4J conf file
git-svn-id: https://svn.apache.org/repos/asf/incubator/qpid/trunk/qpid@612473 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'java/client/example/src')
-rw-r--r--java/client/example/src/main/java/log4j.xml49
-rw-r--r--java/client/example/src/main/java/org/apache/qpid/example/jmsexample/common/BaseExample.java33
-rw-r--r--java/client/example/src/main/java/org/apache/qpid/example/jmsexample/direct/Consumer.java6
-rw-r--r--java/client/example/src/main/java/org/apache/qpid/example/jmsexample/direct/Producer.java4
-rwxr-xr-xjava/client/example/src/main/java/runSample.sh7
-rw-r--r--java/client/example/src/main/java/sample.properties38
6 files changed, 116 insertions, 21 deletions
diff --git a/java/client/example/src/main/java/log4j.xml b/java/client/example/src/main/java/log4j.xml
new file mode 100644
index 0000000000..0b38b14c02
--- /dev/null
+++ b/java/client/example/src/main/java/log4j.xml
@@ -0,0 +1,49 @@
+<?xml version="1.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.
+ -
+ -->
+<!DOCTYPE log4j:configuration SYSTEM "log4j.dtd">
+<log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/">
+ <appender name="FileAppender" class="org.apache.log4j.FileAppender">
+ <param name="File" value="qpid_messaging.log"/>
+ <param name="Append" value="false"/>
+
+ <layout class="org.apache.log4j.PatternLayout">
+ <param name="ConversionPattern" value="%t %-5p %c{2} - %m%n"/>
+ </layout>
+ </appender>
+
+ <appender name="STDOUT" class="org.apache.log4j.ConsoleAppender">
+ <layout class="org.apache.log4j.PatternLayout">
+ <param name="ConversionPattern" value="%d %-5p [%t] %C{2} (%F:%L) - %m%n"/>
+ </layout>
+ </appender>
+
+ <logger name="org.apache">
+ <!-- Print only messages of level warn or above in the package org.apache -->
+ <level value="warn"/>
+ </logger>
+
+ <root>
+ <priority value="info"/>
+ <appender-ref ref="STDOUT"/>
+ <!-- <appender-ref ref="FileAppender"/> -->
+ </root>
+</log4j:configuration> \ No newline at end of file
diff --git a/java/client/example/src/main/java/org/apache/qpid/example/jmsexample/common/BaseExample.java b/java/client/example/src/main/java/org/apache/qpid/example/jmsexample/common/BaseExample.java
index 1eb207ada5..78aead5913 100644
--- a/java/client/example/src/main/java/org/apache/qpid/example/jmsexample/common/BaseExample.java
+++ b/java/client/example/src/main/java/org/apache/qpid/example/jmsexample/common/BaseExample.java
@@ -42,14 +42,14 @@ import org.apache.qpid.example.jmsexample.common.ArgProcessor;
abstract public class BaseExample
{
/* The AMQP INITIAL_CONTEXT_FACTORY */
- private static final String INITIAL_CONTEXT_FACTORY_NAME =
+ private static final String INITIAL_CONTEXT_FACTORY_NAME=
"org.apache.qpid.jndi.PropertiesFileInitialContextFactory";
/* Default connection factory name. */
- private static final String DEFAULT_CONNECTION_FACTORY_NAME = "ConnectionFactory";
+ private static final String DEFAULT_CONNECTION_FACTORY_NAME="ConnectionFactory";
/* Default number of messages to process. */
- private static final int DEFAULT_NUMBER_MESSAGES = 1;
+ private static final int DEFAULT_NUMBER_MESSAGES=10;
/* JNDI provider URL. */
private String _providerURL;
@@ -64,10 +64,10 @@ abstract public class BaseExample
protected ArgProcessor _argProcessor;
/* The supported properties */
- protected static Properties _options = new Properties();
+ protected static Properties _options=new Properties();
/* The properties default values */
- protected static Properties _defaults = new Properties();
+ protected static Properties _defaults=new Properties();
/* The broker communication objects */
private InitialContext _initialContext;
@@ -89,14 +89,14 @@ abstract public class BaseExample
_options.put("-numMessages", "Number of messages to process");
_defaults.put("-numMessages", String.valueOf(DEFAULT_NUMBER_MESSAGES));
- _argProcessor = new ArgProcessor(Id, args, _options, _defaults);
+ _argProcessor=new ArgProcessor(Id, args, _options, _defaults);
_argProcessor.display();
//Set the initial context factory
- _providerURL = _argProcessor.getStringArgument("-providerURL");
+ _providerURL=_argProcessor.getStringArgument("-providerURL");
// Set the number of messages
- _numberMessages = _argProcessor.getIntegerArgument("-numMessages");
+ _numberMessages=_argProcessor.getIntegerArgument("-numMessages");
// Set the delivery mode
- _deliveryMode = _argProcessor.getStringArgument("-deliveryMode")
+ _deliveryMode=_argProcessor.getStringArgument("-deliveryMode")
.equals("persistent") ? DeliveryMode.PERSISTENT : DeliveryMode.NON_PERSISTENT;
}
@@ -143,15 +143,18 @@ 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("connectionfactory.ConnectionFactory",
- "qpid:password=guest;username=guest;client_id=clientid;virtualhost=test@tcp:127.0.0.1:5672");
+ Hashtable<String, String> jndiEnvironment=new Hashtable<String, String>();
+ jndiEnvironment.put(Context.INITIAL_CONTEXT_FACTORY, INITIAL_CONTEXT_FACTORY_NAME);
if (getProviderURL() != null)
{
jndiEnvironment.put(Context.PROVIDER_URL, getProviderURL());
}
- _initialContext = new InitialContext(jndiEnvironment);
+ else
+ {
+ jndiEnvironment.put("connectionfactory.ConnectionFactory",
+ "qpid:password=guest;username=guest;client_id=clientid;virtualhost=test@tcp:127.0.0.1:5672");
+ }
+ _initialContext=new InitialContext(jndiEnvironment);
}
return _initialContext;
}
@@ -166,7 +169,7 @@ abstract public class BaseExample
{
if (_connectionFactory == null)
{
- _connectionFactory = (ConnectionFactory) getInitialContext().lookup(DEFAULT_CONNECTION_FACTORY_NAME);
+ _connectionFactory=(ConnectionFactory) getInitialContext().lookup(DEFAULT_CONNECTION_FACTORY_NAME);
}
return _connectionFactory;
}
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 752925f63b..4ceeff4ba0 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
@@ -57,7 +57,7 @@ public class Consumer extends BaseExample
public static void main(String[] args)
{
_options.put("-queueName", "Queue name");
- _defaults.put("-queueName", "message_queue");
+ _defaults.put("-queueName", "direct_message_queue");
Consumer syncConsumer = new Consumer(args);
syncConsumer.runTest();
}
@@ -94,8 +94,8 @@ public class Consumer extends BaseExample
Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
// lookup the queue
- Queue destination = session.createQueue(_queueName);
-
+ Queue destination = (Queue) getInitialContext().lookup(_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/Producer.java b/java/client/example/src/main/java/org/apache/qpid/example/jmsexample/direct/Producer.java
index 2f3a185809..8a91fce59e 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
@@ -52,7 +52,7 @@ public class Producer extends BaseExample
public static void main(String[] args)
{
_options.put("-queueName", "Queue name");
- _defaults.put("-queueName", "message_queue");
+ _defaults.put("-queueName", "direct_message_queue");
Producer producer = new Producer(args);
producer.runTest();
}
@@ -70,7 +70,7 @@ public class Producer extends BaseExample
Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
// lookup the queue
- Queue destination = session.createQueue(_queueName);
+ Queue destination = (Queue) getInitialContext().lookup(_queueName);
// Create a Message producer
System.out.println(CLASS + ": Creating a Message Producer");
diff --git a/java/client/example/src/main/java/runSample.sh b/java/client/example/src/main/java/runSample.sh
index ac2cbcd803..6be8636c45 100755
--- a/java/client/example/src/main/java/runSample.sh
+++ b/java/client/example/src/main/java/runSample.sh
@@ -38,6 +38,11 @@ javac -cp "$CLASSPATH" -sourcepath "$QPID_SAMPLE" -d . `find $QPID_SAMPLE -name
# Add output classes to CLASSPATH
CLASSPATH="$CLASSPATH$DIVIDER$."
+# Set VM parameters
+QPID_PARAM="$QPID_PARAM -Dlog4j.configuration=file://$QPID_SAMPLE/log4j.xml"
+
+# Set arguments
+QPID_ARGS="$QPID_ARGS -providerURL $QPID_SAMPLE/sample.properties"
# Check if the user supplied a sample classname
if test "'x$1'" = "'x'"
@@ -45,5 +50,5 @@ then
echo "No sample classname specified"
exit;
else
- java -cp $CLASSPATH $*
+ java -cp $CLASSPATH $QPID_PARAM $* $QPID_ARGS
fi \ No newline at end of file
diff --git a/java/client/example/src/main/java/sample.properties b/java/client/example/src/main/java/sample.properties
new file mode 100644
index 0000000000..9c7a6bfe42
--- /dev/null
+++ b/java/client/example/src/main/java/sample.properties
@@ -0,0 +1,38 @@
+# 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.
+
+
+java.naming.factory.initial = org.apache.qpid.jndi.PropertiesFileInitialContextFactory
+
+# A 0.10 connection factory
+connectionfactory.ConnectionFactory = qpid:password=pass;username=name@tcp:localhost:5672
+
+# register some queues in JNDI using the form
+# queue.[jndiName] = [physicalName]
+#queue.MyQueue = example.MyQueue
+#queue.syncQueue = syncQueue
+#queue.testQueue = testQueue
+
+# register some topics in JNDI using the form
+# topic.[jndiName] = [physicalName]
+#topic.ibmStocks = stocks.nyse.ibm
+#topic.testTopic = testTopic
+
+# Register an AMQP destination in JNDI
+# NOTE: Qpid currently only supports direct,topics and headers
+# destination.[jniName] = [BindingURL]
+destination.direct_message_queue = direct://amq.direct/routing_key/message_queue \ No newline at end of file