0

I want to achieve the following:

i) we have a weblogic queue and external applications would be writing into the queue

ii)I have to write a stand-alone application which can read and write into this queue inside a transaction. i.e. the messages from the queue has to be persisted into DB. So in case of any error at any stage, the transaction should rollback and the message should be available in the queue again.

To achieve this I have done some self study and came across the below URL: http://www.javaworld.com/article/2077963/open-source-tools/distributed-transactions-in-spring--with-and-without-xa.html?page=3 I have understood that I have to use JTA and XA resources for this. I have tried using Atomikos as the JTA Transaction manager following the below URL: http://www.atomikos.com/Documentation/SpringIntegration

After trying whole day I have comeup with the following incomplete applicationContext.xml:

<beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context"
    xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd">

    <bean id="jndiTemplate" class="org.springframework.jndi.JndiTemplate">
        <property name="environment">
            <props>
                <prop key="java.naming.provider.url">t3://somehost.corp.com:8011</prop>
                <prop key="java.naming.factory.initial">weblogic.jndi.WLInitialContextFactory</prop>
            </props>
        </property>
    </bean>
<!--
This is an interface not a concreate class. Not sure what needs to go here for weblogic queue connection factory.
     <bean id="xaFactory" class="javax.jms.XAConnectionFactory">
        <property name="brokerURL" value="t3://somehost.corp.com:8011" />
    </bean> -->

    <bean id="ConnectionFactory" class="com.atomikos.jms.AtomikosConnectionFactoryBean"
        init-method="init" destroy-method="close">
        <property name="uniqueResourceName" value="jms/AuditCF" />
         <property name="xaConnectionFactory" ref="xaFactory" />
    </bean>

    <bean id="JtaTransactionManager"
        class="org.springframework.transaction.jta.JtaTransactionManager">
        <property name="transactionManager" ref="AtomikosTransactionManager" />
        <property name="userTransaction" ref="AtomikosUserTransaction" />
    </bean>

    <bean id="AtomikosTransactionManager" class="com.atomikos.icatch.jta.UserTransactionManager"
        init-method="init" destroy-method="close">
        <property name="forceShutdown" value="false" />
    </bean>

    <bean id="AtomikosUserTransaction" class="com.atomikos.icatch.jta.UserTransactionImp">
        <property name="transactionTimeout" value="300" />
    </bean>
    <bean id="myDestination" class="org.springframework.jndi.JndiObjectFactoryBean">
        <property name="jndiName">
            <value>jms/AuditQ</value>
        </property>
    </bean>
    <bean id="service" class="com.samples.AccountService">
        <property name="jmsTemplate">
            <ref bean="jmsTemplate" />
        </property>
    </bean>
    <bean id="jmsTemplate" class="org.springframework.jms.core.JmsTemplate">
        <property name="connectionFactory">
            <ref bean="ConnectionFactory" />
        </property>
        <property name="defaultDestination">
            <ref bean="myDestination" />
        </property>
        <property name="destinationResolver" ref="jndiResolver" />
    </bean>

    <!-- a class that implements javax.jms.MessageListener -->
    <bean id="MessageListener" class="com.samples.Messages" />

    <bean id="MessageListenerContainer"
        class="org.springframework.jms.listener.DefaultMessageListenerContainer">
        <property name="transactionManager" ref="JtaTransactionManager" />
        <property name="connectionFactory" ref="ConnectionFactory" />
        <property name="messageListener" ref="MessageListener" />
        <property name="destinationName" value="jms/AuditQ" />
        <property name="concurrentConsumers" value="1" />
        <property name="receiveTimeout" value="3000" />
        <property name="sessionTransacted" value="true" />
    </bean>

    <bean id="hibernateTemplate" class="org.springframework.orm.hibernate4.HibernateTemplate">
        <property name="sessionFactory">
            <ref bean="sessionFactory" />
        </property>
    </bean>



    <bean id="connectionFactory" class="org.springframework.jndi.JndiObjectFactoryBean">
        <property name="jndiTemplate">
            <ref bean="jndiTemplate" />
        </property>
        <property name="jndiName">
            <value>weblogic.jms.XAConnectionFactory</value>
        </property>
    </bean>
    <bean id="jndiResolver"
        class="org.springframework.jms.support.destination.JndiDestinationResolver">
        <property name="jndiTemplate">
            <ref bean="jndiTemplate" />
        </property>
        <property name="cache">
            <value>true</value>
        </property>
    </bean>
    <!-- <bean id="jmsTemplate" class="org.springframework.jms.core.JmsTemplate">
        <property name="connectionFactory" ref="connectionFactory" />
        <property name="receiveTimeout">
            <value>0</value>
        </property>
        <property name="destinationResolver" ref="jndiResolver" />
    </bean> -->

    <bean id="datasource" class="com.atomikos.jdbc.AtomikosDataSourceBean"
        init-method="init" destroy-method="close">
        <!-- set an arbitrary but unique name for the datasource -->
        <property name="uniqueResourceName">
            <value>XADBMS</value>
        </property>
        <!-- set the underlying driver class to use, in this example case we use
            Oracle -->
        <property name="xaDataSourceClassName">
            <value>oracle.jdbc.xa.client.OracleXADataSource</value>
        </property>
        <property name="xaProperties">
            <props>
                <prop key="user"><user></prop>
                <prop key="password"><pwd></prop>
                <prop key="URL">jdbc:oracle:thin:@host:3028/DB
                </prop>
            </props>
        </property>
        <!-- how many connections in the pool? -->
        <property name="poolSize" value="3" />
    </bean>
    <bean id="sessionFactory"
        class="org.springframework.orm.hibernate4.LocalSessionFactoryBean">

        <property name="packagesToScan" value="com.samples">
        </property>

        <property name="dataSource">
            <ref bean="datasource" />
        </property>

        <property name="hibernateProperties">
            <props>
                <prop key="hibernate.dialect">org.hibernate.dialect.Oracle10gDialect</prop>
                <prop key="hibernate.connection.isolation">3</prop>
                <prop key="hibernate.current_session_context_class">jta</prop>
                <prop key="hibernate.transaction.factory_class">
                    org.hibernate.transaction.JTATransactionFactory
                </prop>
                <prop key="hibernate.transaction.manager_lookup_class">
                    com.atomikos.icatch.jta.hibernate4.TransactionManagerLookup
                </prop>
            </props>
        </property>
    </bean>

