activemq-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Eugene Prokopiev <prokop...@stc.donpac.ru>
Subject Jencks : JMS & JDBC Transaction problem
Date Tue, 01 Aug 2006 14:56:28 GMT
Hi,

I use this context.xml:

<beans>
	
	<bean id="broker" class="org.apache.activemq.broker.BrokerService" 
init-method="start" destroy-method="stop">
		<property name="persistent" value="false"/>
		<property name="transportConnectorURIs">
			<list>
				<value>tcp://localhost:5000</value>
			</list>
		</property>
	</bean>
	
	<bean id="transactionContextManager" 
class="org.jencks.factory.TransactionContextManagerFactoryBean"/>
	<bean id="userTransaction" 
class="org.jencks.factory.GeronimoTransactionManagerFactoryBean"/>
	<bean id="jtaTransactionManager" 
class="org.springframework.transaction.jta.JtaTransactionManager">
		<property name="userTransaction" ref="userTransaction" />
	</bean>
	
	<bean id="jmsResourceAdapter" 
class="org.apache.activemq.ra.ActiveMQResourceAdapter">
		<property name="serverUrl" value="tcp://localhost:5000"/>
	</bean>

	<bean id="jencks" class="org.jencks.JCAContainer">
		<property name="bootstrapContext">
			<bean class="org.jencks.factory.BootstrapContextFactoryBean">
				<property name="threadPoolSize" value="25"/>
			</bean>
		</property>
		<property name="resourceAdapter" ref="jmsResourceAdapter"/>
	</bean>

	<bean id="inboundConnector" class="org.jencks.JCAConnector">
		<property name="jcaContainer" ref="jencks" />
		<property name="activationSpec">
			<bean class="org.apache.activemq.ra.ActiveMQActivationSpec">
				<property name="destination" value="messages.input"/>
				<property name="destinationType" value="javax.jms.Queue"/>
			</bean>
		</property>
		<property name="transactionManager" ref="userTransaction"/>
		<property name="ref" value="echoBean"/>
	</bean>
	
	<bean id="connectionManager" 
class="org.jencks.factory.ConnectionManagerFactoryBean">
		<property name="transactionSupport">
			<bean class="org.jencks.factory.XATransactionFactoryBean">
				<property name="useTransactionCaching" value="true"/>
				<property name="useThreadCaching" value="false"/>
			</bean>
		</property>
		<property name="poolingSupport">
			<bean class="org.jencks.factory.SinglePoolFactoryBean">
				<property name="maxSize" value="2"/>
				<property name="minSize" value="1"/>
				<property name="blockingTimeoutMilliseconds" value="60"/>
				<property name="idleTimeoutMinutes" value="60"/>
				<property name="matchOne" value="true"/>
				<property name="matchAll" value="true"/>
				<property name="selectOneAssumeMatch" value="true"/>
			</bean>
		</property>
	</bean>
	
	<bean id="echoBean" class="transaction.test.EchoBean">
		<property name="jdbcTemplate">
			<bean class="org.springframework.jdbc.core.JdbcTemplate">
				<property name="dataSource">
					<!--
					<bean class="org.postgresql.xa.PGXADataSource">
						<property name="serverName" value="ats-manager"/>
						<property name="databaseName" value="activemq"/>
						<property name="user" value="activemq"/>
					</bean>
					-->
					<bean 
class="org.springframework.jca.support.LocalConnectionFactoryBean">
						<property name="managedConnectionFactory">
							<bean class="org.jencks.tranql.XAPoolDataSourceMCF">
								<property name="driverName" value="org.postgresql.Driver"/>
								<property name="url" 
value="jdbc:postgresql://ats-manager/activemq"/>
								<property name="user" value="activemq"/>
							</bean>
						</property>
						<property name="connectionManager" ref="connectionManager"/>
					</bean>
				</property>
			</bean>
		</property>
		<property name="jmsTemplate">
			<bean class="org.springframework.jms.core.JmsTemplate">
			    <property name="connectionFactory">
			    	<bean 
class="org.springframework.jca.support.LocalConnectionFactoryBean">
						<property name="managedConnectionFactory">
							<bean 
class="org.apache.activemq.ra.ActiveMQManagedConnectionFactory">
								<property name="resourceAdapter" ref="jmsResourceAdapter"/>
							</bean>
						</property>
					</bean>
			    </property>
			</bean>
		</property>
		<property name="destination">
			<bean class="org.apache.activemq.command.ActiveMQQueue">
				<constructor-arg value="messages.output"/>
			</bean>
		</property>
	</bean>

</beans>

EchoBean is:

