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 [EMAIL PROTECTED] INFO ClassPathXmlApplicationContext - Unable to locate ApplicationEventMulticaster with name 'applicationEventMulticaster': using default [EMAIL PROTECTED] 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: [EMAIL PROTECTED] INFO JtaTransactionManager - Using JTA TransactionManager: [EMAIL PROTECTED]
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

Reply via email to