Issue with CachingConnectionFactory and DefaultMessageListenerContainer - java

It is mentioned in the documentation of DefaultMessageListenerContainer class that it is not recommended to use CachingConnectionFactory with dynamic scaling. While searching, I have encountered following link:
Why DefaultMessageListenerContainer should not use CachingConnectionFactory?
Here found a comment from Gary Russell that
the problem is with caching consumers when using variable concurrency in the container; we can end up with a live consumer "stuck" in the cache".
We have used DefaultMessageListenerContainer and CachingConnectionFactory together so this is surely a problem from above link.
We are encountering problems with our application having following behaviour:
TCP ZeroWindow network congestion
TCP RESET from application server to MQ
DB connection grows during the issue while different transactions halt
Messages in certain queues gets built up
We have following code configuration :
In ibmmq-context.xml file:
<!-- WebSphere MQ Connection Factory -->
<bean id="appMqConnectionFactory" class="com.ibm.mq.jms.MQConnectionFactory">
<property name="hostName">
<value>${ibmmq.ip}</value>
</property>
<property name="port">
<value>${ibmmq.port}</value>
</property>
<property name="queueManager">
<value>${ibmmq.queuemanager}</value>
</property>
<property name="channel">
<value>${ibmmq.channel}</value>
</property>
<property name="clientReconnectOptions">
<util:constant static-field="com.ibm.msg.client.wmq.WMQConstants.WMQ_CLIENT_RECONNECT"/>
</property>
<property name="transportType" ref="appTransport"/>
</bean>
<!-- A cached connection -->
<bean id="appCachedConnectionFactory" class="org.springframework.jms.connection.CachingConnectionFactory">
<property name="targetConnectionFactory" ref="appMqConnectionFactory"/>
<property name="sessionCacheSize" value="${jms.session.cachesize}"/>
</bean>
<!-- Use native MQ classes. -->
<bean id="appTransport" class="org.springframework.beans.factory.config.FieldRetrievingFactoryBean">
<property name="staticField">
<value>com.ibm.mq.jms.JMSC.MQJMS_TP_CLIENT_MQ_TCPIP</value>
</property>
</bean>
In jms-context file:
<bean id="bankListener" class="org.springframework.jms.listener.DefaultMessageListenerContainer">
<property name="connectionFactory" ref="cachedConnectionFactory" />
<property name="destination" ref="transactionResponseDestination" />
<property name="messageListener" ref="thirdpartyService" />
<property name="autoStartup" value="false"/>
<property name="taskExecutor" ref="listenerExecutor"/>
<property name="concurrency" value="20-30"/>
</bean>
There are 6 such listeners like bankListener and each of the listeners has concurrency value, varies from 10-40
<bean id="listenerExecutor" class="org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor">
<property name="maxPoolSize" value="140"/>
<property name="corePoolSize" value="100"/>
<property name="queueCapacity" value="30"/>
<property name="threadNamePrefix" value="jms-listener-task-"/>
<property name="threadGroupName" value="jms-listener-tasks"/>
</bean>
and jms-context.xml file uses ibmmq-context.xml file.
And to note, we have used IBM MQ 7.1, Spring 4.2.8, spring-integration-core as 4.3.1.RELEASE and JBoss EAP 6.4.10
We are planning to fix this by following way:
<bean id="bankListener" class="org.springframework.jms.listener.DefaultMessageListenerContainer">
<property name="connectionFactory" ref="appMqConnectionFactory" />
<property name="destination" ref="transactionResponseDestination" />
<property name="messageListener" ref="thirdpartyService" />
<property name="autoStartup" value="false"/>
<property name="taskExecutor" ref="listenerExecutor"/>
<property name="concurrency" value="20-30"/>
</bean>
My request:
Please review the configuration and let me know is there anything else to be changed.
Could you please also explain our application behaviour(above 4 points - a to d) with our current configuration with CachingConnectionFactory and DefaultMessageListenerContainer
Thanks in advance for your help.

