Spring singleton scope isn't working in spring-integration application - spring

I have a spring-integration application with the following configuration :
<beans:bean id="customMessageListenerContainer" class="org.springframework.jms.listener.DefaultMessageListenerContainer" scope = "singleton">
<beans:property name="errorHandler" ref="customErrorHandler"/>
<beans:property name="connectionFactory" ref="connectionFactory" />
<beans:property name="destination" ref="jmsInputQueueXssl" />
<beans:property name="sessionTransacted" value="true" />
<beans:property name="maxConcurrentConsumers" value="1" />
<beans:property name="concurrentConsumers" value="1" />
<beans:property name="receiveTimeout" value="5000" />
<beans:property name="recoveryInterval" value="60000" />
<beans:property name="autoStartup" value="true" />
<beans:property name="exposeListenerSession" value="false" />
<beans:property name="subscriptionDurable" value="true" />
<beans:property name="durableSubscriptionName" value="${ibm.jms.subscription.id1}" />
<beans:property name="backOff" ref="myBackoff" />
</beans:bean>
<beans:bean id="myBackoff" class="c.h.i.c.d.x.j.MyFixedBackOff">
<beans:constructor-arg index="0" value="5000"/>
<beans:constructor-arg index="1" value="5"/>
</beans:bean>
<!-- Custom error handler -->
<beans:bean id="customErrorHandler" class="c.h.i.c.d.x.j.XsslCustomErrorHandler" />
<beans:beans profile="env">
<jms:message-driven-channel-adapter
id="jmsInboundAdapterXssl" channel="channel2"
acknowledge="transacted" error-channel="errorChannel"
container="customMessageListenerContainer"/>
</beans:beans>
However, it seems that there are several instances of that class customMessageListenerContainer if I read the logs :
2019-05-10 17:54:39,783 INFO [main] o.s.i.e.SourcePollingChannelAdapter [AbstractEndpoint.java:97] started org.springframework.integration.config.SourcePollingChannelAdapterFactoryBean#0
2019-05-10 17:54:39,783 INFO [main] o.s.c.s.DefaultLifecycleProcessor [DefaultLifecycleProcessor.java:341] Starting beans in phase 2147483647
2019-05-10 17:54:39,924 INFO [customMessageListenerContainer-1] c.h.i.c.d.x.j.MyFixedBackOff [MyFixedBackOff.java:115] MyFixedBackOff currentAttempts = 0
2019-05-10 17:54:44,930 WARN [customMessageListenerContainer-1] o.s.j.l.DefaultMessageListenerContainer [DefaultMessageListenerContainer.java:871] Setup of JMS message listener invoker failed for destination 'queue:///CT_XSSL.CT_CPMX.MRZC_DGRM.0013' - trying to recover. Cause: JMSWMQ2008: Failed to open MQ queue 'CT_XSSL.CT_CPMX.MRZC_DGRM.0013'.; nested exception is com.ibm.mq.MQException: JMSCMQ0001: WebSphere MQ call failed with compcode '2' ('MQCC_FAILED') reason '2085' ('MQRC_UNKNOWN_OBJECT_NAME').
2019-05-10 17:54:44,930 INFO [customMessageListenerContainer-1] o.s.j.l.DefaultMessageListenerContainer [DefaultMessageListenerContainer.java:921] Successfully refreshed JMS Connection
2019-05-10 17:54:44,930 INFO [customMessageListenerContainer-2] c.h.i.c.d.x.j.MyFixedBackOff [MyFixedBackOff.java:115] MyFixedBackOff currentAttempts = 0
2019-05-10 17:54:49,938 WARN [customMessageListenerContainer-2] o.s.j.l.DefaultMessageListenerContainer [DefaultMessageListenerContainer.java:871] Setup of JMS message listener invoker failed for destination 'queue:///CT_XSSL.CT_CPMX.MRZC_DGRM.0013' - trying to recover. Cause: JMSWMQ2008: Failed to open MQ queue 'CT_XSSL.CT_CPMX.MRZC_DGRM.0013'.; nested exception is com.ibm.mq.MQException: JMSCMQ0001: WebSphere MQ call failed with compcode '2' ('MQCC_FAILED') reason '2085' ('MQRC_UNKNOWN_OBJECT_NAME').
2019-05-10 17:54:49,938 INFO [customMessageListenerContainer-2] o.s.j.l.DefaultMessageListenerContainer [DefaultMessageListenerContainer.java:921] Successfully refreshed JMS Connection
2019-05-10 17:54:49,953 INFO [customMessageListenerContainer-3] c.h.i.c.d.x.j.MyFixedBackOff [MyFixedBackOff.java:115] MyFixedBackOff currentAttempts = 0
2019-05-10 17:54:54,962 WARN [customMessageListenerContainer-3] o.s.j.l.DefaultMessageListenerContainer [DefaultMessageListenerContainer.java:871] Setup of JMS message listener invoker failed for destination 'queue:///CT_XSSL.CT_CPMX.MRZC_DGRM.0013' - trying to recover. Cause: JMSWMQ2008: Failed to open MQ queue 'CT_XSSL.CT_CPMX.MRZC_DGRM.0013'.; nested exception is com.ibm.mq.MQException: JMSCMQ0001: WebSphere MQ call failed with compcode '2' ('MQCC_FAILED') reason '2085' ('MQRC_UNKNOWN_OBJECT_NAME').
2019-05-10 17:54:54,962 INFO [customMessageListenerContainer-3] o.s.j.l.DefaultMessageListenerContainer [DefaultMessageListenerContainer.java:921] Successfully refreshed JMS Connection
How can I make customMessageListenerContainer effectively a singleton ?

