I am using spring Integration kafka outbount channel to send the messages to Kafka and i am using handler advice to handle the response to update status in database table (Success OR failure ).
<int-kafka:outbound-channel-adapter id="someID"
kafka-template="kafkaTemplate"
header-mapper="kafkaHeaderMapper"
auto-startup="true"
topic-expression="headers['topic']"
partition-id-expression="headers['partition']"
sync="true">
<int-kafka:request-handler-advice-chain>
<ref bean="requestHandlerAdvice"/>
<ref bean="retryAdvice"/>
</int-kafka:request-handler-advice-chain>
<bean id="requestHandlerAdvice"
class="org.springframework.integration.handler.advice.ExpressionEvaluatingRequestHandlerAdvice">
<property name="trapException" value="true"/>
<property name="onSuccessExpression" ref="success"/>
<property name="successChannelName" value="successChannel"/>
<property name="onFailureExpression" ref="failure"/>
<property name="failureChannelName" value="failureChannel"/>
</bean>
Few times if producer is not able to send the message due to cluster is down or some other issues then it simply print WARNING in logs and doesn’t throw exception hence my app flow assume that is success and update status in table as a SUCCESS but message was never delivered.
From logs i can see the errors
WARN [kafka-producer-network-thread | producer-1] org.apache.kafka.clients.producer.internals.Sender:624 – [Producer clientId=producer-1] Got error produce response with correlation id 155018 on topic-partition xxxxxxxxxxxxx, retrying (1 attempts left). Error: NOT_LEADER_OR_FOLLOWER
This print as WARN.
Is there any way I can catch this as as exception that we know delivery failed?
Note – I am NOT using transaction in my current flow. I was thinking if wrapping in transaction may work — any thoughts?
Thanks