NO-JIRA removing example added by accident

This commit is contained in:
Clebert Suconic 2017-12-18 22:12:36 -05:00
parent de7251d546
commit fe537fa257
4 changed files with 0 additions and 405 deletions

View File

@ -1,94 +0,0 @@
<?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.broker</groupId>
<artifactId>jms-examples</artifactId>
<version>2.5.0-SNAPSHOT</version>
</parent>
<artifactId>send-acknowledgements-fail</artifactId>
<packaging>jar</packaging>
<name>ActiveMQ Artemis JMS Send Acknowledgements Example</name>
<properties>
<activemq.basedir>${project.basedir}/../../../..</activemq.basedir>
</properties>
<dependencies>
<dependency>
<groupId>org.apache.activemq</groupId>
<artifactId>artemis-jms-client-all</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<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>
<instance>${basedir}/target/server0</instance>
<args>
<arg>--global-max-size</arg>
<arg>10M</arg>
</args>
</configuration>
</execution>
<execution>
<id>runClient</id>
<goals>
<goal>runClient</goal>
</goals>
<configuration>
<clientClass>org.apache.activemq.artemis.jms.example.SendAcknowledgementsExample</clientClass>
<args>
<param>${basedir}/target/server0</param>
</args>
</configuration>
</execution>
</executions>
<dependencies>
<dependency>
<groupId>org.apache.activemq.examples.broker</groupId>
<artifactId>send-acknowledgements-fail</artifactId>
<version>${project.version}</version>
</dependency>
</dependencies>
</plugin>
</plugins>
</build>
</project>

View File

@ -1,140 +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.
-->
<html>
<head>
<title>ActiveMQ Artemis Asynchronous Send Acknowledgements 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>Asynchronous Send Acknowledgements Example</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>Asynchronous Send Acknowledgements are an advanced feature of ActiveMQ Artemis which allow you to
receive acknowledgements that messages were successfully received at the server in a separate thread to the sending thread<p/>
<p>In this example we create a normal JMS session, then set a SendAcknowledgementHandler on the JMS
session's underlying core session. We send many messages to the server without blocking and asynchronously
receive send acknowledgements via the SendAcknowledgementHandler.
<p>For more information on Asynchronous Send Acknowledgements please see the user manual</p>
<h2>Example step-by-step</h2>
<p><i>To run the example, simply type <code>mvn verify -Pexample</code> from this directory</i></p>
<ol>
<li>First we need to get an initial context so we can look-up the JMS connection factory and destination objects from JNDI. This initial context will get it's properties from the <code>client-jndi.properties</code> file in the directory <code>../common/config</code></li>
<pre class="prettyprint">
<code>InitialContext initialContext = getContext();</code>
</pre>
<li>We look-up the JMS queue object from JNDI</li>
<pre class="prettyprint">
<code>Queue queue = (Queue) initialContext.lookup("/queue/exampleQueue");</code>
</pre>
<li>We look-up the JMS connection factory object from JNDI</li>
<pre class="prettyprint">
<code>ConnectionFactory cf = (ConnectionFactory) initialContext.lookup("/ConnectionFactory");</code>
</pre>
<li>We create a JMS connection</li>
<pre class="prettyprint">
<code>connection = cf.createConnection();</code>
</pre>
<li>Define a SendAcknowledgementHandler which will receive asynchronous acknowledgements</li>
<pre class="prettyprint">
<code>
class MySendAcknowledgementsHandler implements SendAcknowledgementHandler
{
int count = 0;
public void sendAcknowledged(final Message message)
{
System.out.println("Received send acknowledgement for message " + count++);
}
}
</code>
</pre>
<li>Create a JMS session</li>
<pre class="prettyprint">
<code>Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);</code>
</pre>
<li>Set the handler on the underlying core session</li>
<pre class="prettyprint">
<code>
ClientSession coreSession = ((ActiveMQSession)session).getCoreSession();
coreSession.setSendAcknowledgementHandler(new MySendAcknowledgementsHandler());
</code>
</pre>
<li>Create a JMS Message Producer</li>
<pre class="prettyprint">
<code>
MessageProducer producer = session.createProducer(queue);
producer.setDeliveryMode(DeliveryMode.NON_PERSISTENT);
</code>
</pre>
<li>Send 5000 messages, the handler will get called asynchronously some time later after the messages are sent.</li>
<pre class="prettyprint">
<code>
final int numMessages = 5000;
for (int i = 0; i < numMessages; i++)
{
javax.jms.Message jmsMessage = session.createMessage();
producer.send(jmsMessage);
System.out.println("Sent message " + i);
}
</code>
</pre>
<li>And finally, <b>always</b> remember to close your JMS connections and resources after use, in a <code>finally</code> block. Closing a JMS connection will automatically close all of its sessions, consumers, producer and browser objects</li>
<pre class="prettyprint">
<code>finally
{
if (initialContext != null)
{
initialContext.close();
}
if (connection != null)
{
connection.close();
}
}</code>
</pre>
</ol>
</body>
</html>