Try setting:
cachingConnectionFactory.setCacheConsumers(false);
Or in Spring it should be:
<bean id="appCachedConnectionFactory" class="org.springframework.jms.connection.CachingConnectionFactory">
...
<property name="cacheConsumers" value="false"/>
...
</bean>

Related

Messages are getting stuck in activemq queue

Activemq version: 5.14.3
Java version 1.7
There are 8 consumers for one queue, messages are stuck in some of the consumers.
In the above image messages are stuck in dispatched queue of first 4 consumer.
Here is my spring configuration file.
<bean id="connectionFactory" class="org.apache.activemq.ActiveMQConnectionFactory">
<property name="brokerURL" value="failover:(tcp://localhost:61616,tcp://localhost:61617)?randomize=false"/>
</bean>
<bean id="cachingFactory" class="org.springframework.jms.connection.CachingConnectionFactory">
<property name="targetConnectionFactory" ref="connectionFactory"/>
</bean>
<bean id="jmsTemplate" class="org.springframework.jms.core.JmsTemplate">
<property name="connectionFactory" ref="connectionFactory"/>
<property name="defaultDestinationName" value="queue/WebHookProcessingQueue"/>
</bean>
<bean id="myMessageSender" class="com.omoto.jms.sender.MyMessageSender">
<property name="jmsTemplate">
<ref bean="jmsTemplate"/>
</property>
</bean>
<bean id="responseJsonMessageListenerContainer" class="org.springframework.jms.listener.DefaultMessageListenerContainer">
<property name="connectionFactory" ref="cachingFactory"/>
<property name="destinationName" value="/queue/ResponseJsonProcessingQueue"/>
<property name="concurrentConsumers" value="8"/>
<property name="messageListener" ref="responseJsonServiceListner"/>
</bean>
I am new to activemq, please help me to solve this problem.
We had similar issue with CachingConnectionFactory with DefaultMessageListenerContainer, the issue is resolved after removing the CachingConnectionFactory from DefaultMessageListenerContainer. Alternatively you can disable consumer caching from CachingConnectionFactory . Refer this thread for more info Why DefaultMessageListenerContainer should not use CachingConnectionFactory?.

Apache Ignite nodes fail: Failed to read magic header

