Return-Path:
This example shows how to configure and use security using ActiveMQ Artemis. With security properly configured, ActiveMQ Artemis can restrict client access to its resources, including
- connection creation, message sending/receiving, etc. This is done by configuring users and roles as well as permissions in
- the configuration files. ActiveMQ Artemis supports wild-card security configuration. This feature makes security configuration very
- flexible and enables fine-grained control over permissions in an efficient way. For a full description of how to configure security with ActiveMQ Artemis, please consult the user
- manual. This example demonstrates how to configure users/roles, how to configure topics with proper permissions using wild-card
- expressions, and how they take effects in a simple program. First we need to configure users with roles. Users and Roles are configured in
- Each user has three properties available: user name, password, and roles it belongs to. It should be noted that
- a user can belong to more than one role. In the above configuration, all users belong to role 'user'. User 'andrew' also
- belongs to role 'europe-user', user 'frank' also belongs to 'us-user' and 'news-user' and user 'sam' also belongs to 'news-user'.
-
- User name and password consists of a valid account that can be used to establish connections to a ActiveMQ Artemis server, while
- roles are used in controlling the access privileges against ActiveMQ Artemis topics and queues. You can achieve this control by
- configuring proper permissions in Permissions can be defined on any group of queues, by using a wildcard. You can easily specify
- wildcards to apply certain permissions to a set of matching queues and topics. In the above configuration
- we have created four sets of permissions, each set matches against a special group of targets, indicated by wild-card match attributes. You can provide a very broad permission control as a default and then add more strict control
- over specific addresses. By the above we define the following access rules: To illustrate the effect of permissions, three topics are deployed. Topic 'genericTopic' matches 'jms.topic.#' wild-card, topic 'news.europe.europeTopic' matches
- jms.topic.news.europe.#' wild-cards, and topic 'news.us.usTopic' matches 'jms.topic.news.us.#'. With ActiveMQ Artemis, the security manager is also configurable. You can use JAASSecurityManager or JBossASSecurityManager based on you need. Please
- check out the activemq-beans.xml for how to do. In this example we just use the basic ActiveMQSecurityManagerImpl which reads users/roles/passwords from the xml
- file To run the example, simply type 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 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.
-
- For more information on Asynchronous Send Acknowledgements please see the user manual To run the example, simply type 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. YOU MUST DOWNLOAD THE SPRING LIBRARIES TO RUN THIS EXAMPLE!!! You must also modify the build.xml file to include the spring jars. You'll see the placeholder that is already there. To run the example, simply type This example shows you how to configure SSL with ActiveMQ Artemis to send and receive message. 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:
- JMS Security Example
-
- To run the example, simply type mvn verify from this directory,
-
-
-
or mvn -PnoServer verify if you want to start and create the server manually.activemq-users.xml
. This example has four users
- configured as below
-
-
-
- <user name="bill" password="activemq">
- <role name="user"/>
- </user>
-
- <user name="andrew" password="activemq1">
- <role name="europe-user"/>
- <role name="user"/>
- </user>
-
- <user name="frank" password="activemq2">
- <role name="us-user"/>
- <role name="news-user"/>
- <role name="user"/>
- </user>
-
- <user name="sam" password="activemq3">
- <role name="news-user"/>
- <role name="user"/>
- </user>
-
- broker.xml
, like the following
-
-
-
- <security-settings>
- <!-- any user can have full control of generic topics -->
- <security-setting match="jms.topic.#">
- <permission type="createDurableQueue" roles="user"/>
- <permission type="deleteDurableQueue" roles="user"/>
- <permission type="createNonDurableQueue" roles="user"/>
- <permission type="deleteNonDurableQueue" roles="user"/>
- <permission type="send" roles="user"/>
- <permission type="consume" roles="user"/>
- </security-setting>
-
- <security-setting match="jms.topic.news.europe.#">
- <permission type="createDurableQueue" roles="user"/>
- <permission type="deleteDurableQueue" roles="user"/>
- <permission type="createNonDurableQueue" roles="user"/>
- <permission type="deleteNonDurableQueue" roles="user"/>
- <permission type="send" roles="europe-user"/>
- <permission type="consume" roles="news-user"/>
- </security-setting>
-
- <security-setting match="jms.topic.news.us.#">
- <permission type="createDurableQueue" roles="user"/>
- <permission type="deleteDurableQueue" roles="user"/>
- <permission type="createNonDurableQueue" roles="user"/>
- <permission type="deleteNonDurableQueue" roles="user"/>
- <permission type="send" roles="us-user"/>
- <permission type="consume" roles="news-user"/>
- </security-setting>
- </security-settings>
-
activemq-users.xml
.
-
-
- Example step-by-step
- mvn verify -Pexample
from this directory
-
-
-
http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/6b17d966/examples/broker-features/standard/security/src/main/java/org/apache/activemq/artemis/jms/example/SecurityExample.java
----------------------------------------------------------------------
diff --git a/examples/broker-features/standard/security/src/main/java/org/apache/activemq/artemis/jms/example/SecurityExample.java b/examples/broker-features/standard/security/src/main/java/org/apache/activemq/artemis/jms/example/SecurityExample.java
deleted file mode 100644
index 88fd1da..0000000
--- a/examples/broker-features/standard/security/src/main/java/org/apache/activemq/artemis/jms/example/SecurityExample.java
+++ /dev/null
@@ -1,282 +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 javax.jms.Connection;
-import javax.jms.ConnectionFactory;
-import javax.jms.JMSException;
-import javax.jms.JMSSecurityException;
-import javax.jms.MessageConsumer;
-import javax.jms.MessageProducer;
-import javax.jms.Session;
-import javax.jms.TextMessage;
-import javax.jms.Topic;
-import javax.naming.InitialContext;
-
-public class SecurityExample {
-
- public static void main(final String[] args) throws Exception {
- boolean result = true;
- Connection failConnection = null;
- Connection billConnection = null;
- Connection andrewConnection = null;
- Connection frankConnection = null;
- Connection samConnection = null;
-
- InitialContext initialContext = null;
- try {
- // /Step 1. Create an initial context to perform the JNDI lookup.
- initialContext = new InitialContext();
-
- // Step 2. perform lookup on the topics
- Topic genericTopic = (Topic) initialContext.lookup("topic/genericTopic");
- Topic europeTopic = (Topic) initialContext.lookup("topic/europeTopic");
- Topic usTopic = (Topic) initialContext.lookup("topic/usTopic");
-
- // Step 3. perform a lookup on the Connection Factory
- ConnectionFactory cf = (ConnectionFactory) initialContext.lookup("ConnectionFactory");
-
- // Step 4. Try to create a JMS Connection without user/password. It will fail.
- try {
- failConnection = cf.createConnection();
- result = false;
- }
- catch (JMSSecurityException e) {
- System.out.println("Default user cannot get a connection. Details: " + e.getMessage());
- }
-
- // Step 5. bill tries to make a connection using wrong password
- billConnection = null;
- try {
- billConnection = createConnection("bill", "activemq1", cf);
- result = false;
- }
- catch (JMSException e) {
- System.out.println("User bill failed to connect. Details: " + e.getMessage());
- }
-
- // Step 6. bill makes a good connection.
- billConnection = createConnection("bill", "activemq", cf);
- billConnection.start();
-
- // Step 7. andrew makes a good connection.
- andrewConnection = createConnection("andrew", "activemq1", cf);
- andrewConnection.start();
-
- // Step 8. frank makes a good connection.
- frankConnection = createConnection("frank", "activemq2", cf);
- frankConnection.start();
-
- // Step 9. sam makes a good connection.
- samConnection = createConnection("sam", "activemq3", cf);
- samConnection.start();
-
- // Step 10. Check every user can publish/subscribe genericTopics.
- System.out.println("------------------------Checking permissions on " + genericTopic + "----------------");
- checkUserSendAndReceive(genericTopic, billConnection, "bill");
- checkUserSendAndReceive(genericTopic, andrewConnection, "andrew");
- checkUserSendAndReceive(genericTopic, frankConnection, "frank");
- checkUserSendAndReceive(genericTopic, samConnection, "sam");
- System.out.println("-------------------------------------------------------------------------------------");
-
- System.out.println("------------------------Checking permissions on " + europeTopic + "----------------");
-
- // Step 11. Check permissions on news.europe.europeTopic for bill: can't send and can't receive
- checkUserNoSendNoReceive(europeTopic, billConnection, "bill");
-
- // Step 12. Check permissions on news.europe.europeTopic for andrew: can send but can't receive
- checkUserSendNoReceive(europeTopic, andrewConnection, "andrew", frankConnection);
-
- // Step 13. Check permissions on news.europe.europeTopic for frank: can't send but can receive
- checkUserReceiveNoSend(europeTopic, frankConnection, "frank", andrewConnection);
-
- // Step 14. Check permissions on news.europe.europeTopic for sam: can't send but can receive
- checkUserReceiveNoSend(europeTopic, samConnection, "sam", andrewConnection);
- System.out.println("-------------------------------------------------------------------------------------");
-
- System.out.println("------------------------Checking permissions on " + usTopic + "----------------");
-
- // Step 15. Check permissions on news.us.usTopic for bill: can't send and can't receive
- checkUserNoSendNoReceive(usTopic, billConnection, "bill");
-
- // Step 16. Check permissions on news.us.usTopic for andrew: can't send and can't receive
- checkUserNoSendNoReceive(usTopic, andrewConnection, "andrew");
-
- // Step 17. Check permissions on news.us.usTopic for frank: can both send and receive
- checkUserSendAndReceive(usTopic, frankConnection, "frank");
-
- // Step 18. Check permissions on news.us.usTopic for sam: can't send but can receive
- checkUserReceiveNoSend(usTopic, samConnection, "sam", frankConnection);
- System.out.println("-------------------------------------------------------------------------------------");
- }
- finally {
- // Step 19. Be sure to close our JMS resources!
- if (failConnection != null) {
- failConnection.close();
- }
- if (billConnection != null) {
- billConnection.close();
- }
- if (andrewConnection != null) {
- andrewConnection.close();
- }
- if (frankConnection != null) {
- frankConnection.close();
- }
- if (samConnection != null) {
- samConnection.close();
- }
-
- // Also the initialContext
- if (initialContext != null) {
- initialContext.close();
- }
- }
- }
-
- // Check the user can receive message but cannot send message.
- private static void checkUserReceiveNoSend(final Topic topic,
- final Connection connection,
- final String user,
- final Connection sendingConn) throws JMSException {
- Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
- MessageProducer producer = session.createProducer(topic);
- MessageConsumer consumer = session.createConsumer(topic);
- TextMessage msg = session.createTextMessage("hello-world-1");
-
- try {
- producer.send(msg);
- throw new IllegalStateException("Security setting is broken! User " + user +
- " can send message [" +
- msg.getText() +
- "] to topic " +
- topic);
- }
- catch (JMSException e) {
- System.out.println("User " + user + " cannot send message [" + msg.getText() + "] to topic: " + topic);
- }
-
- // Now send a good message
- Session session1 = sendingConn.createSession(false, Session.AUTO_ACKNOWLEDGE);
- producer = session1.createProducer(topic);
- producer.send(msg);
-
- TextMessage receivedMsg = (TextMessage) consumer.receive(2000);
-
- if (receivedMsg != null) {
- System.out.println("User " + user + " can receive message [" + receivedMsg.getText() + "] from topic " + topic);
- }
- else {
- throw new IllegalStateException("Security setting is broken! User " + user + " cannot receive message from topic " + topic);
- }
-
- session1.close();
- session.close();
- }
-
- // Check the user can send message but cannot receive message
- private static void checkUserSendNoReceive(final Topic topic,
- final Connection connection,
- final String user,
- final Connection receivingConn) throws JMSException {
- Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
- MessageProducer producer = session.createProducer(topic);
- try {
- session.createConsumer(topic);
- }
- catch (JMSException e) {
- System.out.println("User " + user + " cannot receive any message from topic " + topic);
- }
-
- Session session1 = receivingConn.createSession(false, Session.AUTO_ACKNOWLEDGE);
- MessageConsumer goodConsumer = session1.createConsumer(topic);
-
- TextMessage msg = session.createTextMessage("hello-world-2");
- producer.send(msg);
-
- TextMessage receivedMsg = (TextMessage) goodConsumer.receive(2000);
- if (receivedMsg != null) {
- System.out.println("User " + user + " can send message [" + receivedMsg.getText() + "] to topic " + topic);
- }
- else {
- throw new IllegalStateException("Security setting is broken! User " + user +
- " cannot send message [" +
- msg.getText() +
- "] to topic " +
- topic);
- }
-
- session.close();
- session1.close();
- }
-
- // Check the user has neither send nor receive permission on topic
- private static void checkUserNoSendNoReceive(final Topic topic,
- final Connection connection,
- final String user) throws JMSException {
- Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
- MessageProducer producer = session.createProducer(topic);
-
- try {
- session.createConsumer(topic);
- }
- catch (JMSException e) {
- System.out.println("User " + user + " cannot create consumer on topic " + topic);
- }
-
- TextMessage msg = session.createTextMessage("hello-world-3");
- try {
- producer.send(msg);
- throw new IllegalStateException("Security setting is broken! User " + user +
- " can send message [" +
- msg.getText() +
- "] to topic " +
- topic);
- }
- catch (JMSException e) {
- System.out.println("User " + user + " cannot send message [" + msg.getText() + "] to topic: " + topic);
- }
-
- session.close();
- }
-
- // Check the user connection has both send and receive permissions on the topic
- private static void checkUserSendAndReceive(final Topic topic,
- final Connection connection,
- final String user) throws JMSException {
- Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
- TextMessage msg = session.createTextMessage("hello-world-4");
- MessageProducer producer = session.createProducer(topic);
- MessageConsumer consumer = session.createConsumer(topic);
- producer.send(msg);
- TextMessage receivedMsg = (TextMessage) consumer.receive(5000);
- if (receivedMsg != null) {
- System.out.println("User " + user + " can send message: [" + msg.getText() + "] to topic: " + topic);
- System.out.println("User " + user + " can receive message: [" + msg.getText() + "] from topic: " + topic);
- }
- else {
- throw new IllegalStateException("Error! User " + user + " cannot receive the message! ");
- }
- session.close();
- }
-
- private static Connection createConnection(final String username,
- final String password,
- final ConnectionFactory cf) throws JMSException {
- return cf.createConnection(username, password);
- }
-}
http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/6b17d966/examples/broker-features/standard/security/src/main/resources/activemq/server0/artemis-roles.properties
----------------------------------------------------------------------
diff --git a/examples/broker-features/standard/security/src/main/resources/activemq/server0/artemis-roles.properties b/examples/broker-features/standard/security/src/main/resources/activemq/server0/artemis-roles.properties
deleted file mode 100644
index 09b3f5d..0000000
--- a/examples/broker-features/standard/security/src/main/resources/activemq/server0/artemis-roles.properties
+++ /dev/null
@@ -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.
-## ---------------------------------------------------------------------------
-bill=user
-andrew=europe-user,user
-frank=us-user,news-user,user
-sam=news-user,user
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/6b17d966/examples/broker-features/standard/security/src/main/resources/activemq/server0/artemis-users.properties
----------------------------------------------------------------------
diff --git a/examples/broker-features/standard/security/src/main/resources/activemq/server0/artemis-users.properties b/examples/broker-features/standard/security/src/main/resources/activemq/server0/artemis-users.properties
deleted file mode 100644
index 0a206c6..0000000
--- a/examples/broker-features/standard/security/src/main/resources/activemq/server0/artemis-users.properties
+++ /dev/null
@@ -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.
-## ---------------------------------------------------------------------------
-bill=activemq
-andrew=activemq1
-frank=activemq2
-sam=activemq3
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/6b17d966/examples/broker-features/standard/security/src/main/resources/activemq/server0/broker.xml
----------------------------------------------------------------------
diff --git a/examples/broker-features/standard/security/src/main/resources/activemq/server0/broker.xml b/examples/broker-features/standard/security/src/main/resources/activemq/server0/broker.xml
deleted file mode 100644
index 6a8b82b..0000000
--- a/examples/broker-features/standard/security/src/main/resources/activemq/server0/broker.xml
+++ /dev/null
@@ -1,81 +0,0 @@
-
-
-
-client-jndi.properties
file in the directory ../common/config
-
-
-
- InitialContext initialContext = getContext(0);
-
-
-
-
-
- Topic genericTopic = (Topic) initialContext.lookup("/topic/genericTopic");
- Topic europeTopic = (Topic) initialContext.lookup("/topic/europeTopic");
- Topic usTopic = (Topic) initialContext.lookup("/topic/usTopic");
-
-
-
-
-
- ConnectionFactory cf = (ConnectionFactory) initialContext.lookup("/ConnectionFactory");
-
-
-
-
-
- try
- {
- cf.createConnection();
- result = false;
- }
- catch (JMSSecurityException e)
- {
- System.out.println("Default user cannot get a connection. Details: " + e.getMessage());
- }
-
-
-
-
-
- billConnection = null;
- try
- {
- billConnection = createConnection("bill", "activemq1", cf);
- result = false;
- }
- catch (JMSException e)
- {
- System.out.println("User bill failed to connect. Details: " + e.getMessage());
- }
-
-
-
-
-
- billConnection = createConnection("bill", "activemq", cf);
- billConnection.start();
-
-
-
-
-
- andrewConnection = createConnection("andrew", "activemq1", cf);
- andrewConnection.start();
-
-
-
-
-
- frankConnection = createConnection("frank", "activemq2", cf);
- frankConnection.start();
-
-
-
-
-
- samConnection = createConnection("sam", "activemq3", cf);
- samConnection.start();
-
-
-
-
-
- checkUserSendAndReceive(genericTopic, billConnection, "bill");
- checkUserSendAndReceive(genericTopic, andrewConnection, "andrew");
- checkUserSendAndReceive(genericTopic, frankConnection, "frank");
- checkUserSendAndReceive(genericTopic, samConnection, "sam");
-
-
-
-
-
- checkUserNoSendNoReceive(europeTopic, billConnection, "bill", andrewConnection, frankConnection);
-
-
-
-
-
- checkUserSendNoReceive(europeTopic, andrewConnection, "andrew", frankConnection);
-
-
-
-
-
- checkUserReceiveNoSend(europeTopic, frankConnection, "frank", andrewConnection);
-
-
-
-
-
- checkUserReceiveNoSend(europeTopic, samConnection, "sam", andrewConnection);
-
-
-
-
-
- checkUserNoSendNoReceive(usTopic, billConnection, "bill");
-
-
-
-
-
- checkUserNoSendNoReceive(usTopic, andrewConnection, "andrew");
-
-
-
-
-
- checkUserSendAndReceive(usTopic, frankConnection, "frank");
-
-
-
-
-
- checkUserReceiveNoSend(usTopic, samConnection, "sam", frankConnection);
-
- finally
block. Closing a JMS connection will automatically close all of its sessions, consumers, producer and browser objects
-
-
- finally
- {
- if (billConnection != null)
- {
- billConnection.close();
- }
- if (andrewConnection != null)
- {
- andrewConnection.close();
- }
- if (frankConnection != null)
- {
- frankConnection.close();
- }
- if (samConnection != null)
- {
- samConnection.close();
- }
-
- // Also the initialContext
- if (initialContext != null)
- {
- initialContext.close();
- }
- }
-
- Asynchronous Send Acknowledgements Example
-
- To run the example, simply type mvn verify from this directory,
-
-
-
or mvn -PnoServer verify if you want to start and create the server manually.Example step-by-step
- mvn verify -Pexample
from this directory
-
-
-
http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/6b17d966/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
deleted file mode 100644
index 578d198..0000000
--- a/examples/broker-features/standard/send-acknowledgements/src/main/java/org/apache/activemq/artemis/jms/example/SendAcknowledgementsExample.java
+++ /dev/null
@@ -1,104 +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 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/6b17d966/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
deleted file mode 100644
index 8421f25..0000000
--- a/examples/broker-features/standard/send-acknowledgements/src/main/resources/jndi.properties
+++ /dev/null
@@ -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
http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/6b17d966/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
deleted file mode 100644
index 238a550..0000000
--- a/examples/broker-features/standard/spring-integration/pom.xml
+++ /dev/null
@@ -1,82 +0,0 @@
-
-
-
-client-jndi.properties
file in the directory ../common/config
-
-
- InitialContext initialContext = getContext();
-
-
-
- Queue queue = (Queue) initialContext.lookup("/queue/exampleQueue");
-
-
-
- ConnectionFactory cf = (ConnectionFactory) initialContext.lookup("/ConnectionFactory");
-
-
-
- connection = cf.createConnection();
-
-
-
-
- class MySendAcknowledgementsHandler implements SendAcknowledgementHandler
- {
- int count = 0;
-
- public void sendAcknowledged(final Message message)
- {
- System.out.println("Received send acknowledgement for message " + count++);
- }
- }
-
-
-
-
- Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
-
-
-
-
- ClientSession coreSession = ((ActiveMQSession)session).getCoreSession();
-
- coreSession.setSendAcknowledgementHandler(new MySendAcknowledgementsHandler());
-
-
-
-
-
-
- MessageProducer producer = session.createProducer(queue);
-
- producer.setDeliveryMode(DeliveryMode.NON_PERSISTENT);
-
-
-
-
-
-
- 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
block. Closing a JMS connection will automatically close all of its sessions, consumers, producer and browser objects
-
-
-
-
- finally
- {
- if (initialContext != null)
- {
- initialContext.close();
- }
- if (connection != null)
- {
- connection.close();
- }
- }
- ActiveMQ Artemis Spring Example
-
- Example step-by-step
- mvn verify -Pexample
from this directoryJMS SSL Example
-
- To run the example, simply type mvn verify from this directory,
-
-
-
or mvn -PnoServer verify if you want to start and create the server manually.
-
-
- <!-- 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>
-
-
-
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 purpose1.
- - http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/6b17d966/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 deleted file mode 100644 index 27bf739..0000000 --- a/examples/broker-features/standard/ssl-enabled/src/main/java/org/apache/activemq/artemis/jms/example/SSLExample.java +++ /dev/null @@ -1,86 +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 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(); - } - } - } -}