View File

@ -1,151 +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.
*/
package org.apache.activemq.artemis.jms.example;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;
import org.apache.activemq.artemis.api.core.Message;
import org.apache.activemq.artemis.api.core.RoutingType;
import org.apache.activemq.artemis.api.core.SimpleString;
import org.apache.activemq.artemis.api.core.client.ActiveMQClient;
import org.apache.activemq.artemis.api.core.client.ClientConsumer;
import org.apache.activemq.artemis.api.core.client.ClientMessage;
import org.apache.activemq.artemis.api.core.client.ClientProducer;
import org.apache.activemq.artemis.api.core.client.ClientSession;
import org.apache.activemq.artemis.api.core.client.ClientSessionFactory;
import org.apache.activemq.artemis.api.core.client.SendAcknowledgementHandler;
import org.apache.activemq.artemis.api.core.client.ServerLocator;
import org.apache.activemq.artemis.util.ServerUtil;
/**
* Asynchronous Send Acknowledgements are an advanced feature of ActiveMQ Artemis which allow you to
* receive acknowledgements that messages were successfully received at the server in a separate stream
* to the stream of messages being sent to the server.
* For more information please see the readme.html file
*/
public class SendAcknowledgementsExample {
private static Process server0;
private static final int numMessages = 30_000;
private static final SimpleString queueName = SimpleString.toSimpleString("testQueue");
public static void main(final String[] args) throws Exception {
for (int i = 0; i < 500; i++) {
System.out.println("$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$ Running test " + i);
server0 = ServerUtil.startServer(args[0], SendAcknowledgementsExample.class.getSimpleName() + "0", 0, 10000);
sendMessages();
server0 = ServerUtil.startServer(args[0], SendAcknowledgementsExample.class.getSimpleName() + "0", 0, 10000);
consumeMessages();
}
}
private static void sendMessages() throws Exception {
try {
ServerLocator locator = ActiveMQClient.createServerLocator("tcp://localhost:61616").setBlockOnDurableSend(false).setConfirmationWindowSize(1024 * 1024);
ClientSessionFactory factory = locator.createSessionFactory();
ClientSession session = factory.createSession(null, null, false, true, true, false, ActiveMQClient.DEFAULT_ACK_BATCH_SIZE);
try {
// Tried with and without the createAddress
session.createAddress(queueName, RoutingType.MULTICAST, false);
session.createQueue(queueName.toString(), RoutingType.MULTICAST, queueName.toString(), true);
} catch (Exception e) {
}
ClientProducer producer = session.createProducer(queueName);
CountDownLatch latch = new CountDownLatch(numMessages);
for (int i = 0; i < numMessages; i++) {
if (i % 10000 == 0) {
System.out.println("Send " + i);
}
ClientMessage message = session.createMessage(true);
message.getBodyBuffer().writeBytes("hello world".getBytes());
// tried with producer.send(queueName, message, ...);; // didn't make a difference
producer.send(message, new SendAcknowledgementHandler() {
@Override
public void sendAcknowledged(Message message) {
latch.countDown();
if (latch.getCount() % 10_000 == 0) {
System.out.println(latch.getCount() + " to go");
}
}
});
}
latch.await(10, TimeUnit.MINUTES);
} finally {
server0.destroy();
server0.waitFor();
}
}
private static void consumeMessages() throws Exception {
try {
ServerLocator locator = ActiveMQClient.createServerLocator("tcp://localhost:61616").setBlockOnDurableSend(false).setConfirmationWindowSize(-1);
ClientSessionFactory factory = locator.createSessionFactory();
ClientSession session = factory.createSession(null, null, false, false, false, false, ActiveMQClient.DEFAULT_ACK_BATCH_SIZE);
ClientConsumer consumer = session.createConsumer(queueName);
session.start();
for (int i = 0; i < numMessages; i++) {
if (i % 10000 == 0) {
System.out.println("Received " + i);
}
ClientMessage message = consumer.receive(5000);
message.acknowledge();
if (message == null) {
System.err.println("Expected message at " + i);
System.exit(-1);
}
}
session.commit();
ClientMessage message = consumer.receiveImmediate();
if (message != null) {
System.err.println("Received too many messages");
System.exit(-1);
}
session.close();
locator.close();
} finally {
server0.destroy();
server0.waitFor();
}
}
}

View File

@ -1,20 +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.
java.naming.factory.initial=org.apache.activemq.artemis.jndi.ActiveMQInitialContextFactory
connectionFactory.ConnectionFactory=tcp://localhost:61616?confirmationWindowSize=1048576
queue.queue/exampleQueue=exampleQueue