Apache Ignite servers deployed on two machines automatically shut down. No concrete clue in logs. I am able to see following warning message in log file :
[00:35:14,047][WARNING][tcp-disco-sock-reader-#86379%null%][TcpDiscoverySpi] Failed to read magic header (too few bytes received) [rmtAddr=/10.96.36.48:47830, locAddr=/10.96.36.48:47500]
How can i debug and solve this issue ?
Configuration:
<bean id="grid.cfg" class="org.apache.ignite.configuration.IgniteConfiguration">
<property name="peerClassLoadingEnabled" value="true"/>
<property name="cacheConfiguration">
<list>
<bean class="org.apache.ignite.configuration.CacheConfiguration">
<property name="name" value="xyxCache" />
<property name="writeSynchronizationMode" value="FULL_SYNC" />
<property name="cacheMode" value="REPLICATED" />
<property name="rebalanceMode" value="SYNC" />
<property name="readFromBackup" value="true" />
<property name="startSize" value="150000" />
<property name="evictionPolicy">
<bean class="org.apache.ignite.cache.eviction.lru.LruEvictionPolicy">
<property name="maxSize" value="1000000" />
</bean>
</property>
</bean>
</list>
</property>
<property name="discoverySpi">
<bean class="org.apache.ignite.spi.discovery.tcp.TcpDiscoverySpi">
<property name="ipFinder">
<bean class="org.apache.ignite.spi.discovery.tcp.ipfinder.multicast.TcpDiscoveryMulticastIpFinder">
<property name="addresses">
<list>
<value>10.96.36.48:47500</value>
<value>10.96.36.214:47500</value>
</list>
</property>
</bean>
</property>
</bean>
</property>
</bean>
Check which process on 10.96.36.48 machine binded to port 47830.
For example, netstat -lnp will list the pid and process name next to each listening port. This will work under Linux.
This usually happens if some other application like telnet connects to the port.
Please share your configuration and setup details, without which it is not possible to answer any further.

RMI Configuration in JBoss 7

Our current application is configured using RMI protocol. Now we are migrating the same on JBoss7.2 and JDK 1.7 versons. Since JBoss 7 has removed the support of RMI, could any one help on this a how can we configure RMI in JBoss 7?
Below one is code snippet -
Service configuration -
<bean id="claimsOSRMIRegistry" class="org.springframework.remoting.rmi.RmiRegistryFactoryBean">
<property name="port" value="${rmi.port}" />
</bean>
<!-- Exposing RMI services starts -->
<bean id="reportedClaimService" class="org.springframework.remoting.rmi.RmiServiceExporter">
<property name="serviceName" value="${context.root}ReportedClaimService"/>
<property name="service">
<ref bean="reportedClaimServiceProxy" />
</property>
<property name="serviceInterface" value="com.claimsos.claim.ReportedClaimService"/>
<property name="registry">
<ref bean="claimsOSRMIRegistry"/>
</property>
<property name="registerTraceInterceptor" value="false"/>
</bean>
Client Configuration -
<bean id="reportedClaimService" class="org.springframework.remoting.rmi.RmiProxyFactoryBean">
<property name="serviceUrl"
value="${rmi.service.location}ReportedClaimService" />
<property name="serviceInterface"
value="com.claimsos.claim.ReportedClaimService" />
<property name="lookupStubOnStartup" value="false" />
<property name="refreshStubOnConnectFailure" value="true" />
</bean>
Here is my RMI port configuration -
rmi.port=1199
rmi.service.location=rmi://localhost:${rmi.port}/${context.root}
If any one has any suggestion or have come a crossed this, Please do share.

Spring Routing-source and connection pooling

I am using spring Routing data source as explained here and things works well. Now, I want to add connection pooling (Apache DBCP). I changed the basic data source to the connection pool data source. well, It does not work.
On the server start-up I see that connection pooling is happening and I can debug Apache's code, but then, when I am trying to access the DB through my code, I go to the routing data source, and from there to the DriverManager class to get a connection - completely ignoring Apache's code.
<bean id="catalogDataSource"
class="org.springframework.jdbc.datasource.DriverManagerDataSource">
<property name="driverClassName" value="${jdbc.driverClass}" />
<property name="url" value="${jdbc.url}" />
<property name="username" value="${jdbc.user}" />
<property name="password" value="${jdbc.pwd}" />
</bean>
<bean id="pool" class="org.apache.commons.pool.impl.GenericObjectPool">
<property name="minEvictableIdleTimeMillis"><value>300000</value></property>
<property name="timeBetweenEvictionRunsMillis"><value>60000</value></property>
</bean>
<bean id="dsConnectionFactory" class="org.apache.commons.dbcp.DataSourceConnectionFactory">
<constructor-arg><ref bean="catalogDataSource"/></constructor-arg>
</bean>
<bean id="poolableConnectionFactory" class="org.apache.commons.dbcp.PoolableConnectionFactory">
<constructor-arg index="0"><ref bean="dsConnectionFactory"/></constructor-arg>
<constructor-arg index="1"><ref bean="pool"/></constructor-arg>
<constructor-arg index="2"><null/></constructor-arg>
<constructor-arg index="3"><null/></constructor-arg>
<constructor-arg index="4"><value>false</value></constructor-arg>
<constructor-arg index="5"><value>true</value></constructor-arg>
</bean>
<bean id="pooledDS" class="org.apache.commons.dbcp.PoolingDataSource" depends-on="poolableConnectionFactory">
<constructor-arg><ref bean="pool"/></constructor-arg>
</bean>
<bean id="routingDataSource" class="something that derived from RoutingDataSource">
<property name="defaultTargetDataSource" ref="pooledDS"/>
<property name="targetDataSources">
<map key-type="java.lang.Integer">
</map>
</property>
</bean>
Can you help me please - what did I do wrong?

JMS + Spring Integration + ActiveMQ ! Not working on JVM but working on activeMQ server

Create connection factory where broker url to JVM
<!--tcp://localhost:61616-->
<bean id="connectionFactoryActiveMQ" class="org.apache.activemq.ActiveMQConnectionFactory">
<property name="brokerURL" value="vm://localhost"/>
<property name="useAsyncSend" value="true"/>
</bean>
Create single connection factory becose need one connection
<bean id="connectionFactory" class="org.springframework.jms.connection.SingleConnectionFactory">
<property name="targetConnectionFactory" ref="connectionFactoryActiveMQ"/>
</bean>
create topic destination because need implemented some classes
<bean id="destination" class="org.apache.activemq.command.ActiveMQTopic">
<property name="physicalName" value="TEST"/>
</bean>
Generate jmsTemplate object
<bean id="jmsTemplate" class="org.springframework.jms.core.JmsTemplate">
<property name="connectionFactory" ref="connectionFactory"/>
<property name="defaultDestination" ref="destination"/>
<property name="pubSubDomain" value="true"/>
</bean>
My classes who receive messages
<bean id="messageListener1" class="com.aimrposoft.jms.server.Server"/>
<bean id="messageListener2" class="com.aimrposoft.jms.server.Server1"/>
<bean id="messageListener3" class="com.aimrposoft.jms.server.Server2"/>
Generate message class
<bean id="producer" class="com.aimrposoft.jms.client.Producer"/>
<!--<bean id="jmsContainer" class="org.springframework.jms.listener.DefaultMessageListenerContainer">-->
<!--<property name="connectionFactory" ref="connectionFactory"/>-->
<!--<property name="destination" ref="destination"/>-->
<!--<property name="messageListener" ref="messageListener1"/>-->
<!--</bean>-->
<jms:listener-container
connection-factory="connectionFactory" destination-type="topic" acknowledge="transacted">
<jms:listener destination="TEST" ref="messageListener1" method="onMessage" subscription="subscription"/>
<jms:listener destination="TEST" ref="messageListener2" method="onMessage" subscription="subscription"/>
<jms:listener destination="TEST" ref="messageListener3" method="onMessage" subscription="subscription"/>
</jms:listener-container>
When I am using vm://localhost message listener don't working correctly, but if I run activeMQ and change broker URL to tcp://localhost:61616, all work is fine.
I think you are missing configuration to start up a embedded broker, can you try adding this to your configuration also:
<amq:broker id="activeMQBroker">
<amq:transportConnectors>
<amq:transportConnector uri="vm://localhost" />
</amq:transportConnectors>
</amq:broker>
amq namespace prefix can be defined this way:
xmlns:amq="http://activemq.apache.org/schema/core"
To further Biju's answer, I use queues not topics, here's my spring config that appears to work just fine (62999 is just a random available port number):
<amq:broker useJmx="false" persistent="false">
<amq:transportConnectors>
<amq:transportConnector uri="tcp://localhost:62999" />
</amq:transportConnectors>
</amq:broker>
<bean id="rawConnectionFactory" class="org.apache.activemq.ActiveMQConnectionFactory">
<property name="brokerURL" value="vm://localEmbeddedBroker" />
</bean>
<bean id="connectionFactory" class="org.springframework.jms.connection.CachingConnectionFactory">
<property name="targetConnectionFactory" ref="rawConnectionFactory" />
<property name="sessionCacheSize" value="30" />
<property name="cacheProducers" value="true" />
<property name="cacheConsumers" value="false" />
</bean>

Categories