public class EchoBean implements MessageListener {
	
	private Log log = LogFactory.getLog(getClass());
	
	private JdbcTemplate jdbcTemplate;
	private JmsTemplate jmsTemplate;
	private Destination destination;
	
	public void setDestination(Destination destination) {
		this.destination = destination;
	}
	
	public void setJmsTemplate(JmsTemplate template) {
		this.jmsTemplate = template;
	}
	
	public void setJdbcTemplate(JdbcTemplate jdbcTemplate) {
		this.jdbcTemplate = jdbcTemplate;
	}
	
	public void onMessage(final Message message) {
		log.debug("MESSAGE : "+message);
		if (message instanceof TextMessage) {
			jmsTemplate.send(destination, new MessageCreator() {
				public Message createMessage(Session session) throws JMSException {
					return session.createTextMessage(((TextMessage)message).getText());
				}			
			});
			try {
				jdbcTemplate.execute(
					"insert into t2 values('"+((TextMessage)message).getText()+"')");
			} catch (Exception e) {
				e.printStackTrace();
			}
		}		
	}	

}

On starting context and put message to messages.input with external 
application I got:

DEBUG org.jencks.XAEndpoint 
      Transaction started and resource enlisted
DEBUG transaction.test.EchoBean 
      MESSAGE : ActiveMQTextMessage {commandId = 5, responseRequired = 
true, messageId = 
ID:prokopiev.stc.donpac.ru-52879-1154443542693-0:0:1:1:1, 
originalDestination = null, originalTransactionId = null, producerId = 
ID:prokopiev.stc.donpac.ru-52879-1154443542693-0:0:1:1, destination = 
queue://messages.input, transactionId = null, expiration = 0, timestamp 
= 1154443543118, arrival = 0, correlationId = null, replyTo = null, 
persistent = true, type = null, priority = 4, groupID = null, 
groupSequence = 0, targetConsumerId = null, compressed = false, userID = 
null, content = org.apache.activeio.packet.ByteSequence@158689a, 
marshalledProperties = null, dataStructure = null, redeliveryCounter = 
0, size = 0, properties = null, readOnlyProperties = true, readOnlyBody 
= true, text = null}
DEBUG org.apache.activemq.ActiveMQSession 
      Sending message: ActiveMQTextMessage {commandId = 0, 
responseRequired = false, messageId = 
ID:prokopiev.stc.donpac.ru-52866-1154443516464-3:1:1:1:1, 
originalDestination = null, originalTransactionId = null, producerId = 
ID:prokopiev.stc.donpac.ru-52866-1154443516464-3:1:1:1, destination = 
queue://messages.output, transactionId = null, expiration = 0, timestamp 
= 1154443543423, arrival = 0, correlationId = null, replyTo = null, 
persistent = true, type = null, priority = 4, groupID = null, 
groupSequence = 0, targetConsumerId = null, compressed = false, userID = 
null, content = null, marshalledProperties = null, dataStructure = null, 
redeliveryCounter = 0, size = 0, properties = null, readOnlyProperties = 
true, readOnlyBody = true, text = Test Message String}
INFO  org.springframework.beans.factory.xml.XmlBeanDefinitionReader 
      Loading XML bean definitions from class path resource 
[org/springframework/jdbc/support/sql-error-codes.xml]
INFO  org.springframework.jdbc.support.SQLErrorCodesFactory 
      SQLErrorCodes loaded: [DB2, HSQL, MS-SQL, MySQL, Oracle, Informix, 
PostgreSQL, Sybase]
org.springframework.jdbc.BadSqlGrammarException: StatementCallback; bad 
SQL grammar [insert into t2 values('Test Message String')]; nested 
exception is org.postgresql.util.PSQLException: ERROR: relation "t2" 
does not existDEBUG org.apache.activemq.TransactionContext 
                    End: 
[globalId=100000005748415420444f2057452043414c4c2049543f0000000000000000000000000000000000000,branchId=100000005748415420444f2057452043414c4c2049543f0000000000000000000000000000000000000]
DEBUG org.apache.activemq.TransactionContext 
      Ended XA transaction: 
XID:1197822575:01000000000000005748415420444f2057452043414c4c2049543f00000000000000000000000000000000000000000000000000000000000000000000000000:01000000000000005748415420444f2057452043414c4c2049543f00000000000000000000000000000000000000000000000000000000000000000000000000
DEBUG org.apache.activemq.TransactionContext 
      End: 
[globalId=100000005748415420444f2057452043414c4c2049543f0000000000000000000000000000000000000,branchId=100000005748415420444f2057452043414c4c2049543f0000000000000000000000000000000000000]
DEBUG org.apache.activemq.TransactionContext 
      Rollback: 
