org.jencks.pool.PooledSpringXAConnectionFactory without full Jencks JCA support

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
3 messages Options
ENP
Reply | Threaded
Open this post in threaded view
|

org.jencks.pool.PooledSpringXAConnectionFactory without full Jencks JCA support

ENP
Hi,

Is it possible to use only
org.jencks.pool.PooledSpringXAConnectionFactory without full Jencks JCA
support for Spring Message Driven POJO?

I tried to use this context:

<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="geronimo"
class="org.jencks.factory.GeronimoTransactionManagerFactoryBean"/>
        <bean id="geronimoTransactionManager"
class="org.springframework.transaction.jta.JtaTransactionManager">
                <property name="userTransaction" ref="geronimo" />
        </bean>

        <bean id="jmsFactory"
class="org.apache.activemq.ActiveMQXAConnectionFactory">
                <property name="brokerURL" value="tcp://localhost:5000" />
                <property name="userName" value="dispatcher1" />
                <property name="password" value="dpwd1" />
        </bean>
        <bean id="jmsConnectionFactory"
class="org.jencks.pool.PooledSpringXAConnectionFactory">
                <property name="connectionFactory" ref="jmsFactory"/>
                <property name="jtaTransactionManager" ref="geronimoTransactionManager"/>
        </bean>
        <bean id="destination" class="org.apache.activemq.command.ActiveMQQueue">
                <constructor-arg value="messages.input"/>
        </bean>
        <bean id="listenerContainer"
class="org.springframework.jms.listener.DefaultMessageListenerContainer">
                <property name="concurrentConsumers" value="1"/>
                <property name="maxMessagesPerTask" value="1"/>
                <property name="connectionFactory" ref="jmsConnectionFactory"/>
                <property name="destination" ref="destination"/>
                <property name="messageListener" ref="myMessageListener"/>
                <property name="transactionManager" ref="geronimoTransactionManager" />
        </bean>
       
     <bean id="myMessageListener" class="manager.broker.MyMessageListener"/>

</beans>

On consuming message I got:

INFO  CollectionFactory                - JDK 1.4+ collections available
INFO  XmlBeanDefinitionReader          - Loading XML bean definitions
from file [/home/john/workspace/AMQ/conf/manager-simple.xml]
INFO  FileSystemXmlApplicationContext  - Bean factory for application
context
[org.springframework.context.support.FileSystemXmlApplicationContext;hashCode=12282550]:
org.springframework.beans.factory.support.DefaultListableBeanFactory
defining beans
[broker,transactionContextManager,geronimo,geronimoTransactionManager,jmsFactory,jmsConnectionFactory,destination,listenerContainer,myMessageListener];
root of BeanFactory hierarchy
INFO  FileSystemXmlApplicationContext  - 9 beans defined in application
context
[org.springframework.context.support.FileSystemXmlApplicationContext;hashCode=12282550]
INFO  FileSystemXmlApplicationContext  - Unable to locate MessageSource
with name 'messageSource': using default
[org.springframework.context.support.DelegatingMessageSource@388993]
INFO  FileSystemXmlApplicationContext  - Unable to locate
ApplicationEventMulticaster with name 'applicationEventMulticaster':
using default
[org.springframework.context.event.SimpleApplicationEventMulticaster@18aaa1e]
INFO  DefaultListableBeanFactory       - Pre-instantiating singletons in
factory
[org.springframework.beans.factory.support.DefaultListableBeanFactory
defining beans
[broker,transactionContextManager,geronimo,geronimoTransactionManager,jmsFactory,jmsConnectionFactory,destination,listenerContainer,myMessageListener];
root of BeanFactory hierarchy]
INFO  BrokerService                    - ActiveMQ null JMS Message
Broker (localhost) is starting
INFO  BrokerService                    - For help or more information
please see: http://incubator.apache.org/activemq/
INFO  TransportServerThreadSupport     - Listening for connections at:
tcp://prokopiev.stc.donpac.ru:5000
INFO  TransportConnector               - Connector
tcp://prokopiev.stc.donpac.ru:5000 Started
INFO  BrokerService                    - ActiveMQ JMS Message Broker
(localhost, ID:prokopiev.stc.donpac.ru-58620-1155025769955-0:0) started
INFO  JtaTransactionManager            - Using JTA UserTransaction:
org.apache.geronimo.transaction.context.GeronimoTransactionManager@1afae45
INFO  JtaTransactionManager            - Using JTA TransactionManager:
org.apache.geronimo.transaction.context.GeronimoTransactionManager@1afae45
INFO  ManagementContext                - JMX consoles can connect to
service:jmx:rmi:///jndi/rmi://localhost:1099/jmxrmi


