You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@qpid.apache.org by jo...@apache.org on 2010/04/16 20:32:17 UTC
svn commit: r935034 - in
/qpid/trunk/qpid/java/client/example/src/main/java/org/apache/qpid/example/jmsexample/hello:
./ Hello.java hello.properties
Author: jonathan
Date: Fri Apr 16 18:32:16 2010
New Revision: 935034
URL: http://svn.apache.org/viewvc?rev=935034&view=rev
Log:
"Hello world!" example in Java
Added:
qpid/trunk/qpid/java/client/example/src/main/java/org/apache/qpid/example/jmsexample/hello/
qpid/trunk/qpid/java/client/example/src/main/java/org/apache/qpid/example/jmsexample/hello/Hello.java
qpid/trunk/qpid/java/client/example/src/main/java/org/apache/qpid/example/jmsexample/hello/hello.properties
Added: qpid/trunk/qpid/java/client/example/src/main/java/org/apache/qpid/example/jmsexample/hello/Hello.java
URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/java/client/example/src/main/java/org/apache/qpid/example/jmsexample/hello/Hello.java?rev=935034&view=auto
==============================================================================
--- qpid/trunk/qpid/java/client/example/src/main/java/org/apache/qpid/example/jmsexample/hello/Hello.java (added)
+++ qpid/trunk/qpid/java/client/example/src/main/java/org/apache/qpid/example/jmsexample/hello/Hello.java Fri Apr 16 18:32:16 2010
@@ -0,0 +1,83 @@
+/*
+ *
+ * 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.example.jmsexample.hello;
+
+import javax.jms.*;
+import javax.naming.Context;
+import javax.naming.InitialContext;
+import java.util.Properties;
+
+/**
+ * Message producer example, sends message to a queue.
+ */
+public class Hello {
+ private static final String CLASS = "Hello";
+
+
+ public Hello() {
+ }
+
+ public static void main(String[] args) {
+ Hello producer = new Hello();
+ producer.runTest();
+ }
+
+ private void runTest() {
+ try {
+ // Create JNDI context
+ Properties properties = new Properties();
+ properties.load(this.getClass().getResourceAsStream("hello.properties"));
+ Context context = new InitialContext(properties);
+
+ ConnectionFactory connectionFactory = (ConnectionFactory) context.lookup("qpidConnectionfactory");
+ Connection connection = connectionFactory.createConnection();
+ connection.setExceptionListener(new ExceptionListener() {
+ public void onException(JMSException e) {
+ e.printStackTrace();
+ }
+ });
+
+ Session session = connection.createSession();
+ Destination destination = (Destination) context.lookup("topicExchange");
+
+ MessageProducer messageProducer = session.createProducer(destination);
+ MessageConsumer messageConsumer = session.createConsumer(destination);
+
+ Message message = session.createTextMessage("Hello world!");
+ messageProducer.send(message);
+
+ message = messageConsumer.receive();
+ if (message instanceof TextMessage) {
+ String text = ((TextMessage) message).getText();
+ System.out.println(text);
+ } else {
+ System.out.println("Ooops, not a TextMessage!");
+ }
+
+ connection.close();
+ context.close();
+ }
+ catch (Exception exp) {
+ System.err.println(CLASS + ": Caught an Exception: " + exp);
+ exp.printStackTrace();
+ }
+ }
+}
Added: qpid/trunk/qpid/java/client/example/src/main/java/org/apache/qpid/example/jmsexample/hello/hello.properties
URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/java/client/example/src/main/java/org/apache/qpid/example/jmsexample/hello/hello.properties?rev=935034&view=auto
==============================================================================
--- qpid/trunk/qpid/java/client/example/src/main/java/org/apache/qpid/example/jmsexample/hello/hello.properties (added)
+++ qpid/trunk/qpid/java/client/example/src/main/java/org/apache/qpid/example/jmsexample/hello/hello.properties Fri Apr 16 18:32:16 2010
@@ -0,0 +1,27 @@
+#
+# 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
+
+# register some connection factories
+# connectionfactory.[jndiname] = [ConnectionURL]
+connectionfactory.qpidConnectionfactory = amqp://guest:guest@clientid/test?brokerlist='tcp://localhost:5672'
+
+# Register an AMQP destination in JNDI
+# destination.[jniName] = [BindingURL]
+destination.topicExchange = amq.topic
---------------------------------------------------------------------
Apache Qpid - AMQP Messaging Implementation
Project: http://qpid.apache.org
Use/Interact: mailto:commits-subscribe@qpid.apache.org