...
External ActiveMQ Broker
Code Block | ||||||
---|---|---|---|---|---|---|
| ||||||
<openejb> <Container<Resource id="MyMDBContainerMyJmsResourceAdapter" type="MESSAGEActiveMQResourceAdapter"> # The resource adapter# deliversDo messagesnot tostart the embedded ActiveMQ containerbroker ResourceAdapter BrokerXmlConfig MyActiveMQResourceAdapter # Specifies the message listener interface handled by this container ServerUrl tcp://someHostName:61616 </Resource> <Resource MessageListenerInterface id="MyJmsConnectionFactory" type="javax.jms.MessageListenerConnectionFactory"> # Specifies the activation specResourceAdapter classMyJmsResourceAdapter ActivationSpecClass org.apache.activemq.ra.ActiveMQActivationSpec</Resource> # Specifies the maximum number of bean instances that are<Container id="MyJmsMdbContainer" ctype="MESSAGE"> # allowed to exist for each MDB deployment. InstanceLimit 10 ResourceAdapter MyJmsResourceAdapter </Container> <Resource id="MyActiveMQResourceAdapterFooQueue" providertype="Default JMS Resource Adapter"javax.jms.Queue"/> # Broker configuration URI as defined by ActiveMQ # see http://activemq.apache.org/broker-configuration-uri.html BrokerXmlConfig broker:(tcp://localhost:61616)?useJmx=false # Broker address ServerUrl vm://localhost?async=true # Specifies the size of the thread pool available to AciveMQ. ThreadPoolSize 30 </Resource> </openejb> |
Note on BrokerConfigXml
See Broker Configuration URI for the full list of URI syntax and options.
<Resource id="BarTopic" type="javax.jms.Topic"/>
</openejb>
|
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:'.
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.
Code Block |
---|
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");
// Do not start the ActiveMQ broker
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);
|
From anywhere in the same VM as the EJB Container you could lookup the above resources like so:
Code Block |
---|
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");
|
Internal ActiveMQ Broker
TODOSupport for the "broker:" and "properties:" URI syntaxes should work out of the box. For the "xbean:" option you'll need to add spring, xbean-spring and possibly a few other libraries to the libs/ dir (or your classpath if we are embedded) – all of which will be available from an activemq 4.1.1 distro.