Update embedded docs/example

This commit is contained in:
jbertram 2016-06-06 17:00:00 -05:00
parent 50d83fb63d
commit 1e28b3e7e7
2 changed files with 46 additions and 40 deletions

View File

@ -72,10 +72,9 @@ properties. See the javadocs for this class for more details.
## JMS API ## JMS API
JMS embedding is simple as well. This example requires that you have JMS embedding is simple as well. This example requires that you have
defined the config files `broker.xml`, defined the config file `broker.xml`. Let's also assume that a queue
`activemq-jms.xml`, and a `activemq-users.xml` if you have security and connection factory has been defined in the `broker.xml`
enabled. Let's also assume that a queue and connection factory has been config file as well.
defined in the `activemq-jms.xml` config file.
``` java ``` java
import org.apache.activemq.artemis.jms.server.embedded.EmbeddedJMS; import org.apache.activemq.artemis.jms.server.embedded.EmbeddedJMS;
@ -85,19 +84,19 @@ import org.apache.activemq.artemis.jms.server.embedded.EmbeddedJMS;
EmbeddedJMS jms = new EmbeddedJMS(); EmbeddedJMS jms = new EmbeddedJMS();
jms.start(); jms.start();
// This assumes we have configured activemq-jms.xml with the appropriate config information // This assumes we have configured broker.xml with the appropriate config information
ConnectionFactory connectionFactory = jms.lookup("ConnectionFactory"); ConnectionFactory connectionFactory = jms.lookup("ConnectionFactory");
Destination destination = jms.lookup("/example/queue"); Destination destination = jms.lookup("/example/queue");
... regular JMS code ... ... regular JMS code ...
``` ```
By default, the `EmbeddedJMS` class will store component entries defined By default, the `EmbeddedJMS` class will store the "entries" defined for
within your `activemq-jms.xml` file in an internal concurrent hash map. your JMS components within `broker.xml` in an internal concurrent hash
The `EmbeddedJMS.lookup()` method returns components stored in this map. map. The `EmbeddedJMS.lookup()` method returns components stored in
If you want to use JNDI, call the `EmbeddedJMS.setContext()` method with this map. If you want to use JNDI, call the `EmbeddedJMS.setContext()`
the root JNDI context you want your components bound into. See the method with the root JNDI context you want your components bound into.
javadocs for this class for more details on other config options. See the JavaDocs for this class for more details on other config options.
## POJO instantiation - Embedding Programmatically ## POJO instantiation - Embedding Programmatically
@ -159,28 +158,34 @@ an example of this:
``` java ``` java
// Step 1. Create Apache ActiveMQ Artemis core configuration, and set the properties accordingly // Step 1. Create Apache ActiveMQ Artemis core configuration, and set the properties accordingly
Configuration configuration = new ConfigurationImpl(); Configuration configuration = new ConfigurationImpl()
configuration.setPersistenceEnabled(false); .setPersistenceEnabled(false)
configuration.setSecurityEnabled(false); .setSecurityEnabled(false)
configuration.getAcceptorConfigurations().add(new TransportConfiguration(NettyAcceptorFactory.class.getName())); .addAcceptorConfiguration(new TransportConfiguration(NettyAcceptorFactory.class.getName()))
.addConnectorConfiguration("myConnector", new TransportConfiguration(NettyAcceptorFactory.class.getName()));
// Step 2. Create the JMS configuration // Step 2. Create the JMS configuration
JMSConfiguration jmsConfig = new JMSConfigurationImpl(); JMSConfiguration jmsConfig = new JMSConfigurationImpl();
// Step 3. Configure the JMS ConnectionFactory // Step 3. Configure the JMS ConnectionFactory
TransportConfiguration connectorConfig = new TransportConfiguration(NettyConnectorFactory.class.getName()); ConnectionFactoryConfiguration cfConfig = new ConnectionFactoryConfigurationImpl()
ConnectionFactoryConfiguration cfConfig = new ConnectionFactoryConfigurationImpl("cf", connectorConfig, "/cf"); .setName("cf")
.setConnectorNames(Arrays.asList("myConnector"))
.setBindings("/cf");
jmsConfig.getConnectionFactoryConfigurations().add(cfConfig); jmsConfig.getConnectionFactoryConfigurations().add(cfConfig);
// Step 4. Configure the JMS Queue // Step 4. Configure the JMS Queue
JMSQueueConfiguration queueConfig = new JMSQueueConfigurationImpl("queue1", null, false, "/queue/queue1"); JMSQueueConfiguration queueConfig = new JMSQueueConfigurationImpl()
.setName("queue1")
.setDurable(false)
.setBindings("/queue/queue1");
jmsConfig.getQueueConfigurations().add(queueConfig); jmsConfig.getQueueConfigurations().add(queueConfig);
// Step 5. Start the JMS Server using the Apache ActiveMQ Artemis core server and the JMS configuration // Step 5. Start the JMS Server using the Apache ActiveMQ Artemis core server and the JMS configuration
EmbeddedJMS jmsServer = new EmbeddedJMS(); jmsServer = new EmbeddedJMS()
jmsServer.setConfiguration(configuration); .setConfiguration(configuration)
jmsServer.setJmsConfiguration(jmsConfig); .setJmsConfiguration(jmsConfig)
jmsServer.start(); .start();
``` ```
Please see the examples for an example which shows how to setup and run Apache ActiveMQ Artemis Please see the examples for an example which shows how to setup and run Apache ActiveMQ Artemis

