Announcement Announcement Module
Collapse
No announcement yet.
WebSphereUowTransactionManager XA transaction JMS and JDBC Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • WebSphereUowTransactionManager XA transaction JMS and JDBC

    Hi i want to do the following two operations in a transaction using WebSphereUowTransactionManager, any example would be a great help.

    1.) Send JMS message to Queue using JMS outbound channel adapter.
    2.) Insert record into database.

    But when any exception comes inside the method the message sent to the Queue is not rolled back.
    Here is the method implementation to send message and insert into db.
    Code:
            
           @Autowired	
    	private IMessageSenderGateway messageSender;
    
           @Transactional(rollbackFor={Exception.class, DuplicateKeyException.class})
    	public void testSendMessage() throws Exception {
    		messageSender.sendMessage("Hello Gateway");
    		System.out.println("JMS message sent  ");
    
    		String sql = "insert into public.customer(cust_id, first_name, age) values ("
    				+ 3 + ", 'test2', " + 20 + ")";
    		jdbcTemplate.execute(sql);
    		System.out.println("Inserted into DB ");
    
    	}
    Here is my spring configuration,

    Code:
           <context:annotation-config />
    	<context:component-scan base-package="com.spring" />
    	<tx:annotation-driven transaction-manager="transactionManager" />
    	<tx:jta-transaction-manager />
    
    	<bean id="jndiTemplate" class="org.springframework.jndi.JndiTemplate">
    		<property name="environment">
    			<props>
    				<prop key="java.naming.factory.initial">com.ibm.websphere.naming.WsnInitialContextFactory
    				</prop>
    				<prop key="java.naming.provider.url">iiop://localhost:2809</prop>
    			</props>
    		</property>
    	</bean>
    
    	<bean id="jmsDestinationResolver"
    		class="org.springframework.jms.support.destination.JndiDestinationResolver">
    		<property name="jndiTemplate" ref="jndiTemplate" />
    		<property name="cache" value="true" />
    	</bean>
    
    	<bean id="connectionFactory" class="org.springframework.jndi.JndiObjectFactoryBean">
    		<property name="jndiTemplate" ref="jndiTemplate" />
    		<property name="jndiName" value="jms/JmsConnectionFactory" />
    	</bean>
    
    	<bean id="destination" class="org.springframework.jndi.JndiObjectFactoryBean">
    		<property name="jndiTemplate" ref="jndiTemplate" />
    		<property name="jndiName" value="jms/JmsQueue" />
    	</bean>
    
    	<bean id="jmsTemplate" class="org.springframework.jms.core.JmsTemplate">
    		<property name="connectionFactory" ref="connectionFactory" />
    		<property name="destinationResolver" ref="jmsDestinationResolver" />
    		<property name="defaultDestination" ref="destination" />
    		<property name="sessionTransacted" value="true" />		
    	</bean>
    
    	
    	<bean id="transactionManager"
    		class="org.springframework.transaction.jta.WebSphereUowTransactionManager">
    		<property name="jndiTemplate" ref="jndiTemplate" />
    		<property name="userTransactionName" value="java:comp/UserTransaction" />
    	</bean>
    
    	<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource"
    		destroy-method="close">
    		<property name="driverClassName" value="org.postgresql.xa.PGXADataSource" />
    		<property name="url" value="jdbc:postgresql://localhost:5432/postgres" />
    		<property name="username" value="postgres" />
    		<property name="password" value="postgres" />
    	</bean>
    
    	<bean id="jdbcTemplate" class="org.springframework.jdbc.core.JdbcTemplate">
    		<property name="dataSource" ref="dataSource" />
    	</bean>
    	
    	<int:channel id="outputsendjmsmessage"/>
    	<int:gateway id="messageSenderGateway" service-interface="com.spring.springjms.gateway.IMessageSenderGateway"
    	 	default-request-channel="outputsendjmsmessage" /> 
    	<jms:outbound-channel-adapter channel="outputsendjmsmessage" jms-template="jmsTemplate" extract-payload="true" />

  • #2
    Sorry for not getting to this sooner. We are in the process of moving to StackOverflow for our forums.

    This question is probably a better candidate for StackOverflow, perhaps against the #spring-jms tag.

    If you do post it there, please reply here with the link.

    Thanks!

    Comment

    Working...
    X