I am trying to create Apache Kafka consumer / listener on SAP Commerce application. I have followed basic steps which are given in the link:
But unable to create the listener. The below error occurs on the server startup. Please advise.
ERROR [localhost-startStop-7] [HybrisContextFactory] Error initializing global application context!
java.lang.IllegalArgumentException: Unable to determine source type <S> and target type <T> for your Converter [de.hybris.platform.converters.impl.AbstractPopulatingConverter]; does the class parameterize those types?
at org.springframework.core.convert.support.GenericConversionService.addConverter(GenericConversionService.java:93) ~[spring-core-5.3.18.jar:5.3.18]
at org.springframework.kafka.annotation.KafkaListenerAnnotationBeanPostProcessor.addFormatters(KafkaListenerAnnotationBeanPostProcessor.java:1057) ~[spring-kafka-2.9.0.jar:2.9.0]
at org.springframework.kafka.annotation.KafkaListenerAnnotationBeanPostProcessor.afterSingletonsInstantiated(KafkaListenerAnnotationBeanPostProcessor.java:318) ~[spring-kafka-2.9.0.jar:2.9.0]
at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:972) ~[spring-beans-5.3.18.jar:5.3.18]
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:918) ~[spring-context-5.3.18.jar:5.3.18]
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:583) ~[spring-context-5.3.18.jar:5.3.18]
at de.hybris.platform.core.HybrisContextFactory.refreshContext(HybrisContextFactory.java:88) ~[coreserver.jar:?]
at de.hybris.platform.core.HybrisContextFactory$ApplicationContextFactory.build(HybrisContextFactory.java:256) ~[coreserver.jar:?]
at de.hybris.platform.core.HybrisContextHolder.getApplicationInstance(HybrisContextHolder.java:78) ~[coreserver.jar:?]
at de.hybris.platform.core.AbstractTenant.createCoreApplicationContext(AbstractTenant.java:763) ~[coreserver.jar:?]
at de.hybris.platform.core.AbstractTenant.doStartupSafe(AbstractTenant.java:804) ~[coreserver.jar:?]
at de.hybris.platform.core.AbstractTenant.doStartUp(AbstractTenant.java:735) ~[coreserver.jar:?]
The error occurs because there is OOTB hybris converter
de.hybris.platform.converters.impl.AbstractPopulatingConverter
This is causing the IllegalArgumentException. But this OOTB converter is not required. So, to avoid this error you can follow the steps given in the documentation as below.
Implement KafkaListenerConfigurer with your class for example,
@Configuration
@EnableKafka
public class AppConfig implements KafkaListenerConfigurer {}
This will let you implement the method:
public void configureKafkaListeners(KafkaListenerEndpointRegistrar registrar) {}
Set the custom myMessageHandlerMethodFactory
registrar.setMessageHandlerMethodFactory(myMessageHandlerMethodFactory);
Create and add below in your config class
@Bean
public MessageHandlerMethodFactory myMessageHandlerMethodFactory() {
DefaultMessageHandlerMethodFactory factory = new DefaultMessageHandlerMethodFactory();
// factory configuration
return factory;
}