adding new OpenWire examples

This commit is contained in:
Clebert Suconic 2015-08-12 11:22:25 -04:00
parent 1f0ea1ce21
commit a0cca44107
35 changed files with 776 additions and 31 deletions

View File

@ -17,22 +17,22 @@
package org.apache.activemq.artemis.util;
import org.apache.activemq.artemis.api.core.TransportConfiguration;
import org.apache.activemq.artemis.api.core.client.ClientSession;
import org.apache.activemq.artemis.api.jms.ActiveMQJMSClient;
import org.apache.activemq.artemis.api.jms.JMSFactoryType;
import org.apache.activemq.artemis.core.remoting.impl.netty.NettyConnectorFactory;
import org.apache.activemq.artemis.jms.client.ActiveMQConnection;
import org.apache.activemq.artemis.jms.client.ActiveMQConnectionFactory;
import javax.jms.Connection;
import java.io.BufferedReader;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.HashMap;
import org.apache.activemq.artemis.api.core.TransportConfiguration;
import org.apache.activemq.artemis.api.core.client.ClientSession;
import org.apache.activemq.artemis.api.jms.ActiveMQJMSClient;
import org.apache.activemq.artemis.jms.client.ActiveMQConnection;
import org.apache.activemq.artemis.jms.client.ActiveMQConnectionFactory;
/**
* A tool to let clients start, stop and kill Artemis servers
*/
public class ServerUtil {
public static Process startServer(String artemisInstance, String serverName) throws Exception {
@ -76,19 +76,20 @@ public class ServerUtil {
}
public static void waitForServerToStart(int id, int timeout) throws InterruptedException {
waitForServerToStart("tcp://localhost:" + (61616 + id), timeout);
}
public static void waitForServerToStart(String uri, long timeout) throws InterruptedException {
long realTimeout = System.currentTimeMillis() + timeout;
while (System.currentTimeMillis() < realTimeout) {
try {
HashMap<String, Object> params = new HashMap<String, Object>();
params.put("host", "localhost");
params.put("port", 61616 + id);
TransportConfiguration transportConfiguration = new TransportConfiguration(NettyConnectorFactory.class.getName(), params);
ActiveMQConnectionFactory cf = ActiveMQJMSClient.createConnectionFactoryWithoutHA(JMSFactoryType.CF, transportConfiguration);
ActiveMQConnectionFactory cf = ActiveMQJMSClient.createConnectionFactory(uri, null);
cf.createConnection().close();
System.out.println("server " + id + " started");
cf.close();
System.out.println("server " + uri + " started");
}
catch (Exception e) {
System.out.println("awaiting server " + id + " start at " + (61616 + id));
System.out.println("awaiting server " + uri + " start at ");
Thread.sleep(500);
continue;
}

View File

@ -32,7 +32,7 @@ under the License.
<name>ActiveMQ Artemis JMS PerfExample Example</name>
<properties>
<activemq.basedir>${project.basedir}/../../..</activemq.basedir>
<activemq.basedir>${project.basedir}/../../../..</activemq.basedir>
</properties>
<dependencies>

View File

@ -40,7 +40,7 @@ under the License.
filtered resources, i.e. build is platform dependent!
-->
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<activemq.basedir>${project.basedir}/../..</activemq.basedir>
<activemq.basedir>${project.basedir}/../../..</activemq.basedir>
</properties>
<modules>

View File

@ -41,7 +41,7 @@ under the License.
<properties>
<server.dir>${basedir}/server0/</server.dir>
<activemq.basedir>${project.basedir}/../../..</activemq.basedir>
<activemq.basedir>${project.basedir}/../../../..</activemq.basedir>
</properties>
<profiles>

View File

@ -51,6 +51,7 @@ under the License.
<module>ha</module>
<module>standard</module>
<module>sub-modules</module>
<module>perf</module>
</modules>
</profile>
<profile>
@ -60,6 +61,7 @@ under the License.
<module>ha</module>
<module>standard</module>
<module>sub-modules</module>
<module>perf</module>
</modules>
</profile>
</profiles>

View File

@ -44,14 +44,6 @@ under the License.
</properties>
<profiles>
<profile>
<id>examples</id>
<modules>
<module>proton-cpp</module>
<module>proton-j</module>
<module>proton-ruby</module>
</modules>
</profile>
<profile>
<id>release</id>
<modules>
@ -60,5 +52,15 @@ under the License.
<module>proton-ruby</module>
</modules>
</profile>
<profile>
<id>examples</id>
<modules>
<!-- this one to be run manually
<module>proton-cpp</module> -->
<module>proton-j</module>
<module>proton-ruby</module>
</modules>
</profile>
</profiles>
</project>

View File

@ -132,9 +132,6 @@ public class Chat implements javax.jms.MessageListener {
* Main program entry point.
*/
public static void main(String[] argv) {
System.out.println("len::" + argv.length);
// Is there anything to do?
if (argv.length == 0) {
printUsage();

View File

@ -0,0 +1,116 @@
<?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.
-->
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.apache.activemq.examples.openwire</groupId>
<artifactId>openwire-examples</artifactId>
<version>1.0.1-SNAPSHOT</version>
</parent>
<artifactId>message-listener</artifactId>
<packaging>jar</packaging>
<name>ActiveMQ Artemis JMS Queue Example for openwire</name>
<properties>
<activemq.basedir>${project.basedir}/../../../..</activemq.basedir>
</properties>
<dependencies>
<dependency>
<groupId>org.apache.geronimo.specs</groupId>
<artifactId>geronimo-jms_1.1_spec</artifactId>
<version>1.1</version>
</dependency>
<dependency>
<groupId>org.apache.activemq</groupId>
<artifactId>activemq-client</artifactId>
<version>${activemq5-version}</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-nop</artifactId>
<version>${slf4j-version}</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.activemq</groupId>
<artifactId>artemis-maven-plugin</artifactId>
<executions>
<execution>
<id>create</id>
<goals>
<goal>create</goal>
</goals>
</execution>
<execution>
<id>start</id>
<goals>
<goal>cli</goal>
</goals>
<configuration>
<spawn>true</spawn>
<ignore>${noServer}</ignore>
<testURI>tcp://localhost:61616</testURI>
<args>
<param>run</param>
</args>
</configuration>
</execution>
<execution>
<id>runClient</id>
<goals>
<goal>runClient</goal>
</goals>
<configuration>
<clientClass>org.apache.activemq.artemis.jms.example.QueueExample</clientClass>
</configuration>
</execution>
<execution>
<id>stop</id>
<goals>
<goal>cli</goal>
</goals>
<configuration>
<ignore>${noServer}</ignore>
<args>
<param>stop</param>
</args>
</configuration>
</execution>
</executions>
<dependencies>
<dependency>
<groupId>org.apache.activemq.examples.openwire</groupId>
<artifactId>message-listener</artifactId>
<version>${project.version}</version>
</dependency>
</dependencies>
</plugin>
</plugins>
</build>
</project>

View File

@ -0,0 +1,35 @@
<!--
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.
-->
<html>
<head>
<title>ActiveMQ Artemis JMS Queue Example</title>
<link rel="stylesheet" type="text/css" href="../../../common/common.css" />
<link rel="stylesheet" type="text/css" href="../../../common/prettify.css" />
<script type="text/javascript" src="../../../common/prettify.js"></script>
</head>
<body onload="prettyPrint()">
<h1>JMS Queue Message Listener for openwire</h1>
<pre>To run the example, simply type <b>mvn verify</b> from this directory, <br>or <b>mvn -PnoServer verify</b> if you want to start and create the server manually.</pre>
<p>This example shows how to use a MessageListener with the openwire client</p>
</body>
</html>

View File

@ -0,0 +1,103 @@
/*
* 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.activemq.artemis.jms.example;
import javax.jms.Connection;
import javax.jms.ConnectionFactory;
import javax.jms.Message;
import javax.jms.MessageConsumer;
import javax.jms.MessageListener;
import javax.jms.MessageProducer;
import javax.jms.Queue;
import javax.jms.Session;
import javax.jms.TextMessage;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;
import org.apache.activemq.ActiveMQConnectionFactory;
/**
* A simple JMS Queue example that creates a producer and consumer on a queue and sends then receives a message.
*/
public class QueueExample {
public static void main(final String[] args) throws Exception {
Connection connection = null;
try {
ConnectionFactory cf = new ActiveMQConnectionFactory();
connection = cf.createConnection();
Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
Queue queue = session.createQueue("exampleQueue");
int nMessages = 1000;
CountDownLatch latch = new CountDownLatch(nMessages);
MessageConsumer messageConsumer = session.createConsumer(queue);
messageConsumer.setMessageListener(new LocalListener(latch));
connection.start();
MessageProducer producer = session.createProducer(queue);
for (int i = 0; i < 1000; i++) {
TextMessage message = session.createTextMessage("This is a text message " + i);
System.out.println("Sent message: " + message.getText());
producer.send(message);
}
if (!latch.await(5, TimeUnit.SECONDS)) {
throw new RuntimeException("listener didn't receive all the messages");
}
System.out.println("Finished ok!");
}
finally {
if (connection != null) {
connection.close();
}
}
}
private static class LocalListener implements MessageListener {
CountDownLatch latch;
LocalListener(CountDownLatch latch) {
this.latch = latch;
}
@Override
public void onMessage(Message message) {
latch.countDown();
try {
System.out.println("Received " + ((TextMessage)message).getText());
}
catch (Exception e) {
e.printStackTrace();
}
}
}
}

View File

@ -0,0 +1,102 @@
<?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.
-->
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.apache.activemq.examples.openwire</groupId>
<artifactId>openwire-examples</artifactId>
<version>1.0.1-SNAPSHOT</version>
</parent>
<artifactId>message-recovery</artifactId>
<packaging>jar</packaging>
<name>ActiveMQ Artemis JMS Queue Example for openwire</name>
<properties>
<activemq.basedir>${project.basedir}/../../../..</activemq.basedir>
</properties>
<dependencies>
<dependency>
<groupId>org.apache.geronimo.specs</groupId>
<artifactId>geronimo-jms_1.1_spec</artifactId>
<version>1.1</version>
</dependency>
<dependency>
<groupId>org.apache.activemq</groupId>
<artifactId>activemq-client</artifactId>
<version>${activemq5-version}</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-nop</artifactId>
<version>${slf4j-version}</version>
</dependency>
<dependency>
<!-- this is to have the ServerUtil -->
<groupId>org.apache.activemq</groupId>
<artifactId>artemis-cli</artifactId>
<version>${project.version}</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.activemq</groupId>
<artifactId>artemis-maven-plugin</artifactId>
<executions>
<execution>
<id>create</id>
<goals>
<goal>create</goal>
</goals>
<configuration>
<ignore>${noServer}</ignore>
</configuration>
</execution>
<execution>
<id>runClient</id>
<goals>
<goal>runClient</goal>
</goals>
<configuration>
<clientClass>org.apache.activemq.artemis.jms.example.QueueExample</clientClass>
<args>
<param>${basedir}/target/server0</param>
</args>
</configuration>
</execution>
</executions>
<dependencies>
<dependency>
<groupId>org.apache.activemq.examples.openwire</groupId>
<artifactId>message-recovery</artifactId>
<version>${project.version}</version>
</dependency>
</dependencies>
</plugin>
</plugins>
</build>
</project>

View File

@ -0,0 +1,35 @@
<!--
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.
-->
<html>
<head>
<title>ActiveMQ Artemis JMS Queue Example</title>
<link rel="stylesheet" type="text/css" href="../../../common/common.css" />
<link rel="stylesheet" type="text/css" href="../../../common/prettify.css" />
<script type="text/javascript" src="../../../common/prettify.js"></script>
</head>
<body onload="prettyPrint()">
<h1>JMS Queue Message Listener for openwire</h1>
<pre>This example will start and stop the server within the example.</pre>
<p>This example shows how to use send messages to a queue, and having these messages recovered from the journal.</p>
</body>
</html>

View File

@ -0,0 +1,119 @@
/*
* 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.activemq.artemis.jms.example;
import javax.jms.Connection;
import javax.jms.ConnectionFactory;
import javax.jms.Message;
import javax.jms.MessageConsumer;
import javax.jms.MessageListener;
import javax.jms.MessageProducer;
import javax.jms.Queue;
import javax.jms.Session;
import javax.jms.TextMessage;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;
import org.apache.activemq.ActiveMQConnectionFactory;
import org.apache.activemq.artemis.util.ServerUtil;
/**
* A simple JMS Queue example that creates a producer and consumer on a queue and sends then receives a message.
*/
public class QueueExample {
public static void main(final String[] args) throws Exception {
Connection connection = null;
Process server0 = null;
try {
server0 = ServerUtil.startServer(args[0], QueueExample.class.getSimpleName() + "0", 0, 5000);
ConnectionFactory cf = new ActiveMQConnectionFactory();
connection = cf.createConnection();
Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
Queue queue = session.createQueue("exampleQueue");
MessageProducer producer = session.createProducer(queue);
int nMessages = 1000;
for (int i = 0; i < nMessages; i++) {
TextMessage message = session.createTextMessage("This is a text message " + i);
System.out.println("Sent message: " + message.getText());
producer.send(message);
}
connection.close();
ServerUtil.killServer(server0);
server0 = ServerUtil.startServer(args[0], QueueExample.class.getSimpleName() + "0", 0, 5000);
ServerUtil.waitForServerToStart(0, 5000);
connection = cf.createConnection();
session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
CountDownLatch latch = new CountDownLatch(nMessages);
MessageConsumer messageConsumer = session.createConsumer(queue);
messageConsumer.setMessageListener(new LocalListener(latch));
connection.start();
if (!latch.await(5, TimeUnit.SECONDS)) {
throw new RuntimeException("listener didn't receive all the messages");
}
System.out.println("Finished ok!");
}
finally {
if (connection != null) {
connection.close();
}
ServerUtil.killServer(server0);
}
}
private static class LocalListener implements MessageListener {
CountDownLatch latch;
LocalListener(CountDownLatch latch) {
this.latch = latch;
}
@Override
public void onMessage(Message message) {
latch.countDown();
try {
System.out.println("Received " + ((TextMessage)message).getText());
}
catch (Exception e) {
e.printStackTrace();
}
}
}
}

View File

@ -43,6 +43,9 @@ under the License.
<id>release</id>
<modules>
<module>chat</module>
<module>queue</module>
<module>message-listener</module>
<module>message-recovery</module>
</modules>
</profile>
<profile>
@ -50,6 +53,10 @@ under the License.
<modules>
<!-- Needs to be done manually
<module>chat</module> -->
<module>queue</module>
<module>message-listener</module>
<module>message-recovery</module>
</modules>
</profile>
</profiles>

View File

@ -0,0 +1,119 @@
<?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.
-->
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.apache.activemq.examples.openwire</groupId>
<artifactId>openwire-examples</artifactId>
<version>1.0.1-SNAPSHOT</version>
</parent>
<artifactId>queue-openwire</artifactId>
<packaging>jar</packaging>
<name>ActiveMQ Artemis JMS Queue Example for openwire</name>
<properties>
<activemq.basedir>${project.basedir}/../../../..</activemq.basedir>
</properties>
<dependencies>
<dependency>
<groupId>org.apache.geronimo.specs</groupId>
<artifactId>geronimo-jms_1.1_spec</artifactId>
<version>1.1</version>
</dependency>
<dependency>
<groupId>org.apache.activemq</groupId>
<artifactId>activemq-client</artifactId>
<version>${activemq5-version}</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-nop</artifactId>
<version>${slf4j-version}</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.activemq</groupId>
<artifactId>artemis-maven-plugin</artifactId>
<executions>
<execution>
<id>create</id>
<goals>
<goal>create</goal>
</goals>
<configuration>
<ignore>${noServer}</ignore>
</configuration>
</execution>
<execution>
<id>start</id>
<goals>
<goal>cli</goal>
</goals>
<configuration>
<spawn>true</spawn>
<ignore>${noServer}</ignore>
<testURI>tcp://localhost:61616</testURI>
<args>
<param>run</param>
</args>
</configuration>
</execution>
<execution>
<id>runClient</id>
<goals>
<goal>runClient</goal>
</goals>
<configuration>
<clientClass>org.apache.activemq.artemis.jms.example.QueueExample</clientClass>
</configuration>
</execution>
<execution>
<id>stop</id>
<goals>
<goal>cli</goal>
</goals>
<configuration>
<ignore>${noServer}</ignore>
<args>
<param>stop</param>
</args>
</configuration>
</execution>
</executions>
<dependencies>
<dependency>
<groupId>org.apache.activemq.examples.openwire</groupId>
<artifactId>queue-openwire</artifactId>
<version>${project.version}</version>
</dependency>
</dependencies>
</plugin>
</plugins>
</build>
</project>

View File

@ -0,0 +1,39 @@
<!--
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.
-->
<html>
<head>
<title>ActiveMQ Artemis JMS Queue Example</title>
<link rel="stylesheet" type="text/css" href="../../../common/common.css" />
<link rel="stylesheet" type="text/css" href="../../../common/prettify.css" />
<script type="text/javascript" src="../../../common/prettify.js"></script>
</head>
<body onload="prettyPrint()">
<h1>JMS Queue Example for open wire</h1>
<pre>To run the example, simply type <b>mvn verify</b> from this directory, <br>or <b>mvn -PnoServer verify</b> if you want to start and create the server manually.</pre>
<p>This example shows you how to send and receive a message to a JMS Queue using ActiveMQ Artemis.</p>
<p>This example does exactly the same as the <a href="../../../broker-features/standard/queue/readme.html">queue example under broker-features/standard</a>, however using the openwire client.</p>
<p>Queues are a standard part of JMS, please consult the JMS 1.1 specification for full details.</p>
<p>A Queue is used to send messages point to point, from a producer to a consumer. The queue guarantees message ordering between these 2 points.</p>
<p>Notice this example is using pretty much a default stock configuration</p>
</body>
</html>

View File

@ -0,0 +1,68 @@
/*
* 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.activemq.artemis.jms.example;
import javax.jms.Connection;
import javax.jms.ConnectionFactory;
import javax.jms.MessageConsumer;
import javax.jms.MessageProducer;
import javax.jms.Queue;
import javax.jms.Session;
import javax.jms.TextMessage;
import org.apache.activemq.ActiveMQConnectionFactory;
/**
* A simple JMS Queue example that creates a producer and consumer on a queue and sends then receives a message.
*/
public class QueueExample {
public static void main(final String[] args) throws Exception {
Connection connection = null;
try {
ConnectionFactory cf = new ActiveMQConnectionFactory();
connection = cf.createConnection();
Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
Queue queue = session.createQueue("exampleQueue");
MessageProducer producer = session.createProducer(queue);
TextMessage message = session.createTextMessage("This is a text message");
System.out.println("Sent message: " + message.getText());
producer.send(message);
MessageConsumer messageConsumer = session.createConsumer(queue);
connection.start();
TextMessage messageReceived = (TextMessage) messageConsumer.receive(5000);
System.out.println("Received message: " + messageReceived.getText());
}
finally {
if (connection != null) {
connection.close();
}
}
}
}

View File

@ -30,7 +30,7 @@ under the License.
<groupId>org.apache.activemq.examples.protocols</groupId>
<artifactId>protocols</artifactId>
<packaging>pom</packaging>
<name>ActiveMQ Artemis Clustered Examples</name>
<name>ActiveMQ Artemis Protocols Root Example</name>
<!-- Properties -->
<properties>