ERROR DefaultMessageListenerContainer  - Execution of JMS message
listener failed
javax.jms.JMSException: Session's XAResource has not been enlisted in a
distributed transaction.
        at
org.apache.activemq.ActiveMQXASession.doStartTransaction(ActiveMQXASession.java:109)
        at
org.apache.activemq.ActiveMQMessageConsumer.ackLater(ActiveMQMessageConsumer.java:658)
        at
org.apache.activemq.ActiveMQMessageConsumer.beforeMessageIsConsumed(ActiveMQMessageConsumer.java:610)
        at
org.apache.activemq.ActiveMQMessageConsumer.receive(ActiveMQMessageConsumer.java:469)
        at
org.springframework.jms.listener.DefaultMessageListenerContainer.doExecuteListener(DefaultMessageListenerContainer.java:301)
        at
org.springframework.jms.listener.DefaultMessageListenerContainer$1.doInTransactionWithoutResult(DefaultMessageListenerContainer.java:278)
        at
org.springframework.transaction.support.TransactionCallbackWithoutResult.doInTransaction(TransactionCallbackWithoutResult.java:33)
        at
org.springframework.transaction.support.TransactionTemplate.execute(TransactionTemplate.java:128)
        at
org.springframework.jms.listener.DefaultMessageListenerContainer.executeListener(DefaultMessageListenerContainer.java:275)
        at
org.springframework.jms.listener.DefaultMessageListenerContainer$AsyncMessageListenerInvoker.run(DefaultMessageListenerContainer.java:375)
        at
org.springframework.core.task.SimpleAsyncTaskExecutor$ConcurrencyThrottlingRunnable.run(SimpleAsyncTaskExecutor.java:203)
        at java.lang.Thread.run(Thread.java:595)

How can I enlist session in distributed transaction without JCA?

--
Thanks,
Eugene Prokopiev

Reply | Threaded
Open this post in threaded view
|

Re: org.jencks.pool.PooledSpringXAConnectionFactory without full Jencks JCA support

James Strachan-2
On 8/8/06, Eugene Prokopiev <[hidden email]> wrote:
> Hi,
>
> Is it possible to use only
> org.jencks.pool.PooledSpringXAConnectionFactory without full Jencks JCA
> support for Spring Message Driven POJO?

No. I'd recommend not trying to implement your own version of JCA.


