P E N C I L
Login

Example spring context

Note: CachingConnectionFactory automatically setReconnectOnException (so if JMS broker is restart). You will see in the log (not autoreconnect but it's not true)

Established shared JMS Connection: BrokerAddress=sandbox.swissquote.ch:7676(37000), ConnectionID=3826737482566351104, ReconnectEnabled: false, IsConnectedToHABroker: 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>

 

<!-- JMS TEMPLATE SENDER-->

    <bean id="jmsTemplate" class="org.springframework.jms.core.JmsTemplate">
        <property name="connectionFactory" ref="push.connectionFactory_cached" />
        <property name="defaultDestination" ref="push.jms.queue" />
    </bean>


    <!-- MESSAGE LISTENER -->
    <bean id="push.pushJmsMessageListener" class="com.swissquote.mobile.services.push.test.services.MockPushJmsMessageListener" />
    <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>