2
votes

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>
1

1 Answers

2
votes

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.