What makes you think it's not a singleton?
If you mean the thread names are incrementing (customMessageListenerContainer-2 etc), it's because by default a SimpleAsyncTaskExecutor is used and a new thread is used after each failure (and the previous one terminates).
You can change the executor to a different implementation (e.g. thread pool) if you want.
Singleton is the default scope.

Related

Not able to Stop MQueue listener

I have the following configuration for my MQueue:
<jms:listener-container container-type="default" connection-factory="cachedConnectionFactory" acknowledge="auto">
<jms:listener id="myListenerId" destination="myDestination" ref="myListener" method="onMessage" />
</jms:listener-container>
When I try to stop the reception of JMS messages, I write the following code
jmsManagement = myProject.instance.getContext().getBean('myListenerId',Lifecycle.class);
jmsManagement.stop();
PS :
When I stop() my listener, the isRunning() return False, but I still get messages through the MQueue... the onMessage gets triggered.
jmsManagement is an instance of the class Lifecycle. Even when I changed it to DefaultMessageListenerContainer, same thing.
I'm receiving messages before calling start(), even when autoStartup is set to false.
jmsManagement.shutdown(); didn't stop the listener from being triggered.
Does anyone have an idea about how to stop this MQ listener ?
Is there something I'm missing ?
I actually had to set autoStartup to true.
Since I can't do that using jms:listener-container, I instanciated a DefaultMessageListenerContainer bean and set the autoStartup property to false.
Here's the code that worked for me :
<bean class="org.springframework.jms.listener.DefaultMessageListenerContainer" id="pitagorCPYListener">
<property name="autoStartup" value="false" />
<property name="connectionFactory" ref="cachedConnectionFactory" />
<property name="destination" ref="defaultDestination" />
<property name="messageListener" ref="listenerPitagorCPY" />
</bean>
<bean id="defaultDestination" class="com.ibm.mq.jms.MQQueue">
<constructor-arg value="#{mqConnectionFactory.destination}"/>
</bean>

Retry is not working in spring-AMQPwith Rabbitmq

