| Title: JMS Resources and MDB Container |
| <a name="JMSResourcesandMDBContainer-ExternalActiveMQBroker"></a> |
| # External ActiveMQ Broker |
| |
| <openejb> |
| <Resource id="MyJmsResourceAdapter" type="ActiveMQResourceAdapter"> |
| # Do not start the embedded ActiveMQ broker |
| BrokerXmlConfig |
| ServerUrl tcp://someHostName:61616 |
| </Resource> |
| |
| <Resource id="MyJmsConnectionFactory" type="javax.jms.ConnectionFactory"> |
| ResourceAdapter MyJmsResourceAdapter |
| </Resource> |
| |
| <Container id="MyJmsMdbContainer" ctype="MESSAGE"> |
| ResourceAdapter MyJmsResourceAdapter |
| </Container> |
| |
| <Resource id="FooQueue" type="javax.jms.Queue"/> |
| <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. |
| |
| |
| 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: |
| |
| 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 |
| |
| _TODO_ |