diff --git a/examples/jms/embedded-simple/readme.html b/examples/jms/embedded-simple/readme.html index 7a4104c20f..bf412588d6 100644 --- a/examples/jms/embedded-simple/readme.html +++ b/examples/jms/embedded-simple/readme.html @@ -34,38 +34,63 @@ under the License.
  1. Create ActiveMQ core configuration files and make sure they are within your classpath. By default, ActiveMQ - expects the classnames to be "activemq-configuration.xml", "activemq-jms.xml", and "activemq-users.xml".
  2. -
  3. Create and start ActiveMQ JMS server
  4. + expects the configuration file name to be "activemq-configuration.xml". +
  5. Create an embedded ActiveMQ JMS server
  6. -            EmbeddedJMS jmsServer = new EmbeddedJMS();
    -            jmsServer.start();
    +            EmbeddedJMS jmsServer = new EmbeddedJMS();
              
    - + +
  7. Setup security configurations
  8. +
    +            SecurityConfiguration securityConfig = new SecurityConfiguration();
    +            securityConfig.addUser("guest", "guest");
    +            securityConfig.addRole("guest", "guest");
    +            securityConfig.setDefaultUser("guest");
    +            jmsServer.setSecurityManager(new ActiveMQSecurityManagerImpl(securityConfig));
    +         
    + +
  9. Start the embedded ActiveMQ JMS server
  10. +
    +            jmsServer.start()
    +         
    + +
  11. Create JMS resources (connection factory and queue) for the example
  12. +
    +            JMSServerManager jmsServerManager = jmsServer.getJMSServerManager();
    +            List connectors = new ArrayList();
    +            connectors.add("in-vm");
    +            jmsServerManager.createConnectionFactory("ConnectionFactory", false, JMSFactoryType.CF, connectors, "ConnectionFactory");
    +            jmsServerManager.createQueue(false, "exampleQueue", null, false, "queue/exampleQueue");
    +         
    +

    At this point the JMS server is started and any JMS clients can look up JMS resources from the JNDI to send/receive messages from the server. To keep the example simple, we will send and receive a JMS message from the same JVM used to run the JMS server.

  13. Lookup JMS resources defined in the configuration
  14. -            ConnectionFactory cf = (ConnectionFactory)context.lookup("/cf");
    -            Queue queue = (Queue)context.lookup("/queue/queue1");
    +            ConnectionFactory cf = (ConnectionFactory)jmsServer.lookup("ConnectionFactory");
    +            Queue queue = (Queue)jmsServer.lookup("queue/exampleQueue");
              
  15. Send and receive a message using JMS API
  16. -

    See the Queue Example for detailed steps to send and receive a JMS message

    +

    See the Queue Example for detailed steps to send and receive a JMS message

    Finally, we stop the JMS server and its associated resources.

    - + +
  17. Close the connection
  18. +
    +            if (connection != null)
    +            {
    +               connection.close();
    +            }
    +         
    +
  19. Stop the JMS server
  20.              jmsServer.stop();
              
    -
  21. Stop the JNDI server
  22. -
    -            naming.stop();
    -            jndiServer.stop();
    -         
diff --git a/examples/jms/embedded-simple/src/main/java/org/apache/activemq/jms/example/EmbeddedExample.java b/examples/jms/embedded-simple/src/main/java/org/apache/activemq/jms/example/EmbeddedExample.java index 008a6046db..838c3fd6bb 100644 --- a/examples/jms/embedded-simple/src/main/java/org/apache/activemq/jms/example/EmbeddedExample.java +++ b/examples/jms/embedded-simple/src/main/java/org/apache/activemq/jms/example/EmbeddedExample.java @@ -29,8 +29,10 @@ import javax.jms.Session; import javax.jms.TextMessage; import org.apache.activemq.common.example.ActiveMQExample; +import org.apache.activemq.core.config.impl.SecurityConfiguration; import org.apache.activemq.jms.server.embedded.EmbeddedJMS; import org.apache.activemq.jms.server.JMSServerManager; +import org.apache.activemq.spi.core.security.ActiveMQSecurityManagerImpl; import org.apache.activemq.api.jms.JMSFactoryType; /** @@ -50,6 +52,13 @@ public class EmbeddedExample extends ActiveMQExample try { EmbeddedJMS jmsServer = new EmbeddedJMS(); + + SecurityConfiguration securityConfig = new SecurityConfiguration(); + securityConfig.addUser("guest", "guest"); + securityConfig.addRole("guest", "guest"); + securityConfig.setDefaultUser("guest"); + jmsServer.setSecurityManager(new ActiveMQSecurityManagerImpl(securityConfig)); + jmsServer.start(); System.out.println("Started Embedded JMS Server"); @@ -57,6 +66,8 @@ public class EmbeddedExample extends ActiveMQExample List connectors = new ArrayList(); connectors.add("in-vm"); jmsServerManager.createConnectionFactory("ConnectionFactory", false, JMSFactoryType.CF, connectors, "ConnectionFactory"); + jmsServerManager.createQueue(false, "exampleQueue", null, false, "queue/exampleQueue"); + ConnectionFactory cf = (ConnectionFactory)jmsServer.lookup("ConnectionFactory"); Queue queue = (Queue)jmsServer.lookup("queue/exampleQueue"); diff --git a/examples/jms/embedded-simple/src/main/resources/activemq-configuration.xml b/examples/jms/embedded-simple/src/main/resources/activemq-configuration.xml index fdc8811736..68cca46ace 100644 --- a/examples/jms/embedded-simple/src/main/resources/activemq-configuration.xml +++ b/examples/jms/embedded-simple/src/main/resources/activemq-configuration.xml @@ -22,15 +22,14 @@ under the License. xmlns="urn:activemq" xsi:schemaLocation="urn:activemq /schema/activemq-server.xsd"> - - - - - false + + vm://0 + + vm://0 diff --git a/examples/jms/embedded-simple/src/main/resources/activemq-roles.properties b/examples/jms/embedded-simple/src/main/resources/activemq-roles.properties deleted file mode 100644 index 4e2d44cec4..0000000000 --- a/examples/jms/embedded-simple/src/main/resources/activemq-roles.properties +++ /dev/null @@ -1,17 +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. -## --------------------------------------------------------------------------- -guest=guest \ No newline at end of file diff --git a/examples/jms/embedded-simple/src/main/resources/activemq-users.properties b/examples/jms/embedded-simple/src/main/resources/activemq-users.properties deleted file mode 100644 index 4e2d44cec4..0000000000 --- a/examples/jms/embedded-simple/src/main/resources/activemq-users.properties +++ /dev/null @@ -1,17 +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. -## --------------------------------------------------------------------------- -guest=guest \ No newline at end of file