2

I am facing an issue with spring integration error-channel with maprstream.

I have created my own error channel to perform few steps if any exception occurs in normal flow. But I don't want the error channel to be called if there are any exception in sendMessageToMaprstream flow. Because I am expecting it run as a separate thread.

     <int:chain input-channel="errorChannel">
        <int:transformer ref="transformExcep" method="transform"/>
        <int:service-activator ref="dosomeTask"/>
        <int:recipient-list-router>
                <int:recipient channel="sendMessageToMaprstream"/>
        </int:recipient-list-router>
    </int:chain>

    <task:executor id="executor" pool-size="10" />
    <int:publish-subscribe-channel id="sendMessageToMaprstream" task-executor="executor"/>      

    <int-kafka:outbound-channel-adapter 
       id="kafkaOutboundChannelAdapter"
       channel="sendMessageToMaprstream"
       kafka-template="template"
       topic="${maprstream.topicname}"
       message-key-expression="'exp'">                                 
   </int-kafka:outbound-channel-adapter>

With the above configuration, the error channel is getting executed as a infinite loop if there are any exception in sendMessageToMaprstream. Can someone please help me to skip the errors from sendMessageToMaprstream ?

Updated section:

                 <int-kafka:outbound-channel-adapter 
                                id="kafkaOutboundChannelAdapter"
                                channel="sendMessageToMaprstream"
                                kafka-template="template"
                                topic="${maprstream.topicname}"
                                message-key-expression="'exp'"> 
                                    <int-kafka:request-handler-advice-chain>
                                      <bean class="org.springframework.integration.handler.advice.ExpressionEvaluatingRequestHandlerAdvice">
                                       <property name="failureChannel" ref="nullChannel"/>
                                       <property name="trapException" value="true"/>
                                      </bean>
                                   </int-kafka:request-handler-advice-chain>
                        </int-kafka:outbound-channel-adapter>
kattoor
  • 195
  • 14

1 Answers1

2

Well, it's not good at all to swallow exception without at least some logs.

For your task you can use ExpressionEvaluatingRequestHandlerAdvice with its failureChannel and trapException = true options:

<int-kafka:request-handler-advice-chain>
        <bean class="org.springframework.integration.handler.advice.ExpressionEvaluatingRequestHandlerAdvice">
            <property name="failureChannel" ref=" sendMessageToMaprstreamErrors"/>
        </bean>
            <property name="onFailureExpression" value="#root"/>
            <property name="trapException" value="true"/>
    </int-kafka:request-handler-advice-chain>

See more info in the Reference Manual.

Artem Bilan
  • 113,505
  • 11
  • 91
  • 118
  • Thanks a lot giving a leads to the solution. Please check the updated section in the main question and it seems to be working, it's skipping the infinite loop. But I have one query on failureChannel reference. It seems that the failureChannel won't get execute irrespective of the trapException value (true/false). Because when I change the value of trapException as true, it skipped the exception. but when I changed the value of trapException as false then its going to continuous loop. Could you please clarify it? – kattoor Feb 21 '18 at 10:07
  • Please note that I had used a valid reference of failureChannel instead of nullChannel. – kattoor Feb 21 '18 at 10:17
  • 1
    Yeah... Sorry, I have missed this part ``. Without an `onFailureExpression` it isn't going to go to the `failureChannel`. The `#root` there means the `requestMessage`. – Artem Bilan Feb 21 '18 at 15:34
  • Thanks Artem, yes now it is going to the reference channel when the trapException==false. I tried with a nullChannel as output-channel as mentioned below, I was just logging the exception in this handler, but it seems this handler is invoked infinitely. Could you please let me know how can I stop this once entered into the handler? – kattoor Feb 22 '18 at 08:29