View File

@ -23,8 +23,8 @@ import javax.jms.MessageProducer;
import javax.jms.Queue; import javax.jms.Queue;
import javax.jms.Session; import javax.jms.Session;
import javax.jms.TextMessage; import javax.jms.TextMessage;
import java.util.ArrayList;
import java.util.Date; import java.util.Date;
import java.util.Arrays;
import org.apache.activemq.artemis.api.core.TransportConfiguration; import org.apache.activemq.artemis.api.core.TransportConfiguration;
import org.apache.activemq.artemis.core.config.Configuration; import org.apache.activemq.artemis.core.config.Configuration;
@ -46,34 +46,35 @@ public final class EmbeddedExample {
public static void main(final String[] args) throws Exception { public static void main(final String[] args) throws Exception {
// Step 1. Create ActiveMQ Artemis core configuration, and set the properties accordingly // Step 1. Create ActiveMQ Artemis core configuration, and set the properties accordingly
Configuration configuration = new ConfigurationImpl(); Configuration configuration = new ConfigurationImpl()
configuration.setPersistenceEnabled(false); .setPersistenceEnabled(false)
configuration.setJournalDirectory("target/data/journal"); .setJournalDirectory("target/data/journal")
configuration.setSecurityEnabled(false); .setSecurityEnabled(false)
configuration.getAcceptorConfigurations().add(new TransportConfiguration(NettyAcceptorFactory.class.getName())); .addAcceptorConfiguration(new TransportConfiguration(NettyAcceptorFactory.class.getName()))
.addConnectorConfiguration("connector", new TransportConfiguration(NettyConnectorFactory.class.getName()));
TransportConfiguration connectorConfig = new TransportConfiguration(NettyConnectorFactory.class.getName());
configuration.getConnectorConfigurations().put("connector", connectorConfig);
// Step 2. Create the JMS configuration // Step 2. Create the JMS configuration
JMSConfiguration jmsConfig = new JMSConfigurationImpl(); JMSConfiguration jmsConfig = new JMSConfigurationImpl();
// Step 3. Configure the JMS ConnectionFactory // Step 3. Configure the JMS ConnectionFactory
ArrayList<String> connectorNames = new ArrayList<>(); ConnectionFactoryConfiguration cfConfig = new ConnectionFactoryConfigurationImpl()
connectorNames.add("connector"); .setName("cf")
ConnectionFactoryConfiguration cfConfig = new ConnectionFactoryConfigurationImpl().setName("cf").setConnectorNames(connectorNames).setBindings("cf"); .setConnectorNames(Arrays.asList("connector"))
.setBindings("cf");
jmsConfig.getConnectionFactoryConfigurations().add(cfConfig); jmsConfig.getConnectionFactoryConfigurations().add(cfConfig);
// Step 4. Configure the JMS Queue // Step 4. Configure the JMS Queue
JMSQueueConfiguration queueConfig = new JMSQueueConfigurationImpl().setName("queue1").setDurable(false).setBindings("queue/queue1"); JMSQueueConfiguration queueConfig = new JMSQueueConfigurationImpl()
.setName("queue1")
.setDurable(false)
.setBindings("queue/queue1");
jmsConfig.getQueueConfigurations().add(queueConfig); jmsConfig.getQueueConfigurations().add(queueConfig);
// Step 5. Start the JMS Server using the ActiveMQ Artemis core server and the JMS configuration // Step 5. Start the JMS Server using the ActiveMQ Artemis core server and the JMS configuration
EmbeddedJMS jmsServer = new EmbeddedJMS(); EmbeddedJMS jmsServer = new EmbeddedJMS()
jmsServer.setConfiguration(configuration); .setConfiguration(configuration)
jmsServer.setJmsConfiguration(jmsConfig); .setJmsConfiguration(jmsConfig)
jmsServer.start(); .start();
System.out.println("Started Embedded JMS Server"); System.out.println("Started Embedded JMS Server");
// Step 6. Lookup JMS resources defined in the configuration // Step 6. Lookup JMS resources defined in the configuration