http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/21bf4406/examples/broker-features/standard/send-acknowledgements/readme.html ---------------------------------------------------------------------- diff --git a/examples/broker-features/standard/send-acknowledgements/readme.html b/examples/broker-features/standard/send-acknowledgements/readme.html new file mode 100644 index 0000000..fcc37fc --- /dev/null +++ b/examples/broker-features/standard/send-acknowledgements/readme.html @@ -0,0 +1,140 @@ +<!-- +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>
http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/21bf4406/examples/broker-features/standard/send-acknowledgements/src/main/java/org/apache/activemq/artemis/jms/example/SendAcknowledgementsExample.java ---------------------------------------------------------------------- diff --git a/examples/broker-features/standard/send-acknowledgements/src/main/java/org/apache/activemq/artemis/jms/example/SendAcknowledgementsExample.java b/examples/broker-features/standard/send-acknowledgements/src/main/java/org/apache/activemq/artemis/jms/example/SendAcknowledgementsExample.java new file mode 100644 index 0000000..578d198 --- /dev/null +++ b/examples/broker-features/standard/send-acknowledgements/src/main/java/org/apache/activemq/artemis/jms/example/SendAcknowledgementsExample.java @@ -0,0 +1,104 @@ +/* + * 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.DeliveryMode; +import javax.jms.MessageProducer; +import javax.jms.Queue; +import javax.jms.Session; +import javax.naming.InitialContext; + +import org.apache.activemq.artemis.api.core.Message; +import org.apache.activemq.artemis.api.core.client.ClientSession; +import org.apache.activemq.artemis.api.core.client.SendAcknowledgementHandler; +import org.apache.activemq.artemis.jms.client.ActiveMQSession; + +/** + * 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 { + + public static void main(final String[] args) throws Exception { + Connection connection = null; + InitialContext initialContext = null; + try { + // Step 1. Create an initial context to perform the JNDI lookup. + initialContext = new InitialContext(); + + // Step 2. Perfom a lookup on the queue + Queue queue = (Queue) initialContext.lookup("queue/exampleQueue"); + + // Step 3. Perform a lookup on the Connection Factory + ConnectionFactory cf = (ConnectionFactory) initialContext.lookup("ConnectionFactory"); + + // Step 4. Create a JMS Connection + connection = cf.createConnection(); + + // Step 5. Define a SendAcknowledgementHandler which will receive asynchronous acknowledgements + class MySendAcknowledgementsHandler implements SendAcknowledgementHandler { + + int count = 0; + + public void sendAcknowledged(final Message message) { + System.out.println("Received send acknowledgement for message " + count++); + } + } + + // Step 6. Create a JMS Session + Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE); + + // Step 7. Set the handler on the underlying core session + + ClientSession coreSession = ((ActiveMQSession) session).getCoreSession(); + + coreSession.setSendAcknowledgementHandler(new MySendAcknowledgementsHandler()); + + // Step 6. Create a JMS Message Producer + MessageProducer producer = session.createProducer(queue); + + producer.setDeliveryMode(DeliveryMode.NON_PERSISTENT); + + // Step 7. Send 5000 messages, the handler will get called asynchronously some time later after the messages + // are sent. + + 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); + } + } + finally { + // Step 12. Be sure to close our JMS resources! + if (initialContext != null) { + initialContext.close(); + } + + if (connection != null) { + connection.close(); + } + } + } +} http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/21bf4406/examples/broker-features/standard/send-acknowledgements/src/main/resources/jndi.properties ---------------------------------------------------------------------- diff --git a/examples/broker-features/standard/send-acknowledgements/src/main/resources/jndi.properties b/examples/broker-features/standard/send-acknowledgements/src/main/resources/jndi.properties new file mode 100644 index 0000000..8421f25 --- /dev/null +++ b/examples/broker-features/standard/send-acknowledgements/src/main/resources/jndi.properties @@ -0,0 +1,20 @@ +# 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 http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/21bf4406/examples/broker-features/standard/spring-integration/pom.xml ---------------------------------------------------------------------- diff --git a/examples/broker-features/standard/spring-integration/pom.xml b/examples/broker-features/standard/spring-integration/pom.xml new file mode 100644 index 0000000..238a550 --- /dev/null +++ b/examples/broker-features/standard/spring-integration/pom.xml @@ -0,0 +1,82 @@ +<?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>1.0.1-SNAPSHOT</version> + </parent> + + <artifactId>spring-integration</artifactId> + <packaging>jar</packaging> + <name>ActiveMQ Artemis JMS Spring Integration Example</name> + + <properties> + <activemq.basedir>${project.basedir}/../../../..</activemq.basedir> + </properties> + + <dependencies> + <dependency> + <groupId>org.apache.activemq</groupId> + <artifactId>artemis-spring-integration</artifactId> + <version>${project.version}</version> + </dependency> + <dependency> + <groupId>org.apache.geronimo.specs</groupId> + <artifactId>geronimo-jms_2.0_spec</artifactId> + </dependency> + <dependency> + <groupId>org.springframework</groupId> + <artifactId>spring-context</artifactId> + </dependency> + </dependencies> + + <build> + <plugins> + <plugin> + <groupId>org.apache.activemq</groupId> + <artifactId>artemis-maven-plugin</artifactId> + <executions> + <execution> + <id>runClient</id> + <goals> + <goal>runClient</goal> + </goals> + <configuration> + <clientClass>org.apache.activemq.artemis.jms.example.SpringExample</clientClass> + </configuration> + </execution> + </executions> + <dependencies> + <dependency> + <groupId>org.apache.activemq.examples.broker</groupId> + <artifactId>spring-integration</artifactId> + <version>${project.version}</version> + </dependency> + </dependencies> + </plugin> + </plugins> + </build> + +</project> http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/21bf4406/examples/broker-features/standard/spring-integration/readme.html ---------------------------------------------------------------------- diff --git a/examples/broker-features/standard/spring-integration/readme.html b/examples/broker-features/standard/spring-integration/readme.html new file mode 100644 index 0000000..a3855d0 --- /dev/null +++ b/examples/broker-features/standard/spring-integration/readme.html @@ -0,0 +1,36 @@ +<!-- +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 Spring 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>ActiveMQ Artemis Spring Example</h1> + + <p>This examples shows how to setup and run an embedded JMS server within a Spring ApplicationContext using ActiveMQ Artemis along with ActiveMQ Artemis configuration files.</p> + + <h2>Example step-by-step</h2> + <p><i><b>YOU MUST DOWNLOAD THE SPRING LIBRARIES TO RUN THIS EXAMPLE!!!</b> You must also modify the build.xml file to include the spring jars. You'll see the placeholder that is already there.</i></p> + <p><i>To run the example, simply type <code>mvn verify -Pexample</code> from this directory</i></p> + </body> +</html> http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/21bf4406/examples/broker-features/standard/spring-integration/src/main/java/org/apache/activemq/artemis/jms/example/ExampleListener.java ---------------------------------------------------------------------- diff --git a/examples/broker-features/standard/spring-integration/src/main/java/org/apache/activemq/artemis/jms/example/ExampleListener.java b/examples/broker-features/standard/spring-integration/src/main/java/org/apache/activemq/artemis/jms/example/ExampleListener.java new file mode 100644 index 0000000..3d4e063 --- /dev/null +++ b/examples/broker-features/standard/spring-integration/src/main/java/org/apache/activemq/artemis/jms/example/ExampleListener.java @@ -0,0 +1,37 @@ +/* + * 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.JMSException; +import javax.jms.Message; +import javax.jms.MessageListener; +import javax.jms.TextMessage; + +public class ExampleListener implements MessageListener { + + protected static String lastMessage = null; + + public void onMessage(Message message) { + try { + lastMessage = ((TextMessage) message).getText(); + } + catch (JMSException e) { + throw new RuntimeException(e); + } + System.out.println("MESSAGE RECEIVED: " + lastMessage); + } +} http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/21bf4406/examples/broker-features/standard/spring-integration/src/main/java/org/apache/activemq/artemis/jms/example/MessageSender.java ---------------------------------------------------------------------- diff --git a/examples/broker-features/standard/spring-integration/src/main/java/org/apache/activemq/artemis/jms/example/MessageSender.java b/examples/broker-features/standard/spring-integration/src/main/java/org/apache/activemq/artemis/jms/example/MessageSender.java new file mode 100644 index 0000000..594c69b --- /dev/null +++ b/examples/broker-features/standard/spring-integration/src/main/java/org/apache/activemq/artemis/jms/example/MessageSender.java @@ -0,0 +1,71 @@ +/* + * 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.Destination; +import javax.jms.JMSException; +import javax.jms.MessageProducer; +import javax.jms.Session; +import javax.jms.TextMessage; + +public class MessageSender { + + private ConnectionFactory connectionFactory; + private Destination destination; + + public ConnectionFactory getConnectionFactory() { + return connectionFactory; + } + + public void setConnectionFactory(ConnectionFactory connectionFactory) { + this.connectionFactory = connectionFactory; + } + + public Destination getDestination() { + return destination; + } + + public void setDestination(Destination destination) { + this.destination = destination; + } + + public void send(String msg) { + Connection conn = null; + try { + conn = connectionFactory.createConnection(); + Session session = conn.createSession(false, Session.AUTO_ACKNOWLEDGE); + MessageProducer producer = session.createProducer(destination); + TextMessage message = session.createTextMessage(msg); + producer.send(message); + } + catch (Exception ex) { + ex.printStackTrace(); + } + finally { + if (conn != null) { + try { + conn.close(); + } + catch (JMSException e) { + e.printStackTrace(); + } + } + } + } +} http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/21bf4406/examples/broker-features/standard/spring-integration/src/main/java/org/apache/activemq/artemis/jms/example/SpringExample.java ---------------------------------------------------------------------- diff --git a/examples/broker-features/standard/spring-integration/src/main/java/org/apache/activemq/artemis/jms/example/SpringExample.java b/examples/broker-features/standard/spring-integration/src/main/java/org/apache/activemq/artemis/jms/example/SpringExample.java new file mode 100644 index 0000000..cf3ec49 --- /dev/null +++ b/examples/broker-features/standard/spring-integration/src/main/java/org/apache/activemq/artemis/jms/example/SpringExample.java @@ -0,0 +1,32 @@ +/* + * 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 org.springframework.context.support.ClassPathXmlApplicationContext; + +public class SpringExample { + + public static void main(String[] args) throws Exception { + System.out.println("Creating bean factory..."); + ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(new String[]{"spring-jms-beans.xml"}); + MessageSender sender = (MessageSender) context.getBean("MessageSender"); + System.out.println("Sending message..."); + sender.send("Hello world"); + Thread.sleep(100); + context.destroy(); + } +} http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/21bf4406/examples/broker-features/standard/spring-integration/src/main/resources/artemis-roles.properties ---------------------------------------------------------------------- diff --git a/examples/broker-features/standard/spring-integration/src/main/resources/artemis-roles.properties b/examples/broker-features/standard/spring-integration/src/main/resources/artemis-roles.properties new file mode 100644 index 0000000..4e2d44c --- /dev/null +++ b/examples/broker-features/standard/spring-integration/src/main/resources/artemis-roles.properties @@ -0,0 +1,17 @@ +## --------------------------------------------------------------------------- +## 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. +## --------------------------------------------------------------------------- +guest=guest \ No newline at end of file http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/21bf4406/examples/broker-features/standard/spring-integration/src/main/resources/artemis-users.properties ---------------------------------------------------------------------- diff --git a/examples/broker-features/standard/spring-integration/src/main/resources/artemis-users.properties b/examples/broker-features/standard/spring-integration/src/main/resources/artemis-users.properties new file mode 100644 index 0000000..4e2d44c --- /dev/null +++ b/examples/broker-features/standard/spring-integration/src/main/resources/artemis-users.properties @@ -0,0 +1,17 @@ +## --------------------------------------------------------------------------- +## 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. +## --------------------------------------------------------------------------- +guest=guest \ No newline at end of file http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/21bf4406/examples/broker-features/standard/spring-integration/src/main/resources/broker.xml ---------------------------------------------------------------------- diff --git a/examples/broker-features/standard/spring-integration/src/main/resources/broker.xml b/examples/broker-features/standard/spring-integration/src/main/resources/broker.xml new file mode 100644 index 0000000..2970329 --- /dev/null +++ b/examples/broker-features/standard/spring-integration/src/main/resources/broker.xml @@ -0,0 +1,53 @@ +<?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. +--> + +<configuration xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xmlns="urn:activemq" + xsi:schemaLocation="urn:activemq /schema/artemis-server.xsd"> + + <jms xmlns="urn:activemq:jms"> + <!--the queue used by the example--> + <queue name="exampleQueue"/> + </jms> + + <core xmlns="urn:activemq:core"> + + <persistence-enabled>false</persistence-enabled> + + <acceptors> + <acceptor name="in-vm">vm://0</acceptor> + </acceptors> + + <!-- Other config --> + + <security-settings> + <!--security for example queue--> + <security-setting match="#"> + <permission type="createDurableQueue" roles="guest"/> + <permission type="deleteDurableQueue" roles="guest"/> + <permission type="createNonDurableQueue" roles="guest"/> + <permission type="deleteNonDurableQueue" roles="guest"/> + <permission type="consume" roles="guest"/> + <permission type="send" roles="guest"/> + </security-setting> + </security-settings> + + </core> +</configuration> http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/21bf4406/examples/broker-features/standard/spring-integration/src/main/resources/spring-jms-beans.xml ---------------------------------------------------------------------- diff --git a/examples/broker-features/standard/spring-integration/src/main/resources/spring-jms-beans.xml b/examples/broker-features/standard/spring-integration/src/main/resources/spring-jms-beans.xml new file mode 100644 index 0000000..a67de73 --- /dev/null +++ b/examples/broker-features/standard/spring-integration/src/main/resources/spring-jms-beans.xml @@ -0,0 +1,80 @@ +<?xml version="1.0" encoding="UTF-8"?> + +<!-- +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. +--> + +<beans xmlns="http://www.springframework.org/schema/beans" + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://www.springframework.org/schema/beans + http://www.springframework.org/schema/beans/spring-beans-3.0.xsd"> + + <bean id="securityManager" class="org.apache.activemq.artemis.spi.core.security.ActiveMQSecurityManagerImpl"> + <constructor-arg> + <bean class="org.apache.activemq.artemis.core.config.impl.SecurityConfiguration"> + <constructor-arg name="users"> + <map> + <entry key="guest" value="guest"/> + </map> + </constructor-arg> + <constructor-arg name="roles"> + <map> + <entry key="guest"> + <list> + <value>guest</value> + </list> + </entry> + </map> + </constructor-arg> + <property name="DefaultUser" value="guest"/> + </bean> + </constructor-arg> + </bean> + + <bean id="EmbeddedJms" class="org.apache.activemq.artemis.integration.spring.SpringJmsBootstrap" init-method="start" + destroy-method="stop"> + <property name="SecurityManager" ref="securityManager"/> + </bean> + + <bean id="connectionFactory" class="org.apache.activemq.artemis.jms.client.ActiveMQJMSConnectionFactory"> + <constructor-arg value="false"/> + <constructor-arg> + <bean class="org.apache.activemq.artemis.api.core.TransportConfiguration"> + <constructor-arg value="org.apache.activemq.artemis.core.remoting.impl.invm.InVMConnectorFactory"/> + </bean> + </constructor-arg> + </bean> + + <bean id="exampleQueue" class="org.apache.activemq.artemis.jms.client.ActiveMQQueue"> + <constructor-arg index="0" value="exampleQueue"/> + </bean> + + <bean id="listener" class="org.apache.activemq.artemis.jms.example.ExampleListener"/> + + <bean id="MessageSender" class="org.apache.activemq.artemis.jms.example.MessageSender"> + <property name="connectionFactory" ref="connectionFactory"/> + <property name="destination" ref="exampleQueue"/> + </bean> + + <bean id="listenerContainer" class="org.springframework.jms.listener.DefaultMessageListenerContainer"> + <property name="connectionFactory" ref="connectionFactory"/> + <property name="destination" ref="exampleQueue"/> + <property name="messageListener" ref="listener"/> + </bean> +</beans> + http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/21bf4406/examples/broker-features/standard/ssl-enabled/pom.xml ---------------------------------------------------------------------- diff --git a/examples/broker-features/standard/ssl-enabled/pom.xml b/examples/broker-features/standard/ssl-enabled/pom.xml new file mode 100644 index 0000000..7a76435 --- /dev/null +++ b/examples/broker-features/standard/ssl-enabled/pom.xml @@ -0,0 +1,109 @@ +<?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>1.0.1-SNAPSHOT</version> + </parent> + + <artifactId>ssl-enabled</artifactId> + <packaging>jar</packaging> + <name>ActiveMQ Artemis JMS SSL Enabled Example</name> + + <properties> + <activemq.basedir>${project.basedir}/../../../..</activemq.basedir> + </properties> + + <dependencies> + <dependency> + <groupId>org.apache.activemq</groupId> + <artifactId>artemis-jms-client</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>start</id> + <goals> + <goal>cli</goal> + </goals> + <configuration> + <ignore>${noServer}</ignore> + <spawn>true</spawn> + <testURI>tcp://localhost:5500?sslEnabled=true&trustStorePath=activemq/server0/activemq.example.truststore&trustStorePassword=activemqexample</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.SSLExample</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.broker</groupId> + <artifactId>ssl-enabled</artifactId> + <version>${project.version}</version> + </dependency> + </dependencies> + </plugin> + </plugins> + </build> + +</project> http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/21bf4406/examples/broker-features/standard/ssl-enabled/readme.html ---------------------------------------------------------------------- diff --git a/examples/broker-features/standard/ssl-enabled/readme.html b/examples/broker-features/standard/ssl-enabled/readme.html new file mode 100644 index 0000000..bb5e724 --- /dev/null +++ b/examples/broker-features/standard/ssl-enabled/readme.html @@ -0,0 +1,56 @@ +<!-- +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 SSL 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 SSL 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>This example shows you how to configure SSL with ActiveMQ Artemis to send and receive message. </p> + + <p>Using SSL can make your messaging applications interact with ActiveMQ Artemis securely. An application can + be secured transparently without extra coding effort. To secure your messaging application with SSL, you need to configure connector and acceptor as follows:</p> + + <p> + <pre class="prettyprint"> + <code> + <!-- Connector --> + + <connector name="netty-ssl-connector">tcp://localhost:5500?sslEnabled=true;keyStorePath=activemq/server0/activemq.example.keystore;keyStorePassword=activemqexample</connector> + + <!-- Acceptor --> + + <acceptor name="netty-ssl-acceptor">tcp://localhost:5500?sslEnabled=true;keyStorePath=activemq/server0/activemq.example.keystore;keyStorePassword=activemqexample</acceptor> + + </code> + </pre> + </p> + + <p>In the configuration, the activemq.example.keystore is the key store file holding the server's certificate. The activemq.example.truststore + is the file holding the certificates which the client trusts (i.e. the server's certificate exported from activemq.example.keystore). They are pre-generated for illustration purpose<a id="fnr1" href="readme.html#fn1"><sup>1</sup></a>.</p> + </body> +</html> http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/21bf4406/examples/broker-features/standard/ssl-enabled/src/main/java/org/apache/activemq/artemis/jms/example/SSLExample.java ---------------------------------------------------------------------- diff --git a/examples/broker-features/standard/ssl-enabled/src/main/java/org/apache/activemq/artemis/jms/example/SSLExample.java b/examples/broker-features/standard/ssl-enabled/src/main/java/org/apache/activemq/artemis/jms/example/SSLExample.java new file mode 100644 index 0000000..27bf739 --- /dev/null +++ b/examples/broker-features/standard/ssl-enabled/src/main/java/org/apache/activemq/artemis/jms/example/SSLExample.java @@ -0,0 +1,86 @@ +/* + * 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 javax.naming.InitialContext; + +/** + * A simple JMS Queue example that uses SSL secure transport. + */ +public class SSLExample { + + public static void main(final String[] args) throws Exception { + Connection connection = null; + InitialContext initialContext = null; + try { + // Step 1. Create an initial context to perform the JNDI lookup. + initialContext = new InitialContext(); + + // Step 2. Perfom a lookup on the queue + Queue queue = (Queue) initialContext.lookup("queue/exampleQueue"); + + // Step 3. Perform a lookup on the Connection Factory + ConnectionFactory cf = (ConnectionFactory) initialContext.lookup("ConnectionFactory"); + + // Step 4.Create a JMS Connection + connection = cf.createConnection(); + + // Step 5. Create a JMS Session + Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE); + + // Step 6. Create a JMS Message Producer + MessageProducer producer = session.createProducer(queue); + + // Step 7. Create a Text Message + TextMessage message = session.createTextMessage("This is a text message"); + + System.out.println("Sent message: " + message.getText()); + + // Step 8. Send the Message + producer.send(message); + + // Step 9. Create a JMS Message Consumer + MessageConsumer messageConsumer = session.createConsumer(queue); + + // Step 10. Start the Connection + connection.start(); + + // Step 11. Receive the message + TextMessage messageReceived = (TextMessage) messageConsumer.receive(5000); + + System.out.println("Received message: " + messageReceived.getText()); + + initialContext.close(); + } + finally { + // Step 12. Be sure to close our JMS resources! + if (initialContext != null) { + initialContext.close(); + } + if (connection != null) { + connection.close(); + } + } + } +} http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/21bf4406/examples/broker-features/standard/ssl-enabled/src/main/resources/activemq/server0/activemq.example.keystore ---------------------------------------------------------------------- diff --git a/examples/broker-features/standard/ssl-enabled/src/main/resources/activemq/server0/activemq.example.keystore b/examples/broker-features/standard/ssl-enabled/src/main/resources/activemq/server0/activemq.example.keystore new file mode 100644 index 0000000..50de681 Binary files /dev/null and b/examples/broker-features/standard/ssl-enabled/src/main/resources/activemq/server0/activemq.example.keystore differ http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/21bf4406/examples/broker-features/standard/ssl-enabled/src/main/resources/activemq/server0/activemq.example.truststore ---------------------------------------------------------------------- diff --git a/examples/broker-features/standard/ssl-enabled/src/main/resources/activemq/server0/activemq.example.truststore b/examples/broker-features/standard/ssl-enabled/src/main/resources/activemq/server0/activemq.example.truststore new file mode 100644 index 0000000..129391a Binary files /dev/null and b/examples/broker-features/standard/ssl-enabled/src/main/resources/activemq/server0/activemq.example.truststore differ http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/21bf4406/examples/broker-features/standard/ssl-enabled/src/main/resources/activemq/server0/artemis-roles.properties ---------------------------------------------------------------------- diff --git a/examples/broker-features/standard/ssl-enabled/src/main/resources/activemq/server0/artemis-roles.properties b/examples/broker-features/standard/ssl-enabled/src/main/resources/activemq/server0/artemis-roles.properties new file mode 100644 index 0000000..4e2d44c --- /dev/null +++ b/examples/broker-features/standard/ssl-enabled/src/main/resources/activemq/server0/artemis-roles.properties @@ -0,0 +1,17 @@ +## --------------------------------------------------------------------------- +## 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. +## --------------------------------------------------------------------------- +guest=guest \ No newline at end of file http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/21bf4406/examples/broker-features/standard/ssl-enabled/src/main/resources/activemq/server0/artemis-users.properties ---------------------------------------------------------------------- diff --git a/examples/broker-features/standard/ssl-enabled/src/main/resources/activemq/server0/artemis-users.properties b/examples/broker-features/standard/ssl-enabled/src/main/resources/activemq/server0/artemis-users.properties new file mode 100644 index 0000000..4e2d44c --- /dev/null +++ b/examples/broker-features/standard/ssl-enabled/src/main/resources/activemq/server0/artemis-users.properties @@ -0,0 +1,17 @@ +## --------------------------------------------------------------------------- +## 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. +## --------------------------------------------------------------------------- +guest=guest \ No newline at end of file http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/21bf4406/examples/broker-features/standard/ssl-enabled/src/main/resources/activemq/server0/broker.xml ---------------------------------------------------------------------- diff --git a/examples/broker-features/standard/ssl-enabled/src/main/resources/activemq/server0/broker.xml b/examples/broker-features/standard/ssl-enabled/src/main/resources/activemq/server0/broker.xml new file mode 100644 index 0000000..f0de0fc --- /dev/null +++ b/examples/broker-features/standard/ssl-enabled/src/main/resources/activemq/server0/broker.xml @@ -0,0 +1,60 @@ +<?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. +--> + +<configuration xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xmlns="urn:activemq" + xsi:schemaLocation="urn:activemq /schema/artemis-server.xsd"> + + <jms xmlns="urn:activemq:jms"> + <!--the queue used by the example--> + <queue name="exampleQueue"/> + </jms> + + <core xmlns="urn:activemq:core"> + + <bindings-directory>${data.dir}/server0/data/messaging/bindings</bindings-directory> + + <journal-directory>${data.dir}/server0/data/messaging/journal</journal-directory> + + <large-messages-directory>${data.dir}/server0/data/messaging/largemessages</large-messages-directory> + + <paging-directory>${data.dir}/server0/data/messaging/paging</paging-directory> + + <!-- Acceptors --> + <acceptors> + <acceptor name="netty-ssl-acceptor">tcp://localhost:5500?sslEnabled=true;keyStorePath=activemq/server0/activemq.example.keystore;keyStorePassword=activemqexample</acceptor> + </acceptors> + + <!-- Other config --> + + <security-settings> + <!--security for example queue--> + <security-setting match="jms.queue.exampleQueue"> + <permission type="createDurableQueue" roles="guest"/> + <permission type="deleteDurableQueue" roles="guest"/> + <permission type="createNonDurableQueue" roles="guest"/> + <permission type="deleteNonDurableQueue" roles="guest"/> + <permission type="consume" roles="guest"/> + <permission type="send" roles="guest"/> + </security-setting> + </security-settings> + + </core> +</configuration> http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/21bf4406/examples/broker-features/standard/ssl-enabled/src/main/resources/jndi.properties ---------------------------------------------------------------------- diff --git a/examples/broker-features/standard/ssl-enabled/src/main/resources/jndi.properties b/examples/broker-features/standard/ssl-enabled/src/main/resources/jndi.properties new file mode 100644 index 0000000..7929c7c --- /dev/null +++ b/examples/broker-features/standard/ssl-enabled/src/main/resources/jndi.properties @@ -0,0 +1,20 @@ +# 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:5500?sslEnabled=true&trustStorePath=activemq/server0/activemq.example.truststore&trustStorePassword=activemqexample +queue.queue/exampleQueue=exampleQueue http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/21bf4406/examples/broker-features/standard/static-selector/pom.xml ---------------------------------------------------------------------- diff --git a/examples/broker-features/standard/static-selector/pom.xml b/examples/broker-features/standard/static-selector/pom.xml new file mode 100644 index 0000000..1ce08e6 --- /dev/null +++ b/examples/broker-features/standard/static-selector/pom.xml @@ -0,0 +1,109 @@ +<?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>1.0.1-SNAPSHOT</version> + </parent> + + <artifactId>static-selector</artifactId> + <packaging>jar</packaging> + <name>ActiveMQ Artemis Static Selector Example</name> + + <properties> + <activemq.basedir>${project.basedir}/../../../..</activemq.basedir> + </properties> + + <dependencies> + <dependency> + <groupId>org.apache.activemq</groupId> + <artifactId>artemis-jms-client</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>start</id> + <goals> + <goal>cli</goal> + </goals> + <configuration> + <ignore>${noServer}</ignore> + <spawn>true</spawn> + <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.StaticSelectorExample</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.broker</groupId> + <artifactId>static-selector</artifactId> + <version>${project.version}</version> + </dependency> + </dependencies> + </plugin> + </plugins> + </build> + +</project> http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/21bf4406/examples/broker-features/standard/static-selector/readme.html ---------------------------------------------------------------------- diff --git a/examples/broker-features/standard/static-selector/readme.html b/examples/broker-features/standard/static-selector/readme.html new file mode 100644 index 0000000..0dca49f --- /dev/null +++ b/examples/broker-features/standard/static-selector/readme.html @@ -0,0 +1,60 @@ +<!-- +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 Static Message Selector 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>Static Message Selector 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>This example shows you how to configure a ActiveMQ Artemis queue with static message selectors (filters) + (to configure a static selector directly on a <em>JMS</em> queue, please see the + <a href="../static-selector-jms/readme.html">static-selector-jms example</a>).</p> + + <p>Static message selectors are ActiveMQ's extension to message selectors as defined in JMS spec 1.1. + Rather than specifying the selector in the application code, static message selectors are defined in one of + ActiveMQ's configuration files, broker.xml, as an element called 'filter' inside each queue + definition, like</p> + + <pre class="prettyprint"><code> + <queues> + <queue name="jms.queue.selectorQueue"> + <address>jms.queue.selectorQueue</address> + <filter string="color='red'"/> + </queue> + </queues> + </code></pre> + + <p>Once configured the queue 'selectorQueue' only delivers messages that are selected against the filter, i.e., + only the messages whose 'color' properties are of 'red' values can be received by its consumers. Those that don't match + the filter will be dropped by the queue and therefore will never be delivered to any of its consumers.</p> + + <p>In the example code, five messages with different 'color' property values are sent to queue 'selectorQueue'. One consumer + is created to receive messages from the queue. Of the five sent messages, two are of 'red' color properties, one is 'blue', + one is 'green' and one has not the 'color' property at all. The result is that the consumer only gets the two 'red' messages.</p> + + </body> +</html> http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/21bf4406/examples/broker-features/standard/static-selector/src/main/java/org/apache/activemq/artemis/jms/example/StaticSelectorExample.java ---------------------------------------------------------------------- diff --git a/examples/broker-features/standard/static-selector/src/main/java/org/apache/activemq/artemis/jms/example/StaticSelectorExample.java b/examples/broker-features/standard/static-selector/src/main/java/org/apache/activemq/artemis/jms/example/StaticSelectorExample.java new file mode 100644 index 0000000..08f9db9 --- /dev/null +++ b/examples/broker-features/standard/static-selector/src/main/java/org/apache/activemq/artemis/jms/example/StaticSelectorExample.java @@ -0,0 +1,137 @@ +/* + * 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.JMSException; +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 javax.naming.InitialContext; +import java.util.concurrent.atomic.AtomicBoolean; + +/** + * A simple JMS example that shows how static message selectors work. + */ +public class StaticSelectorExample { + + public static void main(final String[] args) throws Exception { + AtomicBoolean result = new AtomicBoolean(true); + Connection connection = null; + InitialContext initialContext = null; + try { + // Step 1. Create an initial context to perform the JNDI lookup. + initialContext = new InitialContext(); + + // Step 2. look-up the JMS queue object from JNDI, this is the queue that has filter configured with it. + Queue queue = (Queue) initialContext.lookup("queue/exampleQueue"); + + // Step 3. look-up the JMS connection factory object from JNDI + ConnectionFactory cf = (ConnectionFactory) initialContext.lookup("ConnectionFactory"); + + // Step 4. Create a JMS Connection + connection = cf.createConnection(); + + // Step 5. Start the connection + connection.start(); + + // Step 6. Create a JMS Session + Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE); + Session producerSession = connection.createSession(false, Session.AUTO_ACKNOWLEDGE); + + // Step 7. Create a JMS Message Producer + MessageProducer producer = producerSession.createProducer(queue); + + // Step 8. Create a JMS Message Consumer that receives 'red' messages + MessageConsumer redConsumer = session.createConsumer(queue); + redConsumer.setMessageListener(new SimpleMessageListener("red", result)); + + // Step 9. Create five messages with different 'color' properties + TextMessage redMessage1 = session.createTextMessage("Red-1"); + redMessage1.setStringProperty("color", "red"); + TextMessage redMessage2 = session.createTextMessage("Red-2"); + redMessage2.setStringProperty("color", "red"); + TextMessage greenMessage = session.createTextMessage("Green"); + greenMessage.setStringProperty("color", "green"); + TextMessage blueMessage = session.createTextMessage("Blue"); + blueMessage.setStringProperty("color", "blue"); + TextMessage normalMessage = session.createTextMessage("No color"); + + // Step 10. Send the Messages + producer.send(redMessage1); + System.out.println("Message sent: " + redMessage1.getText()); + producer.send(greenMessage); + System.out.println("Message sent: " + greenMessage.getText()); + producer.send(blueMessage); + System.out.println("Message sent: " + blueMessage.getText()); + producer.send(redMessage2); + System.out.println("Message sent: " + redMessage2.getText()); + producer.send(normalMessage); + System.out.println("Message sent: " + normalMessage.getText()); + + // Step 11. Waiting for the message listener to check the received messages. + Thread.sleep(5000); + + if (!result.get()) + throw new IllegalStateException(); + } + finally { + // Step 12. Be sure to close our JMS resources! + if (initialContext != null) { + initialContext.close(); + } + if (connection != null) { + connection.close(); + } + } + } +} + +class SimpleMessageListener implements MessageListener { + + private final String name; + private AtomicBoolean result; + + public SimpleMessageListener(final String listener, AtomicBoolean result) { + name = listener; + this.result = result; + } + + public void onMessage(final Message msg) { + TextMessage textMessage = (TextMessage) msg; + try { + String colorProp = msg.getStringProperty("color"); + System.out.println("Receiver " + name + + " receives message [" + + textMessage.getText() + + "] with color property: " + + colorProp); + if (colorProp != null && !colorProp.equals(name)) { + result.set(false); + } + } + catch (JMSException e) { + e.printStackTrace(); + result.set(false); + } + } +} http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/21bf4406/examples/broker-features/standard/static-selector/src/main/resources/activemq/server0/artemis-roles.properties ---------------------------------------------------------------------- diff --git a/examples/broker-features/standard/static-selector/src/main/resources/activemq/server0/artemis-roles.properties b/examples/broker-features/standard/static-selector/src/main/resources/activemq/server0/artemis-roles.properties new file mode 100644 index 0000000..4e2d44c --- /dev/null +++ b/examples/broker-features/standard/static-selector/src/main/resources/activemq/server0/artemis-roles.properties @@ -0,0 +1,17 @@ +## --------------------------------------------------------------------------- +## 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. +## --------------------------------------------------------------------------- +guest=guest \ No newline at end of file http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/21bf4406/examples/broker-features/standard/static-selector/src/main/resources/activemq/server0/artemis-users.properties ---------------------------------------------------------------------- diff --git a/examples/broker-features/standard/static-selector/src/main/resources/activemq/server0/artemis-users.properties b/examples/broker-features/standard/static-selector/src/main/resources/activemq/server0/artemis-users.properties new file mode 100644 index 0000000..4e2d44c --- /dev/null +++ b/examples/broker-features/standard/static-selector/src/main/resources/activemq/server0/artemis-users.properties @@ -0,0 +1,17 @@ +## --------------------------------------------------------------------------- +## 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. +## --------------------------------------------------------------------------- +guest=guest \ No newline at end of file http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/21bf4406/examples/broker-features/standard/static-selector/src/main/resources/activemq/server0/broker.xml ---------------------------------------------------------------------- diff --git a/examples/broker-features/standard/static-selector/src/main/resources/activemq/server0/broker.xml b/examples/broker-features/standard/static-selector/src/main/resources/activemq/server0/broker.xml new file mode 100644 index 0000000..ca09b3b --- /dev/null +++ b/examples/broker-features/standard/static-selector/src/main/resources/activemq/server0/broker.xml @@ -0,0 +1,67 @@ +<?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. +--> + +<configuration xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xmlns="urn:activemq" + xsi:schemaLocation="urn:activemq /schema/artemis-server.xsd"> + + <jms xmlns="urn:activemq:jms"> + <!--the queue used by the example--> + <queue name="exampleQueue"/> + </jms> + + <core xmlns="urn:activemq:core"> + + <bindings-directory>${data.dir}/server0/data/messaging/bindings</bindings-directory> + + <journal-directory>${data.dir}/server0/data/messaging/journal</journal-directory> + + <large-messages-directory>${data.dir}/server0/data/messaging/largemessages</large-messages-directory> + + <paging-directory>${data.dir}/server0/data/messaging/paging</paging-directory> + + <!-- Acceptors --> + <acceptors> + <acceptor name="netty-acceptor">tcp://localhost:61616</acceptor> + </acceptors> + + <queues> + <queue name="jms.queue.exampleQueue"> + <address>jms.queue.exampleQueue</address> + <filter string="color='red'"/> + </queue> + </queues> + + <!-- Other config --> + + <security-settings> + <!--security for example queue--> + <security-setting match="jms.queue.exampleQueue"> + <permission type="createDurableQueue" roles="guest"/> + <permission type="deleteDurableQueue" roles="guest"/> + <permission type="createNonDurableQueue" roles="guest"/> + <permission type="deleteNonDurableQueue" roles="guest"/> + <permission type="consume" roles="guest"/> + <permission type="send" roles="guest"/> + </security-setting> + </security-settings> + + </core> +</configuration> http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/21bf4406/examples/broker-features/standard/static-selector/src/main/resources/jndi.properties ---------------------------------------------------------------------- diff --git a/examples/broker-features/standard/static-selector/src/main/resources/jndi.properties b/examples/broker-features/standard/static-selector/src/main/resources/jndi.properties new file mode 100644 index 0000000..93537c4 --- /dev/null +++ b/examples/broker-features/standard/static-selector/src/main/resources/jndi.properties @@ -0,0 +1,20 @@ +# 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 +queue.queue/exampleQueue=exampleQueue http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/21bf4406/examples/broker-features/standard/temp-queue/pom.xml ---------------------------------------------------------------------- diff --git a/examples/broker-features/standard/temp-queue/pom.xml b/examples/broker-features/standard/temp-queue/pom.xml new file mode 100644 index 0000000..624d8ed --- /dev/null +++ b/examples/broker-features/standard/temp-queue/pom.xml @@ -0,0 +1,109 @@ +<?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>1.0.1-SNAPSHOT</version> + </parent> + + <artifactId>temp-queue</artifactId> + <packaging>jar</packaging> + <name>ActiveMQ Artemis JMS Temporary Queue Example</name> + + <properties> + <activemq.basedir>${project.basedir}/../../../..</activemq.basedir> + </properties> + + <dependencies> + <dependency> + <groupId>org.apache.activemq</groupId> + <artifactId>artemis-jms-client</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>start</id> + <goals> + <goal>cli</goal> + </goals> + <configuration> + <ignore>${noServer}</ignore> + <spawn>true</spawn> + <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.TemporaryQueueExample</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.broker</groupId> + <artifactId>temp-queue</artifactId> + <version>${project.version}</version> + </dependency> + </dependencies> + </plugin> + </plugins> + </build> + +</project> http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/21bf4406/examples/broker-features/standard/temp-queue/readme.html ---------------------------------------------------------------------- diff --git a/examples/broker-features/standard/temp-queue/readme.html b/examples/broker-features/standard/temp-queue/readme.html new file mode 100644 index 0000000..4b4d5c8 --- /dev/null +++ b/examples/broker-features/standard/temp-queue/readme.html @@ -0,0 +1,40 @@ +<!-- +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 Temporary 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 Temporary Queue 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>This example shows you how to use a TemporaryQueue with ActiveMQ Artemis. First a temporary queue is created to send and receive a message and then deleted. + Then another temporary queue is created and used after its connection is closed to illustrate its scope.</p> + <p>A TemporaryQueue is a JMS queue that exists only within the lifetime of its connection. It is often used in request-reply + type messaging where the reply is sent through a temporary destination. The temporary queue is often created as + a server resource, so after using, the user should call delete() method to release the resources. + Please consult the JMS 1.1 specification for full details.</p> + </body> +</html>
