Skip to content
Advertisement

Spring Integration with Kafka throwing ClassCastException

I have a case where i want to publish message from Kafka Producer, My message is just a POJO object e.g CreateRequest. So for consuming I have added below code

JavaScript

Also,I have added setMessageConverter and setPayloadType to get response of type CreateResponse but still i am getting response of type KafkaMessageSource which is throwing java.lang.ClassCastException cannot cast KafkaMessageSource to type CreateResponse

JavaScript

Stacktrace:-

JavaScript

Can somebody tell where i am going wrong?

Advertisement

Answer

Here is a simple Spring Boot app which demonstrates that intention of the mentioned configuration is correct:

JavaScript

I’m not sure what is your CreateResponse, so I have it as simple as this:

JavaScript

Then I have a integration test to verify it against an embedded Kafka:

JavaScript

If I change that consumeMsg() to this (pay attention to the commented @Bean):

JavaScript

// @Bean @InboundChannelAdapter(channel = “inputChannel”, poller=@Poller(fixedDelay = “5000”)) public KafkaMessageSource consumeMsg() {

JavaScript

Then it indeed fails with the:

JavaScript

So, please, revise the configuration on your side.

User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement