Title: JMS Resources and MDB Container
# External ActiveMQ Broker
# Do not start the embedded ActiveMQ broker
BrokerXmlConfig =
ServerUrl = tcp://someHostName:61616
ResourceAdapter = MyJmsResourceAdapter
ResourceAdapter = MyJmsResourceAdapter
The `ServerUrl` would be changed to point to the host and port of the
ActiveMQ process. The various URL formats that ActiveMQ supports also
work, such as 'failover:'.
# Internal ActiveMQ Broker
BrokerXmlConfig = broker:(tcp://someHostName:61616)
ServerUrl = tcp://someHostName:61616
ResourceAdapter = MyJmsResourceAdapter
ResourceAdapter = MyJmsResourceAdapter
The `BrokerXmlConfig` tells ActiveMQ to start on the tcp host/port `someHostName` and `61616`
# Internal ActiveMQ Broker with activemq.xml
The `activemq.xml` file format has a significant number of extra dependencies, such as Spring, and is therefore not included in the distribution by default.
This support can be enabled by adding the right libraries and creating an `conf/activemq.xml` file.
Add the following jars to the `tomee.home/lib/` directory:
- [spring-beans-2.5.6.jar](http://repo1.maven.org/maven2/org/springframework/spring-beans/2.5.6/spring-beans-2.5.6.jar)
- [spring-context-2.5.6.jar](http://repo1.maven.org/maven2/org/springframework/spring-context/2.5.6/spring-context-2.5.6.jar)
- [spring-core-2.5.6.jar](http://repo1.maven.org/maven2/org/springframework/spring-core/2.5.6/spring-core-2.5.6.jar)
- [spring-web-2.5.6.jar](http://repo1.maven.org/maven2/org/springframework/spring-web/2.5.6/spring-web-2.5.6.jar)
- [xbean-spring-3.9.jar](http://repo1.maven.org/maven2/org/apache/xbean/xbean-spring/3.9/xbean-spring-3.9.jar)
Create an [activemq.xml file](http://activemq.apache.org/xml-configuration.html) a in `tomee.home/conf/activemq.xml`.
Then use the `xbean:file:` url prefix in the `BrokerXmlConfig` as shown belog.
BrokerXmlConfig = xbean:file:conf/activemq.xml
ServerUrl = tcp://someHostName:61616
ResourceAdapter = MyJmsResourceAdapter
ResourceAdapter = MyJmsResourceAdapter
Finally, restart the server.
# Configuration via System properties
The same can be done via properties in an embedded configuration, via the
`conf/system.properties` file or on the command line via `-D` flags.
Properties p = new Properties();
p.put(Context.INITIAL_CONTEXT_FACTORY, LocalInitialContextFactory.class.getName());
p.put("MyJmsResourceAdapter", "new://Resource?type=ActiveMQResourceAdapter");
p.put("MyJmsResourceAdapter.ServerUrl", "tcp://someHostName:61616");
p.put("MyJmsResourceAdapter.BrokerXmlConfig", "");
p.put("MyJmsConnectionFactory", "new://Resource?type=javax.jms.ConnectionFactory");
p.put("MyJmsConnectionFactory.ResourceAdapter", "MyJmsResourceAdapter");
p.put("MyJmsMdbContainer", "new://Container?type=MESSAGE");
p.put("MyJmsMdbContainer.ResourceAdapter", "MyJmsResourceAdapter");
p.put("FooQueue", "new://Resource?type=javax.jms.Queue");
p.put("BarTopic", "new://Resource?type=javax.jms.Topic");
InitialContext context = new InitialContext(p);
# Global lookup of JMS Resources
From anywhere in the same VM as the EJB Container you could lookup the
above resources like so:
javax.jms.ConnectionFactory cf = (ConnectionFactory)
context.lookup("openejb:Resource/MyJmsConnectionFactory");
javax.jms.Queue queue = (Queue) context.lookup("openejb:Resource/FooQueue");
javax.jms.Topic topic = (Topic) context.lookup("openejb:Resource/BarTopic");