P E N C I L
Login

Spring context

  1. ConnectionFactory => Authenticated Connection Factory => Cached Connection Factory
  2. Performance
    1. Cache connection factory: cache conection AND set auto reconnect
    2. DefaultMessageListenerContainer: handle Onmessgae multiple thread & cache level consumer cache the connection & session 1 per thread
  3.  

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="  ">http://www.springframework.org/schema/beans"
  
 xmlns:util="http://www.springframework.org/schema/util" xmlns:xsi="  ">http://www.w3.org/2001/XMLSchema-instance"
  
 xsi:schemaLocation="
        http://www.springframework.org/schema/beans 
  
     http://www.springframework.org/schema/beans/spring-beans.xsd
  
     http://www.springframework.org/schema/util
  
       ">http://www.springframework.org/schema/util/spring-util.xsd"
  
 default-lazy-init="false">

    <!-- QUEUE -->
    <bean id="push.jms.jndiTemplate" class="org.springframework.jndi.JndiTemplate">
        <property name="environment">
            <util:map>
                <entry key="java.naming.factory.initial" value="com.sun.jndi.fscontext.RefFSContextFactory" />
                <entry key="java.naming.provider.url"
                    value="${jms.queue.queueFromIalertsToPostfinance > binding.file}" />
            </util:map>
        </property>
    </bean>

    <bean id="push.jms.queue" class="org.springframework.jndi.JndiObjectFactoryBean">
        <property name="jndiTemplate" ref="push.jms.jndiTemplate" />
        <property name="jndiName"
            value="${jms.queue.queueFromIalertsToPostfinance > name}" />
    </bean>

    <!-- CONNECTION FACTORIES -->
    <bean id="push.connectionFactory_noauth" class="org.springframework.jndi.JndiObjectFactoryBean">
        <property name="jndiTemplate" ref="push.jms.jndiTemplate" />
        <property name="jndiName"
            value="${jms.queue.queueFromIalertsToPostfinance > connection.factory}" />
    </bean>

    <bean id="push.connectionFactory_auth"
        class="org.springframework.jms.connection.UserCredentialsConnectionFactoryAdapter">
        <property name="targetConnectionFactory" ref="push.connectionFactory_noauth" />
        <property name="username"
            value="${jms.queue.queueFromIalertsToPostfinance > username}" />
        <property name="password"
            value="${jms.queue.queueFromIalertsToPostfinance > password}" />
    </bean>

    <bean id="push.connectionFactory_cached"
        class="org.springframework.jms.connection.CachingConnectionFactory">
        <property name="targetConnectionFactory" ref="push.connectionFactory_auth" />
    </bean>


    <!-- MESSAGE LISTENER -->
    <bean id="push.pushJmsMessageListener" class="com.swissquote.mobile.push.jms.PushJmsMessageListener" />
    <bean id="push.jms.messageListenerContainer"
        class="org.springframework.jms.listener.DefaultMessageListenerContainer">
        <property name="cacheLevelName" value="CACHE_CONSUMER" />  <!-- Cache a shared JMS connection and Session for each listener thread -->
        <property name="concurrentConsumers" value="1" />
        <property name="maxConcurrentConsumers"
            value="${jms.queue.queueFromIalertsToPostfinance > maxConcurrentConsumers}" />
        <property name="connectionFactory" ref="push.connectionFactory_cached" />
        <property name="destination" ref="push.jms.queue" />
        <property name="messageListener" ref="push.pushJmsMessageListener" />
        <property name="autoStartup" value="true" />
    </bean>

</beans>