Exception handling in Spring Integration - spring-integration

I am using spring integration to make parallel calls to two web services, I wanted to know how to handle the case when one service goes down for some reason. Say I get a timeout exception how do i handle it in spring integration.
<int:service-activator input-channel="wslService-request-b"
method="webServiceCallB" output-channel="wslService-reply" ref="LITESWebServiceCall">
<int:poller max-messages-per-poll="1" fixed-delay="10"
receive-timeout="40000" task-executor="wslServiceRequestExecutor" error-channel="ws-error-channel"/>
</int:service-activator>
<int:service-activator
input-channel="ws-error-channel"
ref="errorHandler" />

Related

Inconsistency Dequeue issues with Spring Integration with Oracle AQ

I am using Spring integration with Oracle AQ,configuration code is as below.
Currently with the below configuration,the service activator is not getting invoked consistently with even the dequeue was successful at oracle end, unable to trace the message after successful Dequeue with the application logs, not even single error message shown on the log. Tried Debug,Trace and info options in the jms adaptor, but no clue from the log details. I have verified with Oracle team on enque and deque messages, but the health check reports are clearing mentioning the messages are dequeued successfully.
Badly required your help to get rid of this inconsitency behaviour while invoking the service activator using spring
<int:logging-channel-adapter id="jmslogger" log-full-message="true" level="TRACE"/>
<!-- Oracle Advanced Queue Integration -->
<bean id="jdbc4NativeJdbcExtractor"
class="org.springframework.jdbc.support.nativejdbc.Jdbc4NativeJdbcExtractor"
p:connectionType="oracle.jdbc.driver.OracleConnection" />
<orcl:aq-jms-connection-factory
id="oracleAqConnectionFactory"
use-local-data-source-transaction="true"
native-jdbc-extractor="jdbc4NativeJdbcExtractor"
data-source="dataSource"/>
<!-- Siebel Atlas Service Request - Oracle Advanced Queue Integration -->
<bean id="jmsJsonMessageConverter" class="org.springframework.jms.support.converter.MappingJackson2MessageConverter"
p:typeIdPropertyName="javaDtoClass"
/>
<int:channel id="submitSiebelAtlasCreateServiceRequestOutboundRequestChannel" ></int:channel>
<int:channel id="submitSiebelAtlasCreateServiceRequestOutboundRequestEnrichedChannel" >
<int:interceptors>
<int:wire-tap channel="jmslogger"/>
</int:interceptors>
</int:channel>
<int:channel id="createSiebelAtlasCreateServiceRequestOutboundReplyChannel" />
<int:logging-channel-adapter id="createSiebelAtlasCreateServiceRequestOutboundReplyChannelLogger"
channel="createSiebelAtlasCreateServiceRequestOutboundReplyChannel" />
<int:gateway
id="submitSiebelAtlasCreateServiceRequestMessagingService"
service-interface="ServiceRequestOutboundGatewayMessagingService"
default-request-channel="submitSiebelAtlasCreateServiceRequestOutboundRequestChannel"
default-reply-channel="submitSiebelAtlasCreateServiceRequestOutboundReplyChannel" />
<int:header-enricher input-channel="submitSiebelAtlasCreateServiceRequestOutboundRequestChannel" output-channel="submitSiebelAtlasCreateServiceRequestOutboundRequestEnrichedChannel">
<int:correlation-id expression="payload.getRequestId()"/>
</int:header-enricher>
<!-- Outbound driven channel adapter, meaning messagings are being sent to / queued in AQ -->
<int-jms:outbound-channel-adapter
id="siebelAtlasCreateServiceRequestJmsOutboundChannelAdapter"
destination-name="Q_NAME"
channel="submitSiebelAtlasCreateServiceRequestOutboundRequestEnrichedChannel"
connection-factory="oracleAqConnectionFactory"
message-converter="jmsJsonMessageConverter"
auto-startup="true">
</int-jms:outbound-channel-adapter>
<int:service-activator
output-channel="createSiebelAtlasCreateServiceRequestOutboundReplyChannel"
input-channel="createSiebelAtlasCreateServiceRequestInboundRequestChannel"
ref="createCustomerRelationshipsSiebelAtlasServiceRequestService"
method="create">
</int:service-activator>
<int:channel id="createSiebelAtlasCreateServiceRequestInboundRequestChannel">
<int:interceptors>
<int:wire-tap channel="jmslogger"/>
</int:interceptors>
</int:channel>
<!-- Inbound message driven channel adapter, meaning messagings are being consumed / dequeued from AQ -->
<int-jms:message-driven-channel-adapter connection-factory="oracleAqConnectionFactory"
message-converter="jmsJsonMessageConverter"
destination-name="Q_NAME"
channel="createSiebelAtlasCreateServiceRequestInboundRequestChannel"
acknowledge="transacted"
max-concurrent-consumers="5"
transaction-manager="transactionManager"
auto-startup="true"
concurrent-consumers="2" />