</beans>

As shown in the Spring-Atomikos integration example, the XAConnectionFactory has been mentioned as :

<bean id="xaFactory"  
              class="org.apache.activemq.ActiveMQXAConnectionFactory"> 
      <property name="brokerURL" value="tcp://localhost:61616" /> 
   </bean>

I am unable to find the related configuration I need to do for weblogic queue. I have tried using "weblogic.jms.XAConnectionFactory" as the class, but I get classnotfoundexception for that.

I dont have any experience working with JTA or XA. Kindly guide me.

AC_1985
  • 183
  • 9
  • 22
  • You've added the `spring-boot` tag. Are you using Spring Boot for this application? – Stephane Nicoll Nov 04 '15 at 18:03
  • @StéphaneNicoll: Yes I am using spring boot – AC_1985 Nov 04 '15 at 18:13
  • You are aware that Spring Boot has auto-configuration support for JTA and atomikos, right? Why are you configuring this yourself then? – Stephane Nicoll Nov 06 '15 at 08:19
  • 1
    @StéphaneNicoll: Thanks for your reply. No I m not fully aware of that. I was trying to do the integration of spring and atomikos following the instruction given in the official atomikos site. Could you please let me know what I need to do to make it wotk with spring boot then? How spring boot will know about my queue details such as connection factory, queue name etc? – AC_1985 Nov 06 '15 at 12:52

0 Answers0