> I tried to use this context:
>
> <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="geronimo"
> class="org.jencks.factory.GeronimoTransactionManagerFactoryBean"/>
>         <bean id="geronimoTransactionManager"
> class="org.springframework.transaction.jta.JtaTransactionManager">
>                 <property name="userTransaction" ref="geronimo" />
>         </bean>
>
>         <bean id="jmsFactory"
> class="org.apache.activemq.ActiveMQXAConnectionFactory">
>                 <property name="brokerURL" value="tcp://localhost:5000" />
>                 <property name="userName" value="dispatcher1" />
>                 <property name="password" value="dpwd1" />
>         </bean>
>         <bean id="jmsConnectionFactory"
> class="org.jencks.pool.PooledSpringXAConnectionFactory">
>                 <property name="connectionFactory" ref="jmsFactory"/>
>                 <property name="jtaTransactionManager" ref="geronimoTransactionManager"/>
>         </bean>
>         <bean id="destination" class="org.apache.activemq.command.ActiveMQQueue">
>                 <constructor-arg value="messages.input"/>
>         </bean>
>         <bean id="listenerContainer"
> class="org.springframework.jms.listener.DefaultMessageListenerContainer">
>                 <property name="concurrentConsumers" value="1"/>
>                 <property name="maxMessagesPerTask" value="1"/>
>                 <property name="connectionFactory" ref="jmsConnectionFactory"/>
>                 <property name="destination" ref="destination"/>
>                 <property name="messageListener" ref="myMessageListener"/>
>                 <property name="transactionManager" ref="geronimoTransactionManager" />
>         </bean>
>
>      <bean id="myMessageListener" class="manager.broker.MyMessageListener"/>
>
> </beans>
>
> On consuming message I got:
>
> INFO  CollectionFactory                - JDK 1.4+ collections available
> INFO  XmlBeanDefinitionReader          - Loading XML bean definitions
> from file [/home/john/workspace/AMQ/conf/manager-simple.xml]
> INFO  FileSystemXmlApplicationContext  - Bean factory for application
> context
> [org.springframework.context.support.FileSystemXmlApplicationContext;hashCode=12282550]:
> org.springframework.beans.factory.support.DefaultListableBeanFactory
> defining beans
> [broker,transactionContextManager,geronimo,geronimoTransactionManager,jmsFactory,jmsConnectionFactory,destination,listenerContainer,myMessageListener];
> root of BeanFactory hierarchy
> INFO  FileSystemXmlApplicationContext  - 9 beans defined in application
> context
> [org.springframework.context.support.FileSystemXmlApplicationContext;hashCode=12282550]
> INFO  FileSystemXmlApplicationContext  - Unable to locate MessageSource
> with name 'messageSource': using default
> [org.springframework.context.support.DelegatingMessageSource@388993]
> INFO  FileSystemXmlApplicationContext  - Unable to locate
> ApplicationEventMulticaster with name 'applicationEventMulticaster':
> using default
> [org.springframework.context.event.SimpleApplicationEventMulticaster@18aaa1e]
> INFO  DefaultListableBeanFactory       - Pre-instantiating singletons in
> factory
> [org.springframework.beans.factory.support.DefaultListableBeanFactory
> defining beans
> [broker,transactionContextManager,geronimo,geronimoTransactionManager,jmsFactory,jmsConnectionFactory,destination,listenerContainer,myMessageListener];
> root of BeanFactory hierarchy]
> INFO  BrokerService                    - ActiveMQ null JMS Message
> Broker (localhost) is starting
> INFO  BrokerService                    - For help or more information
> please see: http://incubator.apache.org/activemq/
> INFO  TransportServerThreadSupport     - Listening for connections at:
> tcp://prokopiev.stc.donpac.ru:5000
> INFO  TransportConnector               - Connector
> tcp://prokopiev.stc.donpac.ru:5000 Started
> INFO  BrokerService                    - ActiveMQ JMS Message Broker
> (localhost, ID:prokopiev.stc.donpac.ru-58620-1155025769955-0:0) started
> INFO  JtaTransactionManager            - Using JTA UserTransaction:
> org.apache.geronimo.transaction.context.GeronimoTransactionManager@1afae45
> INFO  JtaTransactionManager            - Using JTA TransactionManager:
> org.apache.geronimo.transaction.context.GeronimoTransactionManager@1afae45
> INFO  ManagementContext                - JMX consoles can connect to
> service:jmx:rmi:///jndi/rmi://localhost:1099/jmxrmi
>
>
> ERROR DefaultMessageListenerContainer  - Execution of JMS message
> listener failed
> javax.jms.JMSException: Session's XAResource has not been enlisted in a
> distributed transaction.
>         at
> org.apache.activemq.ActiveMQXASession.doStartTransaction(ActiveMQXASession.java:109)
>         at
> org.apache.activemq.ActiveMQMessageConsumer.ackLater(ActiveMQMessageConsumer.java:658)
>         at
> org.apache.activemq.ActiveMQMessageConsumer.beforeMessageIsConsumed(ActiveMQMessageConsumer.java:610)
>         at
> org.apache.activemq.ActiveMQMessageConsumer.receive(ActiveMQMessageConsumer.java:469)
>         at
> org.springframework.jms.listener.DefaultMessageListenerContainer.doExecuteListener(DefaultMessageListenerContainer.java:301)
>         at
> org.springframework.jms.listener.DefaultMessageListenerContainer$1.doInTransactionWithoutResult(DefaultMessageListenerContainer.java:278)
>         at
> org.springframework.transaction.support.TransactionCallbackWithoutResult.doInTransaction(TransactionCallbackWithoutResult.java:33)
>         at
> org.springframework.transaction.support.TransactionTemplate.execute(TransactionTemplate.java:128)
>         at
> org.springframework.jms.listener.DefaultMessageListenerContainer.executeListener(DefaultMessageListenerContainer.java:275)
>         at
> org.springframework.jms.listener.DefaultMessageListenerContainer$AsyncMessageListenerInvoker.run(DefaultMessageListenerContainer.java:375)
>         at
> org.springframework.core.task.SimpleAsyncTaskExecutor$ConcurrencyThrottlingRunnable.run(SimpleAsyncTaskExecutor.java:203)
>         at java.lang.Thread.run(Thread.java:595)
>
> How can I enlist session in distributed transaction without JCA?
>
> --
> Thanks,
> Eugene Prokopiev
>
>