Receive the acknowledgement from TCP server to our application using spring Integration

Currently we are using Spring Integration 2.1.0 Release in our application.
Application flow is as below:
Some operation is performed in application and we got the output string in String via Active MQ.
I have used message-driven-channel-adapter and service-activator to read the data from queue.
That data is displayed successfully on Server(application is working as client) using tcp-outbound-gateway.
Problem is while getting the acknowledgement from server.
Created a new channel and entered in reply-channel in tcp-outbound-gateway
Passing the same channel in service-activator as input channel.
It is showing below error:
[task-scheduler-5] 2017-10-05 18:32:20,732 ERROR org.springframework.integration.handler.LoggingHandler - org.springframework.integration.MessageDeliveryException: Dispatcher has no subscribers.
at org.springframework.integration.dispatcher.UnicastingDispatcher.doDispatch(UnicastingDispatcher.java:108)
at org.springframework.integration.dispatcher.UnicastingDispatcher.dispatch(UnicastingDispatcher.java:101)
at org.springframework.integration.channel.AbstractSubscribableChannel.doSend(AbstractSubscribableChannel.java:61)
at org.springframework.integration.channel.AbstractMessageChannel.send(AbstractMessageChannel.java:157)
at org.springframework.integration.channel.AbstractMessageChannel.send(AbstractMessageChannel.java:128)
at org.springframework.integration.core.MessagingTemplate.doSend(MessagingTemplate.java:288)
at org.springframework.integration.core.MessagingTemplate.send(MessagingTemplate.java:149)
Code is as below
<context:property-placeholder />
<!-- Gateway and connection factory setting -->
<int:channel id="telnetLandingChannel" />
<int:channel id="telnetReplyChannel" />
<beans:bean id="clientCustomSerializer"
class="com.telnet.core.serializer.CustomSerializer">
<beans:property name="terminatingChar" value="10" />
<beans:property name="maxLength" value="65535" />
</beans:bean>
<int:gateway id="gw" default-reply-channel="telnetReplyChannel" default-reply-timeout="100000"
service-interface="com.telnet.core.integration.connection.ParseTcpConfiguration$SimpleGateway"
default-request-channel="telnetLandingChannel"/>
<ip:tcp-connection-factory id="clientFactory"
type="client" host="localhost" port="7777" single-use="false" using-nio="false"
serializer="${client.serializer}" deserializer="${client.serializer}" />
<ip:tcp-outbound-gateway id="clientInGw"
request-channel="telnetLandingChannel"
connection-factory="clientFactory"
reply-channel="telnetReplyChannel"
reply-timeout="100000"/>
<!-- To send the messege over server via JMS and serviceActivator -->
<int:channel id="incidentDispatchMessageChannel" />
<int:channel id="jmsChannel" />
<beans:bean id="customClientServiceActivator"
class= "com.telnet.core.integration.CustomClientServiceActivator">
</beans:bean>
<int-jms:message-driven-channel-adapter id="incidentDispatchMessageChannelAdapter" error-channel="errorChannel"
connection-factory="mqConnectionFactory"
destination-name="${incident.processing.messaging.dispatch.queues}"
channel="incidentDispatchMessageChannel"/>
<int:service-activator id="incidentMessageActivator"
input-channel="incidentDispatchMessageChannel"
output-channel="jmsChannel"
ref="customClientServiceActivator" method="getOutboundMessage">
</int:service-activator>
<int:object-to-string-transformer id="clientBytes2String"
input-channel="jmsChannel"
output-channel="telnetLandingChannel"/>
<!-- To receive the acknowledgement message on server via serviceActivator -->
<int:service-activator id="incidentAck"
input-channel="telnetReplyChannel"
ref="customClientServiceActivator" method="getAck">
</int:service-activator>
I have studied various article on stackverFlow but not able to get any solution
Yeah... That isn't clear by the error what channel is guilty.
On the other hand you really use very old Spring Integration version.
Would be great to consider to upgrade to the latest: http://projects.spring.io/spring-integration/.
However I think that issue is somehow around exactly that reply-channel, which you use not only for the <service-activator> but for the <int:gateway> as well.
I suggest you to remove default-reply-channel="telnetReplyChannel" from the gateway definition, remove reply-channel="telnetReplyChannel" from the <ip:tcp-outbound-gateway> definition. And let them communicate via replyChannel header populated by the gateway during request.
Regarding your <int-jms:message-driven-channel-adapter> flow which leads to the same <ip:tcp-outbound-gateway>, I would suggest to still stay with the replyChannel header but here populate it via <header-enricher> before sending message to the telnetLandingChannel. That replyChannel via <header-enricher> would be exactly an input-channel for the subsequent <int:service-activator> to handle ack from the <ip:tcp-outbound-gateway>.
I got the solution of this issue, there are multiple xmls in our code but i have added the code in one to show flow in stackOverflow.
Issue was i had defined in a xml which has only configuration part like Outbound adapter connection factory where as it should be defined in another xml where I am using service activator. Changed the place of channel definition and it worked.
I want to disconnect the TCP (as server) the moment i got the response message. As of now I am using so-timeout, so my TCP server will gets timedout after the time given in so-timeout, but requirement is to disconnect the connection the moment TCP print/display the acknowledgement. Please suggest how can I implement this.