[globalId=100000005748415420444f2057452043414c4c2049543f0000000000000000000000000000000000000,branchId=100000005748415420444f2057452043414c4c2049543f0000000000000000000000000000000000000]
DEBUG org.apache.activemq.transaction.XATransaction 
      XA Transaction rollback: 
XID:1197822575:01000000000000005748415420444f2057452043414c4c2049543f00000000000000000000000000000000000000000000000000000000000000000000000000:01000000000000005748415420444f2057452043414c4c2049543f00000000000000000000000000000000000000000000000000000000000000000000000000

Caused by: org.postgresql.util.PSQLException: ERROR: relation "t2" does 
not exist
	at 
org.postgresql.core.v3.QueryExecutorImpl.receiveErrorResponse(QueryExecutorImpl.java:1512)
	at 
org.postgresql.core.v3.QueryExecutorImpl.processResults(QueryExecutorImpl.java:1297)
	at 
org.postgresql.core.v3.QueryExecutorImpl.execute(QueryExecutorImpl.java:188)
	at 
org.postgresql.jdbc2.AbstractJdbc2Statement.execute(AbstractJdbc2Statement.java:437)
	at 
org.postgresql.jdbc2.AbstractJdbc2Statement.executeWithFlags(AbstractJdbc2Statement.java:339)
	at 
org.postgresql.jdbc2.AbstractJdbc2Statement.execute(AbstractJdbc2Statement.java:331)
	at org.enhydra.jdbc.core.CoreStatement.execute(CoreStatement.java:87)
	at 
org.tranql.connector.jdbc.StatementHandle.execute(StatementHandle.java:121)
	at 
org.springframework.jdbc.core.JdbcTemplate$1ExecuteStatementCallback.doInStatement(JdbcTemplate.java:309)
	at 
org.springframework.jdbc.core.JdbcTemplate.execute(JdbcTemplate.java:283)
	at 
org.springframework.jdbc.core.JdbcTemplate.execute(JdbcTemplate.java:316)
	at transaction.test.EchoBean.onMessage(EchoBean.java:45)
	at org.jencks.XAEndpoint.onMessage(XAEndpoint.java:126)
	at 
org.apache.activemq.ra.MessageEndpointProxy$MessageEndpointAlive.onMessage(MessageEndpointProxy.java:120)
	at 
org.apache.activemq.ra.MessageEndpointProxy.onMessage(MessageEndpointProxy.java:60)
	at org.apache.activemq.ActiveMQSession.run(ActiveMQSession.java:690)
	at org.apache.activemq.ra.ServerSessionImpl.run(ServerSessionImpl.java:164)
	at 
org.apache.geronimo.connector.work.WorkerContext.run(WorkerContext.java:291)
	at EDU.oswego.cs.dl.util.concurrent.PooledExecutor$Worker.run(Unknown 
Source)
	at java.lang.Thread.run(Thread.java:595)
ERROR Transaction 
      Unexpected exception rolling back 
org.apache.geronimo.transaction.manager.WrapperNamedXAResource@c5122f; 
continuing with rollback
javax.transaction.xa.XAException
	at 
org.enhydra.jdbc.standard.StandardXADataSource.getConnection(StandardXADataSource.java:444)
	at 
org.enhydra.jdbc.standard.StandardXAConnection.rollback(StandardXAConnection.java:547)
	at 
org.apache.geronimo.transaction.manager.WrapperNamedXAResource.rollback(WrapperNamedXAResource.java:78)
	at 
org.apache.geronimo.transaction.manager.TransactionImpl.rollbackResources(TransactionImpl.java:542)
	at 
org.apache.geronimo.transaction.manager.TransactionImpl.commit(TransactionImpl.java:233)
	at 
org.apache.geronimo.transaction.manager.TransactionManagerImpl.commit(TransactionManagerImpl.java:143)
	at 
org.apache.geronimo.transaction.context.InheritableTransactionContext.complete(InheritableTransactionContext.java:196)
	at 
org.apache.geronimo.transaction.context.InheritableTransactionContext.commit(InheritableTransactionContext.java:146)
	at 
org.apache.geronimo.transaction.context.GeronimoTransactionManager.commit(GeronimoTransactionManager.java:81)
	at 
org.apache.geronimo.transaction.context.GeronimoTransactionDelegate.commit(GeronimoTransactionDelegate.java:51)
	at org.jencks.XAEndpoint.afterDelivery(XAEndpoint.java:103)
	at 
