Kafka callback issues with overloaded methods in java

46 views Asked by At

We have two micro-services transfer and approval. The request from transfer will be sent to approval and once approved the funds are transferred. During the submission of approval, there is a Kafka call back from approval to transfer based on which the transfer happens.

Initially, there was only one concept of approval, the callbacks were coming fine. Then there was another concept of conditional approval, so once the conditional approval was submitted we needed to send a new callback for a different approach.

Both the callbacks were written inside a single class (annotated as @Service) and accepted as two different methods, with of course two different topics. So as the second callback was configured the calls from the approval service stopped, but from the logs there was nothing wrong with the approval service so we figured that issue was with the newly written callback.

Due to some hasty copy & paste the developer had accidentally given the two callback methods the same name but with a different arguments/payloads.

@KafkaListener(topics = TransferConstants.APPROVAL_TOPIC, containerFactory = "ApprovalConcurrentKafkaListenerContainerFactory")
public void listen(@Payload Payload approvalRequest) {}


@KafkaListener(topics = TransferConstants.CONDITIONAL_APPROVAL_TOPIC, containerFactory = "ApprovalConcurrentKafkaListenerContainerFactory")
public void listen(@Payload ConditionalApprovalPayload conditionalApprovalRequest) {}

Once we changed the method names both the callbacks came and it was fine. So, the doubts are

  1. Why the callback won't come just because the methods have the same name, even when topics and payloads are different?
  2. What happens internally in Kafka that blocks the callback?
  3. How does the method name come into the picture?
0

There are 0 answers