--

James
-------
http://radio.weblogs.com/0112098/
ENP
Reply | Threaded
Open this post in threaded view
|

Re: org.jencks.pool.PooledSpringXAConnectionFactory without full Jencks JCA support

ENP
>> Is it possible to use only
>> org.jencks.pool.PooledSpringXAConnectionFactory without full Jencks JCA
>> support for Spring Message Driven POJO?
>
>
> No. I'd recommend not trying to implement your own version of JCA.

I need only Message Driven POJO already implemented in Spring 2 without
JCA. I read http://issues.apache.org/activemq/browse/AMQ-303 and see
that PooledSpringXAConnectionFactory has currently been integrated into
Jencks. So I tried to use only this class withot JCA because Spring
context with Jencks JCA Message Driven POJO is more complex without
visible advantages.

Another declared Jencks advantage is pooling and reusing JMS sessions
and connections when sending messages. So, I write simple transactional
sending example but I can't see pooling and reusing JMS sessions and
connections :(

Example context is:

<beans>

        <bean id="transactionContextManager"
class="org.jencks.factory.TransactionContextManagerFactoryBean"/>
        <bean id="geronimo"
class="org.jencks.factory.GeronimoTransactionManagerFactoryBean"/>
        <bean id="geronimoTransactionManager"
class="org.springframework.transaction.jta.JtaTransactionManager">
                <property name="userTransaction" ref="geronimo" />
        </bean>

        <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>
                <property name="plugins">
                        <list>
                                <bean class="transactions.AuthenticationLogger"/>
                        </list>
                </property>
        </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="10"/>
                                <property name="minSize" value="10"/>
                                <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="jmsResourceAdapter"
class="org.apache.activemq.ra.ActiveMQResourceAdapter" depends-on="broker">
                <property name="serverUrl" value="tcp://localhost:5000"/>
        </bean>
        <bean id="jmsManagedConnectionFactory"
class="org.apache.activemq.ra.ActiveMQManagedConnectionFactory">
                <property name="resourceAdapter" ref="jmsResourceAdapter"/>
        </bean>
        <bean id="jmsConnectionFactory"
class="org.springframework.jca.support.LocalConnectionFactoryBean">
                <property name="managedConnectionFactory"
ref="jmsManagedConnectionFactory"/>
                <property name="connectionManager" ref="connectionManager"/>
     </bean>

     <bean id="messageSenderBeanProxy"
class="org.springframework.transaction.interceptor.TransactionProxyFactoryBean">
         <property name="transactionManager"
ref="geronimoTransactionManager"/>
         <property name="transactionAttributes">
             <props>
                 <prop key="*">PROPAGATION_REQUIRED</prop>
             </props>
         </property>
         <property name="target">
                        <bean class="transactions.MessageSenderBean">
                                <property name="jmsTemplate">
                                        <bean class="org.springframework.jms.core.JmsTemplate">
                                                <property name="connectionFactory" ref="jmsConnectionFactory"/>
                                        </bean>
                                </property>
                        </bean>
                </property>
                <property name="proxyTargetClass" value="true"/>
     </bean>

</beans>

AuthenticationLogger.java is:

public class AuthenticationLogger extends BrokerPluginSupport {
        private Log log = LogFactory.getLog(getClass());
        public void addConnection(ConnectionContext context, ConnectionInfo
info) throws Exception {
                log.info("add connection");
                super.addConnection(context, info);
        }
        public void removeConnection(ConnectionContext context, ConnectionInfo
info, Throwable error) throws Exception {
                log.info("remove connection");
                super.removeConnection(context, info, error);
        }
}

MessageSenderBean.java is:

public class MessageSenderBean {
        private JmsTemplate jmsTemplate;
        public void setJmsTemplate(JmsTemplate jmsTemplate) {
                this.jmsTemplate = jmsTemplate;
        }
        public void send() {
                jmsTemplate.convertAndSend("test", "Hello!");
        }
}

This test application can be started with:

public class TestBoot {
        public static void main(String[] args) throws InterruptedException {
                AbstractApplicationContext ctx =
                        new ClassPathXmlApplicationContext(new String []{
                                "transactions/context-outbound.xml"});
                ctx.registerShutdownHook();
                MessageSenderBean bean = (MessageSenderBean)
                        ctx.getBean("messageSenderBeanProxy");
                bean.send();
                bean.send();
                Thread.sleep(1000);
                ctx.close();
        }
}

On starting it I got:

INFO  CollectionFactory - JDK 1.4+ collections available
INFO  XmlBeanDefinitionReader - Loading XML bean definitions from class
path resource [transactions/context-outbound.xml]
INFO  ClassPathXmlApplicationContext - Bean factory for application
context
[org.springframework.context.support.ClassPathXmlApplicationContext;hashCode=30079646]:
org.springframework.beans.factory.support.DefaultListableBeanFactory
defining beans
[transactionContextManager,geronimo,geronimoTransactionManager,broker,connectionManager,jmsResourceAdapter,jmsManagedConnectionFactory,jmsConnectionFactory,messageSenderBeanProxy];
root of BeanFactory hierarchy
INFO  ClassPathXmlApplicationContext - 9 beans defined in application
context
[org.springframework.context.support.ClassPathXmlApplicationContext;hashCode=30079646]
INFO  ClassPathXmlApplicationContext - Unable to locate MessageSource
with name 'messageSource': using default
[org.springframework.context.support.DelegatingMessageSource@15ee671]
INFO  ClassPathXmlApplicationContext - Unable to locate
ApplicationEventMulticaster with name 'applicationEventMulticaster':
using default
[org.springframework.context.event.SimpleApplicationEventMulticaster@329f3d]
INFO  DefaultListableBeanFactory - Pre-instantiating singletons in
factory
[org.springframework.beans.factory.support.DefaultListableBeanFactory
defining beans
[transactionContextManager,geronimo,geronimoTransactionManager,broker,connectionManager,jmsResourceAdapter,jmsManagedConnectionFactory,jmsConnectionFactory,messageSenderBeanProxy];
root of BeanFactory hierarchy]
INFO  BrokerService - ActiveMQ null JMS Message Broker (localhost) is
starting
INFO  BrokerService - For help or more information please see:
http://incubator.apache.org/activemq/
INFO  TransportServerThreadSupport - Listening for connections at:
tcp://prokopiev.stc.donpac.ru:5000
INFO  TransportConnector - Connector tcp://prokopiev.stc.donpac.ru:5000
Started
INFO  BrokerService - ActiveMQ JMS Message Broker (localhost,
ID:prokopiev.stc.donpac.ru-58753-1155032029354-0:0) started
INFO  DefaultAopProxyFactory - CGLIB2 available: proxyTargetClass
feature enabled
INFO  ManagementContext - JMX consoles can connect to
service:jmx:rmi:///jndi/rmi://localhost:1099/jmxrmi
INFO  JtaTransactionManager - Using JTA UserTransaction:
org.apache.geronimo.transaction.context.GeronimoTransactionManager@5dd582
INFO  JtaTransactionManager - Using JTA TransactionManager:
org.apache.geronimo.transaction.context.GeronimoTransactionManager@5dd582
INFO  AuthenticationLogger - add connection
INFO  AuthenticationLogger - remove connection
INFO  AuthenticationLogger - add connection
INFO  AuthenticationLogger - remove connection
INFO  ClassPathXmlApplicationContext - Closing application context
[org.springframework.context.support.ClassPathXmlApplicationContext;hashCode=30079646]
INFO  DefaultListableBeanFactory - Destroying singletons in factory
{org.springframework.beans.factory.support.DefaultListableBeanFactory
defining beans
[transactionContextManager,geronimo,geronimoTransactionManager,broker,connectionManager,jmsResourceAdapter,jmsManagedConnectionFactory,jmsConnectionFactory,messageSenderBeanProxy];
root of BeanFactory hierarchy}
INFO  BrokerService - ActiveMQ Message Broker (localhost,
ID:prokopiev.stc.donpac.ru-58753-1155032029354-0:0) is shutting down
INFO  TransportConnector - Connector tcp://prokopiev.stc.donpac.ru:5000
Stopped
INFO  VMTransportFactory - Shutting down VM connectors for broker: localhost
INFO  BrokerService - ActiveMQ JMS Message Broker (localhost,
ID:prokopiev.stc.donpac.ru-58753-1155032029354-0:0) stopped

So, connection is opening and closing on every transaction. Have I error
in my configuration or this behavior is rigth?

--
Thanks,
Eugene Prokopiev