org.apache.activemq.ra.MessageEndpointProxy$MessageEndpointAlive.afterDelivery(MessageEndpointProxy.java:125)
	at 
org.apache.activemq.ra.MessageEndpointProxy.afterDelivery(MessageEndpointProxy.java:64)
	at 
org.apache.activemq.ra.ServerSessionImpl.afterDelivery(ServerSessionImpl.java:215)
	at org.apache.activemq.ActiveMQSession.run(ActiveMQSession.java:744)
	at org.apache.activemq.ra.ServerSessionImpl.run(ServerSessionImpl.java:164)
	at 
org.apache.geronimo.connector.work.WorkerContext.run(WorkerContext.java:291)
	at EDU.oswego.cs.dl.util.concurrent.PooledExecutor$Worker.run(Unknown 
Source)
	at java.lang.Thread.run(Thread.java:595)
ERROR org.apache.geronimo.transaction.context.AbstractTransactionContext 
     Unable to roll back transaction
java.lang.IllegalStateException: Status is STATUS_NO_TRANSACTION
	at 
org.apache.geronimo.transaction.manager.TransactionImpl.rollback(TransactionImpl.java:438)
	at 
org.apache.geronimo.transaction.context.InheritableTransactionContext.rollbackAndThrow(InheritableTransactionContext.java:308)
	at 
org.apache.geronimo.transaction.context.InheritableTransactionContext.complete(InheritableTransactionContext.java:199)
	at 
org.apache.geronimo.transaction.context.InheritableTransactionContext.commit(InheritableTransactionContext.java:146)
	at 
org.apache.geronimo.transaction.context.GeronimoTransactionManager.commit(GeronimoTransactionManager.java:81)
	at 
org.apache.geronimo.transaction.context.GeronimoTransactionDelegate.commit(GeronimoTransactionDelegate.java:51)
	at org.jencks.XAEndpoint.afterDelivery(XAEndpoint.java:103)
	at 
org.apache.activemq.ra.MessageEndpointProxy$MessageEndpointAlive.afterDelivery(MessageEndpointProxy.java:125)
	at 
org.apache.activemq.ra.MessageEndpointProxy.afterDelivery(MessageEndpointProxy.java:64)
	at 
org.apache.activemq.ra.ServerSessionImpl.afterDelivery(ServerSessionImpl.java:215)
	at org.apache.activemq.ActiveMQSession.run(ActiveMQSession.java:744)
	at org.apache.activemq.ra.ServerSessionImpl.run(ServerSessionImpl.java:164)
	at 
org.apache.geronimo.connector.work.WorkerContext.run(WorkerContext.java:291)
	at EDU.oswego.cs.dl.util.concurrent.PooledExecutor$Worker.run(Unknown 
Source)
	at java.lang.Thread.run(Thread.java:595)
DEBUG org.apache.activemq.ra.ServerSessionImpl:0 
      Endpoint failed to process message.
java.lang.RuntimeException: Endpoint after delivery notification failure
	at 
org.apache.activemq.ra.ServerSessionImpl.afterDelivery(ServerSessionImpl.java:217)
	at org.apache.activemq.ActiveMQSession.run(ActiveMQSession.java:744)
	at org.apache.activemq.ra.ServerSessionImpl.run(ServerSessionImpl.java:164)
	at 
org.apache.geronimo.connector.work.WorkerContext.run(WorkerContext.java:291)
	at EDU.oswego.cs.dl.util.concurrent.PooledExecutor$Worker.run(Unknown 
Source)
	at java.lang.Thread.run(Thread.java:595)
Caused by: java.lang.IllegalStateException: Cannot commit if the 
transaction is not bound to the current thread
	at 
org.apache.geronimo.transaction.context.GeronimoTransactionDelegate.rollback(GeronimoTransactionDelegate.java:72)
	at org.jencks.XAEndpoint.doRollback(XAEndpoint.java:143)
	at org.jencks.XAEndpoint.afterDelivery(XAEndpoint.java:116)
	at 
org.apache.activemq.ra.MessageEndpointProxy$MessageEndpointAlive.afterDelivery(MessageEndpointProxy.java:125)
	at 
org.apache.activemq.ra.MessageEndpointProxy.afterDelivery(MessageEndpointProxy.java:64)
	at 
org.apache.activemq.ra.ServerSessionImpl.afterDelivery(ServerSessionImpl.java:215)
	... 5 more

So, JMS operations in transaction can't rollback correctly and message 
placed from messages.input to messages.output.

Please, help me to resolve this problem ...

--
Thanks,
Eugene Prokopiev



Mime
View raw message