Implementing Gateway causing Problems in Message Flow

I have a scenario in which i am receiving a message and routing it to different message channels using Recipient-list-router.
<int:recipient-list-router input-channel="inputChannel1"
apply-sequence="true" id="router1">
<int:recipient channel="service1" />
<int:recipient channel="service2" />
</int:recipient-list-router>
This aggregator is used to aggregate the response from above 2 services and redirects the aggregated output to some other channel for further processing.
<int:aggregator input-channel="aggregator1" output-channel="channel2" >
<bean class="wsintg.service.AggregatorClass" />
</int:aggregator>
The code for individual services looks like this :
<!--service 1 code -->
<int:service-activator input-channel="service1" ref="service1Ref" />
<int:gateway id="service1Ref" default-request-channel="success_channel" error-channel="error_channel" />
<int:chain id="chainid1" input-channel="success_channel" output-channel="aggregator1">
step 1 :xsl transformation
step 2 :call to a service using ws:outbound-gateway
<int:service-activator id="sa1">
<bean class="samplePkg.returnMessage"></bean> <!--return message simply returns the message without doing anything -->
</int:service-activator>
</int:chain>
<int:chain id="chainid2" input-channel="error_channel" output-channel="aggregator1" >
<int:service-activator>
<!-- some custom exception handling -->
</int:service-activator>
</int:chain>
<!--service 2 code --> same as service 1
Problem :
If i don't use gateway in Service 1 and Service 2 and simply do the transformations, the code works perfectly.
But, as i need to do some error handling using error_channel, so i put a gateway in service1 and service 2 code. Now the flow
stucks after service activator in service 1 without throwing any
exception. and does not calls the service 2 flow.
You need to show real configuration, not just comments; we can't guess what your application looks like.
That said, you can't just send error messages to the aggregator because the aggregation information is in the failedMessage headers and needs to be promoted.
See error handling in this sample for an example.
As always, the first step to debug situations like this is to turn on DEBUG logging for org.springframework.integration and follow the messages through the flow.
You will usually be able to determine the problem that way.

Spring Integration Task Executor Memory Leakage

