Search in sources :

Example 1 with ActiveMQResourceAdapter

use of org.apache.openejb.resource.activemq.ActiveMQResourceAdapter in project tomee by apache.

the class JmsTest method setUp.

@Override
protected void setUp() throws Exception {
    super.setUp();
    // create a transaction manager
    final GeronimoTransactionManager transactionManager = new GeronimoTransactionManager();
    // create the ActiveMQ resource adapter instance
    ra = new ActiveMQResourceAdapter();
    // initialize properties
    ra.setServerUrl(brokerAddress);
    ra.setBrokerXmlConfig(brokerXmlConfig);
    ra.setStartupTimeout(new Duration(10, TimeUnit.SECONDS));
    // create a thead pool for ActiveMQ
    final Executor threadPool = Executors.newFixedThreadPool(30);
    // create a work manager which ActiveMQ uses to dispatch message delivery jobs
    final TransactionContextHandler txWorkContextHandler = new TransactionContextHandler(transactionManager);
    final GeronimoWorkManager workManager = new GeronimoWorkManager(threadPool, threadPool, threadPool, Collections.<WorkContextHandler>singletonList(txWorkContextHandler));
    // wrap the work mananger and transaction manager in a bootstrap context (connector spec thing)
    final BootstrapContext bootstrapContext = new GeronimoBootstrapContext(workManager, transactionManager, transactionManager);
    // Create a ConnectionFactory
    connectionFactory = new ActiveMQConnectionFactory(brokerAddress);
    ra.setConnectionFactory(connectionFactory);
    // start the resource adapter
    try {
        ra.start(bootstrapContext);
    } catch (final ResourceAdapterInternalException e) {
        throw new OpenEJBException(e);
    }
}
Also used : ActiveMQConnectionFactory(org.apache.activemq.ActiveMQConnectionFactory) OpenEJBException(org.apache.openejb.OpenEJBException) Executor(java.util.concurrent.Executor) GeronimoBootstrapContext(org.apache.geronimo.connector.GeronimoBootstrapContext) TransactionContextHandler(org.apache.geronimo.connector.work.TransactionContextHandler) GeronimoWorkManager(org.apache.geronimo.connector.work.GeronimoWorkManager) ActiveMQResourceAdapter(org.apache.openejb.resource.activemq.ActiveMQResourceAdapter) Duration(org.apache.openejb.util.Duration) GeronimoBootstrapContext(org.apache.geronimo.connector.GeronimoBootstrapContext) BootstrapContext(javax.resource.spi.BootstrapContext) GeronimoTransactionManager(org.apache.geronimo.transaction.manager.GeronimoTransactionManager) ResourceAdapterInternalException(javax.resource.spi.ResourceAdapterInternalException)

Aggregations

Executor (java.util.concurrent.Executor)1 BootstrapContext (javax.resource.spi.BootstrapContext)1 ResourceAdapterInternalException (javax.resource.spi.ResourceAdapterInternalException)1 ActiveMQConnectionFactory (org.apache.activemq.ActiveMQConnectionFactory)1 GeronimoBootstrapContext (org.apache.geronimo.connector.GeronimoBootstrapContext)1 GeronimoWorkManager (org.apache.geronimo.connector.work.GeronimoWorkManager)1 TransactionContextHandler (org.apache.geronimo.connector.work.TransactionContextHandler)1 GeronimoTransactionManager (org.apache.geronimo.transaction.manager.GeronimoTransactionManager)1 OpenEJBException (org.apache.openejb.OpenEJBException)1 ActiveMQResourceAdapter (org.apache.openejb.resource.activemq.ActiveMQResourceAdapter)1 Duration (org.apache.openejb.util.Duration)1