am trying to retry 3 times if any exception comes while consuming message from rabbitmq,but it is not stopping after 3 times,contineously retrying n number of times.
can anybody help me on this please
thanks in advance
Config.xml
<!-- Provides connection to the RabbitMQ broker -->
<bean id="connectionFactoryRabbit"
class="org.springframework.amqp.rabbit.connection.CachingConnectionFactory"
p:username="guest" p:password="guest" p:port="5672">
<constructor-arg value="localhost" />
</bean>
<bean id="rabbitTemplate" class="org.springframework.amqp.rabbit.core.RabbitTemplate"
p:connectionFactory-ref="connectionFactoryRabbit">
</bean>
<bean id="messageConverter"
class="org.springframework.amqp.support.converter.SimpleMessageConverter">
<property name="createMessageIds" value="true" />
</bean>
<!-- A template for sending messages and performing other commands to RabbitMQ -->
<bean
class="org.springframework.amqp.rabbit.listener.SimpleMessageListenerContainer"
p:connectionFactory-ref="connectionFactoryRabbit" p:queueNames="TEST"
p:messageListener-ref="messageListener">
<!-- <property name="txSize" value="3" /> -->
<property name="prefetchCount" value="100" />
<property name="messageListener" ref="messageListenerAdapter" />
<property name="adviceChain" ref="retryChain" />
<!-- <property name="adviceChain" ref="retryInterceptor"></property> -->
</bean>
<!-- <rabbit:queue id="adt" name="TEST" /> <rabbit:queue id="adt"> <rabbit:queue-arguments>
<entry key="x-dead-letter-queue" value="dead" /> </rabbit:queue-arguments>
</rabbit:queue> <rabbit:direct-queue name="dead"> <rabbit:bindings> <rabbit:binding
queue="dead" key="dead" /> </rabbit:bindings> </rabbit:direct-queue> -->
<util:list id="retryChain">
<bean class="org.springframework.amqp.rabbit.retry.MissingMessageIdAdvice">
<constructor-arg>
<bean class="org.springframework.retry.policy.MapRetryContextCache" />
</constructor-arg>
</bean>
<ref bean="retryInterceptor" />
</util:list>
<bean id="retryInterceptor"
class="org.springframework.amqp.rabbit.config.StatelessRetryOperationsInterceptorFactoryBean">
<property name="messageRecoverer" ref="rejectAndDontRequeueRecoverer" />
<property name="retryOperations" ref="retryTemplate" />
</bean>
<bean id="messageListenerAdapter"
class="org.springframework.amqp.rabbit.listener.adapter.MessageListenerAdapter">
<property name="delegate" ref="writeToFileHandler" />
<property name="messageConverter" ref="messageConverter" />
</bean>
<bean id="writeToFileHandler" class="com.gnax.sola.jms.AmqpConsumer">
</bean>
<bean id="rejectAndDontRequeueRecoverer"
class="org.springframework.amqp.rabbit.retry.RejectAndDontRequeueRecoverer" />
<!-- <bean id="missingMessageId" class="org.springframework.amqp.rabbit.retry.MissingMessageIdAdvice"
/> -->
<bean id="retryTemplate" class="org.springframework.retry.support.RetryTemplate">
<property name="backOffPolicy">
<bean class="org.springframework.retry.backoff.ExponentialBackOffPolicy">
<property name="initialInterval" value="500" />
<property name="multiplier" value="2" />
<property name="maxInterval" value="30000" />
</bean>
</property>
<property name="retryPolicy">
<bean class="org.springframework.retry.policy.SimpleRetryPolicy">
<property name="maxAttempts" value="3" />
</bean>
</property>
</bean>
<bean id="messageListener" class="com.test.amqp.AmqpConsumer" />
<!-- This helps in configuring the AMQP broker, like creating a new queue -->
<bean id="amqpAdmin" class="org.springframework.amqp.rabbit.core.RabbitAdmin">
<constructor-arg ref="connectionFactoryRabbit" />
</bean>
consumer code
public void onMessage ( Message message, Channel channel ) throws Exception
{
try
{
if ( message != null && message.getMessageProperties ().getReceivedRoutingKey () != null )
{
system.out.println(message);
}
}
catch ( Exception e )
{
LOGGER.error ( "Error while consuming the message ", e );
channel.basicNack ( message.getMessageProperties ().getDeliveryTag (), true, true );
}
}
debug log
at [Source: java.io.StringReader#d998aa1; line: 1, column: 15]
11:42:41,228 INFO [com.gnax.sola.jms.AmqpConsumer] (SimpleAsyncTaskExecutor-5) Proccessed the message from AMQP
11:42:41,448 INFO [com.gnax.sola.imagemanager.jms.ADTRequestHandler] (SimpleAsyncTaskExecutor-5) Consuming ADT Message
11:42:41,448 INFO [com.gnax.sola.imagemanager.jms.ADTRequestHandler] (SimpleAsyncTaskExecutor-5) Error while receiving ADT Message
11:42:41,448 ERROR [com.gnax.sola.imagemanager.jms.ADTRequestHandler] (SimpleAsyncTaskExecutor-5) Unrecognized token 'fgffgfd': was expecting
at [Source: java.io.StringReader#2f852217; line: 1, column: 15]
11:42:41,448 INFO [com.gnax.sola.jms.AmqpConsumer] (SimpleAsyncTaskExecutor-5) Proccessed the message from AMQP
11:42:41,448 WARN [org.springframework.amqp.rabbit.listener.SimpleMessageListenerContainer] (SimpleAsyncTaskExecutor-5) Consumer raised exception, processing can restart if the connection factory supports it. Exception summary: com.rabbitmq.client.ShutdownSignalException: channel error; reason: {#method<channel.close>(reply-code=406, reply-text=PRECONDITION_FAILED - unknown delivery tag 1, class-id=60, method-id=80), null, ""}
11:42:41,448 INFO [org.springframework.amqp.rabbit.listener.SimpleMessageListenerContainer] (SimpleAsyncTaskExecutor-5) Restarting Consumer: tag=[amq.ctag-t5CTaRT9UXy_jsmt5Bz95w], channel=Cached Rabbit Channel: AMQChannel(amqp://sola#192.168.7.108:5672/,16), acknowledgeMode=AUTO local queue size=0
11:42:41,672 INFO [com.gnax.sola.imagemanager.jms.ADTRequestHandler] (SimpleAsyncTaskExecutor-6) Consuming ADT Message
11:42:41,672 INFO [com.gnax.sola.imagemanager.jms.ADTRequestHandler] (SimpleAsyncTaskExecutor-6) Error while receiving ADT Message
11:42:41,672 ERROR [com.gnax.sola.imagemanager.jms.ADTRequestHandler] (SimpleAsyncTaskExecutor-6) Unrecognized token 'fgffgfd': was expecting
at [Source: java.io.StringReader#1736e037; line: 1, column: 15]
11:42:41,682 INFO [com.gnax.sola.jms.AmqpConsumer] (SimpleAsyncTaskExecutor-6) Proccessed the message from AMQP
11:42:41,922 INFO [com.gnax.sola.imagemanager.jms.ADTRequestHandler] (SimpleAsyncTaskExecutor-6) Consuming ADT Message
11:42:41,922 INFO [com.gnax.sola.imagemanager.jms.ADTRequestHandler] (SimpleAsyncTaskExecutor-6) Error while receiving ADT Message
11:42:41,922 ERROR [com.gnax.sola.imagemanager.jms.ADTRequestHandler] (SimpleAsyncTaskExecutor-6) Unrecognized token 'fgffgfd': was expecting
at [Source: java.io.StringReader#467b09b7; line: 1, column: 15]
11:42:41,932 INFO [com.gnax.sola.jms.AmqpConsumer] (SimpleAsyncTaskExecutor-6) Proccessed the message from AMQP
11:42:41,932 WARN [org.springframework.amqp.rabbit.listener.SimpleMessageListenerContainer] (SimpleAsyncTaskExecutor-6) Consumer raised exception, processing can restart if the connection factory supports it. Exception summary: com.rabbitmq.client.ShutdownSignalException: channel error; reason: {#method<channel.close>(reply-code=406, reply-text=PRECONDITION_FAILED - unknown delivery tag 1, class-id=60, method-id=80), null, ""}
11:42:41,932 INFO [org.springframework.amqp.rabbit.listener.SimpleMessageListenerContainer] (SimpleAsyncTaskExecutor-6) Restarting Consumer: tag=[amq.ctag-A3tGkE4oDLM0D4Lgz_4iOw], channel=Cached Rabbit Channel: AMQChannel(amqp://sola#192.168.7.108:5672/,17), acknowledgeMode=AUTO local queue size=0
11:42:41,972 WARN [org.springframework.amqp.rabbit.listener.SimpleMessageListenerContainer] (SimpleAsyncTaskExecutor-1) Consumer raised exception, processing can restart if the connection factory supports it. Exception summary: com.rabbitmq.client.ShutdownSignalException: connection error; reason: com.rabbitmq.client.impl.UnknownChannelException: Unknown channel number 17
11:42:41,972 INFO [org.springframework.amqp.rabbit.listener.SimpleMessageListenerContainer] (SimpleAsyncTaskExecutor-1) Restarting Consumer: tag=[amq.ctag-uczR-I6V7HeiZnQQj3PGqw], channel=Cached Rabbit Channel: AMQChannel(amqp://sola#192.168.7.108:5672/,6), acknowledgeMode=AUTO local queue size=0
11:42:41,972 WARN [org.springframework.amqp.rabbit.listener.SimpleMessageListenerContainer] (SimpleAsyncTaskExecutor-1) Consumer raised exception, processing can restart if the connection factory supports it. Exception summary: com.rabbitmq.client.ShutdownSignalException: connection error; reason: com.rabbitmq.client.impl.UnknownChannelException: Unknown channel number 17
11:42:41,972 WARN [org.springframework.amqp.rabbit.listener.SimpleMessageListenerContainer] (SimpleAsyncTaskExecutor-1) Consumer raised exception, processing can restart if the connection factory supports it. Exception summary: com.rabbitmq.client.ShutdownSignalException: connection error; reason: com.rabbitmq.client.impl.UnknownChannelException: Unknown channel number 17
11:42:41,972 INFO [org.springframework.amqp.rabbit.listener.SimpleMessageListenerContainer] (SimpleAsyncTaskExecutor-1) Restarting Consumer: tag=[amq.ctag-w45jv1s-vMEVL7LHF4C1wA], channel=Cached Rabbit Channel: AMQChannel(amqp://sola#192.168.7.108:5672/,10), acknowledgeMode=AUTO local queue size=0
11:42:41,972 INFO [org.springframework.amqp.rabbit.listener.SimpleMessageListenerContainer] (SimpleAsyncTaskExecutor-1) Restarting Consumer: tag=[amq.ctag-sacFJPkjSwD8GNmpB3rW-Q], channel=Cached Rabbit Channel: AMQChannel(amqp://sola#192.168.7.108:5672/,4), acknowledgeMode=AUTO local queue size=0
11:42:41,972 WARN [org.springframework.amqp.rabbit.listener.SimpleMessageListenerContainer] (SimpleAsyncTaskExecutor-1) Consumer raised exception, processing can restart if the connection factory supports it. Exception summary: com.rabbitmq.client.ShutdownSignalException: connection error; reason: com.rabbitmq.client.impl.UnknownChannelException: Unknown channel number 17
11:42:41,972 INFO [org.springframework.amqp.rabbit.listener.SimpleMessageListenerContainer] (SimpleAsyncTaskExecutor-1) Restarting Consumer: tag=[amq.ctag-d6ezJG0sAGFOJeBOKiCaaA], channel=Cached Rabbit Channel: AMQChannel(amqp://sola#192.168.7.108:5672/,2), acknowledgeMode=AUTO local queue size=0
11:42:42,032 WARN [org.springframework.amqp.rabbit.listener.SimpleMessageListenerContainer] (SimpleAsyncTaskExecutor-1) Consumer raised exception, processing can restart if the connection factory supports it. Exception summary: com.rabbitmq.client.ShutdownSignalException: connection error; reason: com.rabbitmq.client.impl.UnknownChannelException: Unknown channel number 17
11:42:42,032 INFO [org.springframework.amqp.rabbit.listener.SimpleMessageListenerContainer] (SimpleAsyncTaskExecutor-1) Restarting Consumer: tag=[amq.ctag--GGgfZWMvUud7Q3kE7FqtA], channel=Cached Rabbit Channel: AMQChannel(amqp://sola#192.168.7.108:5672/,9), acknowledgeMode=AUTO local queue size=0
11:42:42,032 WARN [org.springframework.amqp.rabbit.listener.SimpleMessageListenerContainer] (SimpleAsyncTaskExecutor-1) Consumer raised exception, processing can restart if the connection factory supports it. Exception summary: com.rabbitmq.client.ShutdownSignalException: connection error; reason: com.rabbitmq.client.impl.UnknownChannelException: Unknown channel number 17
11:42:42,032 INFO [org.springframework.amqp.rabbit.listener.SimpleMessageListenerContainer] (SimpleAsyncTaskExecutor-1) Restarting Consumer: tag=[amq.ctag-i4SmHrGYjAxvAV_uO1hDYA], channel=Cached Rabbit Channel: AMQChannel(amqp://sola#192.168.7.108:5672/,8), acknowledgeMode=AUTO local queue size=0
11:42:42,042 WARN [org.springframework.amqp.rabbit.listener.SimpleMessageListenerContainer] (SimpleAsyncTaskExecutor-1) Consumer raised exception, processing can restart if the connection factory supports it. Exception summary: com.rabbitmq.client.ShutdownSignalException: connection error; reason: com.rabbitmq.client.impl.UnknownChannelException: Unknown channel number 17
11:42:42,042 INFO [org.springframework.amqp.rabbit.listener.SimpleMessageListenerContainer] (SimpleAsyncTaskExecutor-1) Restarting Consumer: tag=[amq.ctag-2VPna8pwyxZHBg-Zh5OicQ], channel=Cached Rabbit Channel: AMQChannel(amqp://sola#192.168.7.108:5672/,5), acknowledgeMode=AUTO local queue size=0
11:42:42,042 WARN [org.springframework.amqp.rabbit.listener.SimpleMessageListenerContainer] (SimpleAsyncTaskExecutor-1) Consumer raised exception, processing can restart if the connection factory supports it. Exception summary: com.rabbitmq.client.ShutdownSignalException: connection error; reason: com.rabbitmq.client.impl.UnknownChannelException: Unknown channel number 17
11:42:42,042 INFO [org.springframework.amqp.rabbit.listener.SimpleMessageListenerContainer] (SimpleAsyncTaskExecutor-1) Restarting Consumer: tag=[amq.ctag-h1TLZWU9wI3DFBIu0k3fQA], channel=Cached Rabbit Channel: AMQChannel(amqp://sola#192.168.7.108:5672/,3), acknowledgeMode=AUTO local queue size=0
11:42:42,162 INFO [com.gnax.sola.imagemanager.jms.ADTRequestHandler] (SimpleAsyncTaskExecutor-7) Consuming ADT Message
11:42:42,162 INFO [com.gnax.sola.imagemanager.jms.ADTRequestHandler] (SimpleAsyncTaskExecutor-7) Error while receiving ADT Message
11:42:42,162 ERROR [com.gnax.sola.imagemanager.jms.ADTRequestHandler] (SimpleAsyncTaskExecutor-7) Unrecognized token 'fgffgfd': was expecting
at [Source: java.io.StringReader#1bbecd4d; line: 1, column: 15]
11:42:42,162 INFO [com.gnax.sola.jms.AmqpConsumer] (SimpleAsyncTaskExecutor-7) Proccessed the message from AMQP
11:42:42,682 WARN [org.springframework.amqp.rabbit.listener.SimpleMessageListenerContainer] (SimpleAsyncTaskExecutor-1) Consumer raised exception, processing can restart if the connection factory supports it. Exception summary: com.rabbitmq.client.ShutdownSignalException: connection error; reason: com.rabbitmq.client.impl.UnknownChannelException: Unknown channel number 17
11:42:42,683 INFO [org.springframework.amqp.rabbit.listener.SimpleMessageListenerContainer] (SimpleAsyncTaskExecutor-1) Restarting Consumer: tag=[amq.ctag-6lQWkrIIeM1etGSo8wcf6g], channel=Cached Rabbit Channel: AMQChannel(amqp://sola#192.168.7.108:5672/,7), acknowledgeMode=AUTO local queue size=0
11:42:43,181 WARN [org.springframework.amqp.rabbit.listener.SimpleMessageListenerContainer] (SimpleAsyncTaskExecutor-7) Consumer raised exception, processing can restart if the connection factory supports it. Exception summary: com.rabbitmq.client.ShutdownSignalException: channel error; reason: {#method<channel.close>(reply-code=406, reply-text=PRECONDITION_FAILED - unknown delivery tag 1, class-id=60, method-id=80), null, ""}
11:42:43,181 INFO [org.springframework.amqp.rabbit.listener.SimpleMessageListenerContainer] (SimpleAsyncTaskExecutor-7) Restarting Consumer: tag=[amq.ctag-QNs_wFdj_MjVeX768J1udg], channel=Cached Rabbit Channel: AMQChannel(amqp://sola#192.168.7.108:5672/,2), acknowledgeMode=AUTO local queue size=0
Turn on DEBUG logging to see the retry activity; if you still can't figure it out, post the log.

Missing Oracle jdbc Driver for Mule ESB Datamapper

Good morning to everyone,
I have a big issue to run a job in Mule ESB. I'm trying to map an CSV file in a table of an oracle database. To do that, I created a JDBC Connector with a Oracle DataSource and the Connection Test is Valid. But if i run The Job an error Message appears.
[Error Message]
-------------------------------------
ERROR 2015-06-17 09:01:26,223 [[....].connector.file.mule.default.receiver.01] org.mule.exception.DefaultMessagingExceptionStrategy:
******************************************************************************
Message : com.mulesoft.mule.module.datamapper.api.exception.DataMapperCreationException: Element [JDBC0:]-Can't initialize connection DBConnection driver[null]:jndi[null]:url[jdbc:oracle:thin:#.....:....:.......]:user[......]. (java.lang.RuntimeException). Message payload is of type: ReceiverFileInputStream
Code : MULE_ERROR--2
--------------------------------------------------------------------------------
Exception stack is:
1. Cannot load class 'oracle.jdbc.OracleDriver' (java.lang.ClassNotFoundException)
org.mule.module.launcher.application.CompositeApplicationClassLoader:74 (null)
2. Cannot create JDBC driver 'Oracle'. Cannot find class. (org.jetel.exception.ComponentNotReadyException)
org.jetel.connection.jdbc.driver.JdbcDriverImpl:188 (null)
3. Can't initialize connection DBConnection driver[null]:jndi[null]:url[..............]:user[.......]. (org.jetel.exception.ComponentNotReadyException)
org.jetel.graph.TransformationGraph:413 (null)
4. Element [JDBC0:]-Can't initialize connection DBConnection driver[null]:jndi[null]:url[..............]:user[...........]. (com.mulesoft.mule.module.datamapper.api.exception.DataMapperCreationException)
com.mulesoft.mule.module.datamapper.clover.impl.graphfactory.DocumentCloverGraphFactoryImpl:59 (null)
5. com.mulesoft.mule.module.datamapper.api.exception.DataMapperCreationException: Element [JDBC0:]-Can't initialize connection DBConnection driver[null]:jndi[null]:url[............]:user[.....]. (java.lang.RuntimeException)
com.mulesoft.mule.module.datamapper.clover.impl.graphprovider.PoolGraphProvider:109 (null)
6. com.mulesoft.mule.module.datamapper.api.exception.DataMapperCreationException: Element [JDBC0:]-Can't initialize connection DBConnection driver[null]:jndi[null]:url[..............]:user[..............]. (java.lang.RuntimeException). Message payload is of type: ReceiverFileInputStream (org.mule.api.MessagingException)
--------------------------------------------------------------------------------
Root Exception stack trace:
java.lang.ClassNotFoundException: Cannot load class 'oracle.jdbc.OracleDriver'
at org.mule.module.launcher.application.CompositeApplicationClassLoader.loadClass(CompositeApplicationClassLoader.java:74)
at org.jetel.util.classloader.GreedyURLClassLoader.loadClassGreedy(GreedyURLClassLoader.java:137)
at org.jetel.util.classloader.GreedyURLClassLoader.loadClass(GreedyURLClassLoader.java:111)
+ 3 more (set debug level logging or '-Dmule.verbose.exceptions=true' for everything)
******************************************************************************
Do I have to put the driver "ojdbc7.jar" in a specific directory?
What it looks like you have configured oracle.jdbc.OracleDriver instead of oracle.jdbc.driver.OracleDriver
You can configure the following example :-
<spring:beans>
<spring:bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">
<spring:property name="driverClassName" value="oracle.jdbc.driver.OracleDriver"/>
<spring:property name="url" value="jdbc:oracle:thin:#192.168.28.129:1521:xe"/>
<spring:property name="username" value="yourUserName"/>
<spring:property name="password" value="yourPassword"/>
<spring:property name="removeAbandoned" value="true"/>
<spring:property name="initialSize" value="10"/>
<spring:property name="maxActive" value="50"/>
</spring:bean>
</spring:beans>
<db:generic-config name="Database_Configuration" dataSource-ref="dataSource" doc:name="Generic Database Configuration" />
<flow name="mainFlow">
<http:listener config-ref="httpListenerConfig" path="/*" doc:name="HTTP" allowedMethods="GET"/>
///////////////////////////////////////
Your Code
////////////////////////////////////
<db:select config-ref="Database_Configuration" doc:name="Database">
<db:parameterized-query><![CDATA[select * from yourtableName]]></db:parameterized-query>
</db:select>
</flow>
You need to configure and change as per your ip, username, password etc
Add commons-dbcp-1.2.2.jar or other version and ojdbc6.jar in your classpath as dependancy

Spring Integration: JMS loosing messages in case of OutOfMemoryError: PermGen space error

I have lost JMS messages(files) which were in the spring integration pipeline flow of jms:message-driven-channel-adapter though the adapter is set to transacted mode and custom exception type router with RuntimeException was configured, which means in case of any Runtime Exception (like PermGenError) it will consume the message, but not happend in my case.
Any help would be appreceated. .
Taking jms messages from ibm mq and after transformation sending it to another queue.
<bean id="queueTradeIn" class="com.ibm.mq.jms.MQQueue">
<constructor-arg value="${queue.name}" />
</bean>
<jms:message-driven-channel-adapter concurrent-consumers="1" id="tradeInputQueueAdaptor" destination="queueTradeIn" channel="topLevelErrorHandlerInputChannel" acknowledge="transacted" />
Exception Configuration:
I am passing all the messages through topLevelErrorHandlerInputChannel.
<!-- The ErrorHandler passes the message on the input channel to the output channel. -->
<beans:bean id="topLevelErrorHandler" class="com.xxx.ErrorHandler" >
<beans:property name="errorChannel" ref="errorChannel"/>
<beans:property name="outputChannel" ref="dataProcessChain"/>
<beans:property name="throwablesToHandle" >
<beans:list>
<beans:value>java.lang.NullPointerException</beans:value>
<beans:value>org.xml.sax.SAXParseException</beans:value>
<beans:value>org.dom4j.DocumentException</beans:value>
<beans:value>com.xxx.DLQMessageException</beans:value>
<beans:value>java.lang.RuntimeException</beans:value>
</beans:list>
</beans:property>
</beans:bean>
<service-activator input-channel="topLevelErrorHandlerInputChannel" ref="topLevelErrorHandler" method="passThrough"/>
<transformer input-channel="errorChannel" method="display" ref="errorMessageConstructor" output-channel="errorLogChannel"/>
<logging-channel-adapter channel="errorLogChannel" id="rejectedLog" expression="'Message passed through!'" level="INFO"/>

Spring taking long time to return cached instance of singleton bean - transactionManager

All API call are taking long time to respond because, spring is taking long time to return cached instance of singleton bean - transactionManager. Please see log, this behaviour is consistent for each request.
2
014-09-24 08:09:02,239 DEBUG servlet.DispatcherServlet - DispatcherServlet with name 'appServlet' processing GET request for [/emsp/locations]
2014-09-24 08:09:02,239 DEBUG annotation.RequestMappingHandlerMapping - Looking up handler method for path /locations
2014-09-24 08:09:02,239 DEBUG annotation.RequestMappingHandlerMapping - Did not find handler method for [/locations]
2014-09-24 08:09:02,239 DEBUG servlet.DispatcherServlet - Last-Modified value for [/emsp/locations] is: -1
2014-09-24 08:09:02,240 DEBUG support.DefaultListableBeanFactory - Returning cached instance of singleton bean 'integrationEvaluationContext'
2014-09-24 08:09:02,241 DEBUG support.DefaultListableBeanFactory - Returning cached instance of singleton bean 'endpointLookupService'
2014-09-24 08:09:07,407 DEBUG support.DefaultListableBeanFactory - Returning cached instance of singleton bean 'txManager'
2014-09-24 08:09:07,407 DEBUG hibernate4.HibernateTransactionManager - Creating new transaction with name [com.***.emsp.service.impl.EndpointLookupServiceImpl.getEndpointLocations]: PROPAGATION_REQUIRED,ISOLATION_DEFAULT; ''
2014-09-24 08:09:07,407 DEBUG hibernate4.HibernateTransactionManager - Opened new Session [SessionImpl(PersistenceContext[entityKeys=[],collectionKeys=[]];ActionQueue[insertions=[] updates=[] deletions=[] orphanRemovals=[] collectionCreations=[] collectionRemovals=[] collectionUpdates=[] collectionQueuedOps=[] unresolvedInsertDependencies=UnresolvedEntityInsertActions[]])] for Hibernate transaction
2014-09-24 08:09:07,407 DEBUG hibernate4.HibernateTransactionManager - Preparing JDBC Connection of Hibernate Session [SessionImpl(PersistenceContext[entityKeys=[],collectionKeys=[]];ActionQueue[insertions=[] updates=[] deletions=[] orphanRemovals=[] collectionCreations=[] collectionRemovals=[] collectionUpdates=[] collectionQueuedOps=[] unresolvedInsertDependencies=UnresolvedEntityInsertActions[]])]
2014-09-24 08:09:07,407 DEBUG internal.LogicalConnectionImpl - Obtaining JDBC connection
2014-09-24 08:09:07,407 DEBUG resourcepool.BasicResourcePool - trace com.mchange.v2.resourcepool.BasicResourcePool#7cfea9ab [managed: 1, unused: 0, excluded: 0] (e.g. com.mchange.v2.c3p0.impl.NewPooledConnection#6a4d7764)
2014-09-24 08:09:07,407 DEBUG internal.LogicalConnectionImpl - Obtained JDBC connection
2014-09-24 08:09:07,407 DEBUG spi.AbstractTransactionImpl - begin
2014-09-24 08:09:07,408 DEBUG jdbc.JdbcTransaction - initial autocommit status: true
2014-09-24 08:09:07,408 DEBUG jdbc.JdbcTransaction - disabling autocommit
2014-09-24 08:09:07,408 DEBUG hibernate4.HibernateTransactionManager - Exposing Hibernate transaction as JDBC transaction [com.mchange.v2.c3p0.impl.NewProxyConnection#3c0b2e6e]
2014-09-24 08:09:07,408 INFO impl.EndpointLookupServiceImpl - EndpointLookupServiceImpl::getEndpointLocations - called (Custom log - after this is almost instantaneous)
If you see these two lines specifically in the above line - there is a 5sec delay - this keeps increasing after a while but comes down once tomcat is restarted.
2014-09-24 08:09:02,241 DEBUG support.DefaultListableBeanFactory - Returning cached instance of singleton bean 'endpointLookupService'
2014-09-24 08:09:07,407 DEBUG support.DefaultListableBeanFactory - Returning cached instance of singleton bean 'txManager'
My spring config
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context"
xmlns:tx="http://www.springframework.org/schema/tx" xmlns:jdbc="http://www.springframework.org/schema/jdbc"
xsi:schemaLocation="
http://www.springframework.org/schema/jdbc http://www.springframework.org/schema/jdbc/spring-jdbc-3.0.xsd
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.0.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd">
<context:component-scan base-package="com.****.emsp" />
<!-- Transaction Manager Declaration -->
<bean id="txManager"
class="org.springframework.orm.hibernate4.HibernateTransactionManager">
<property name="sessionFactory">
<ref bean="sessionFactory" />
</property>
</bean>
<tx:annotation-driven transaction-manager="txManager" />
<bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource"
destroy-method="close">
<property name="driverClass" value="com.mysql.jdbc.Driver" />
<property name="jdbcUrl" value="jdbc:mysql://localhost:3306/emsp" />
<property name="user" value="***" />
<property name="password" value="***" />
<!-- C3P0 properties -->
<property name="acquireIncrement" value="1" />
<property name="minPoolSize" value="1" />
<property name="maxPoolSize" value="20" />
<property name="maxIdleTime" value="300" />
<property name="idleConnectionTestPeriod" value="3000" />
<!--property name="testConnectionOnCheckout" value="true" /> <property
name="preferredTestQuery" value="select 1;" / -->
</bean>
<bean id="sessionFactory"
class="org.springframework.orm.hibernate4.LocalSessionFactoryBean">
<property name="dataSource" ref="dataSource" />
<property name="packagesToScan" value="com.****.emsp.entity" />
<property name="hibernateProperties">
<value>
hibernate.dialect=org.hibernate.dialect.MySQLDialect
hibernate.show_sql=false
hibernate.hbm2ddl.auto=update
</value>
</property>
</bean>
</beans>
And i'm using #Transactional annotation for my service APIs involving DB transaction.
Please suggest how to go about debugging this. Also let me know if any another info is required.
Request Handling code:
#Service
public class EndpointLookupServiceImpl implements EndpointLookupService {
private static final Logger logger = Logger
.getLogger(EndpointLookupServiceImpl.class);
#Autowired
EndpointLocationDaoImpl endpointLoctionDao;
#Autowired
SsidDaoImpl ssidDao;
#Override
#Transactional
public EndpointLocationsResp getEndpointLocations(
String xJwtAssertionHeader, Map<String, List<String>> reqParams) {
logger.info("EndpointLookupServiceImpl::getEndpointLocations - called with xJwtAssertionHeader:"
+ xJwtAssertionHeader + " reqParams:" + reqParams);
.....
}
}
Using spring integration as controller for invoking the service:
<int-http:inbound-gateway id="endpointLocById"
request-channel="endpointLocByIdIn"
supported-methods="GET"
path="/locations/{locationId}"
mapped-request-headers="*"
payload-expression="#pathVariables.locationId" >
</int-http:inbound-gateway>
<int:channel id="endpointLocByIdIn"/>
<int:service-activator input-channel="endpointLocByIdIn" expression="#endpointLookupService.getEndpointLocationByLocationId(headers['x-jwt-assertion'], payload)" output-channel="out" />
Take thread dumps just before and after you see the blocking to see what your main thread is doing, Spring loads beans in a single thread, so you should be able to see where it is stuck and debug that even more.

Resources