My module is on spring integration which pushes message to RabbitMQ.
<task:executor id="bulkChannelExecutor" keep-alive="50" poolsize="50-100" queue-capacity="500"
></task:executor>
<int:channel id="logIngesterRestEndpointBulk" >
<int:dispatcher task-executor="bulkChannelExecutor" failover="false" />
</int:channel>
While Load testing ist not able to handle heavy loads(100 concurrent users) it causing message or request lost ,if i remove pool-size ,having unbounded poolsize its able to handling heavy loads but its creating memory thread leaks?
Rest Gateway will get input as Json and pass it to Filter and then will to
Chain ,there Json messages will get parsed and splitted as indivdiual messages and then will get push to rabbitMQ
<task:executor id="bulkChannelExecutor" keep-alive="50" pool-size="100-500"
queue-capacity="500"
></task:executor>
<int:channel id="logIngesterRestEndpointBulk" >
<int:dispatcher task-executor="bulkChannelExecutor" failover="false" />
</int:channel>
<int-http:inbound-gateway id="logIngesterGatewayBulk" auto-startup="true"
supported-methods="POST" request-channel="logIngesterRestEndpointBulk"
path="/rest/log/bulk" error-channel="errorChannel" reply-timeout="50"
request-payload-type="java.lang.String">
</int-http:inbound-gateway>
<int:channel id="filterChannelbulk">
</int:channel>
<int:channel id="messageOutputChannel" >
</int:channel>
<int:filter input-channel="logIngesterRestEndpointBulk"
throw-exception-on-rejection="true" method="validate" ref="payloadValidation"
output-channel="filterChannelbulk">
</int:filter>
<int:chain input-channel="filterChannelbulk" output-channel="messageOutputChannel" id="chaining" >
<int:splitter id="splitter" ref="payloadSplitter" method="splitPayLoad" >
</int:splitter>
<int:transformer id="logMessageTransformerbulk" ref="logMessageHeaderTransformer"
method="transform">
</int:transformer>
</int:chain>
<int:service-activator input-channel="errorChannel"
ref="responseHandler" method="handleFailedPayLoad" >
</int:service-activator>
<!-- Start RabbitMQ Configuration -->
<int:channel id="ackchannel">
</int:channel>
<int-amqp:outbound-channel-adapter
id="amqpAdapter" channel="messageOutputChannel" amqp-template="amqpTemplate" lazy-connect="false" confirm-ack-channel="ackchannel" confirm-correlation-expression="headers['amqp_publishConfirm']"
exchange-name="dhp_exchange" routing-key-expression="headers['routingKey']" >
</int-amqp:outbound-channel-adapter>
<int:service-activator id="ackservice" input-channel="ackchannel" ref="responseHandler" method="confirmAck" />
Since you are using HTTP, you should remove the task executor and allow the web container to manage the threads. If you need more threads, do it through the web container configuration; don't use a thread handoff here; it really serves no purpose and can cause the issues you describe.

Spring integration-Service activator getting called twice

Hi this is my spring integration configuration..When i hit my service using mozilla fire fox rest console two times its getting called.For example if i hit some service in service-activator (CA request activator),On certaion un predicatable scenarios it s getting called twice.I dont know whetther it is mozilla issue or configuration issue.I tried using new window but this problem persists.In first case my service activator returning xml response properly but immediately it s getting called again.Only on rare scenarios its calling twice.
<int:channel id="accountRequest" />
<int:channel id="accountResponse" />
<int:channel id="catRequestChannel" />
<int:channel id="mataccountRequest" />
<int:channel id="errorChannel"/>
<int-http:inbound-gateway id="cwebAccountManagementGateway"
supported-methods="GET, POST"
request-channel="accountRequest"
reply-channel="accountResponse"
mapped-request-headers="*"
mapped-response-headers="*"
view-name="/policies"
path="/services/{class}/{method}"
reply-timeout="50000"
error-channel="errorChannel">
<int-http:header name="serviceClass" expression="#pathVariables.class"/>
<int-http:header name="serviceMethod" expression="#pathVariables.method"/>
</int-http:inbound-gateway>
<int:header-value-router input-channel="accountRequest"
header-name="state"
default-output-channel="accountRequest" resolution-required="false">
<int:mapping value="MA"
channel="mataccountRequest" />
<int:mapping value="CA"
channel="catRequestChannel" />
</int:header-value-router>
<int:service-activator id="accountServiceActivator"
input-channel="mataccountRequest"
output-channel="accountResponse"
ref="serviceGatewayAdapter"
method="requestHandler"
send-timeout="60000"/>
<int:service-activator id="caRequestActivator"
input-channel="catRequestChannel"
output-channel="accountResponse"
ref="caServiceGatewayAdapter"
method="requestHandler"
send-timeout="60000"/>
<int:service-activator id="errorRequestActivator"
input-channel="errorChannel"
output-channel="accountResponse"
ref="errorGatewayAdapter"
method="errorHandler"
send-timeout="60000"/>
for eg:This is my url
http://localhost:9085/springintegrationsample/create?mail=15999999#mail.com&idNumber=80010600010
if i edit the mail to some other values it ll get called twice
if i change agan it s working fine.I dont understand on what scenarios its getting called twice
You are using the same "requestHandler" for both of your service activators, so its obvious it will be called twice.
You can't know which activator is called for the handler method as when you debug you can only check for the handler method being called.
To better handle this, use different a handler method for each of your service activators. Even if they are using similar operations, it will be more clear and easy to debug.
I would suggest to add channel interceptors for logging of incoming and outgoing messages just to get a better idea.
cheers

Resources