spring-kafka

Configuring Spring Kafka to use DeadLetterPublishingRecoverer

最后都变了- 提交于 2019-12-11 03:24:06
问题 I'm using Spring Boot 2.1.3 and am trying to configure Spring SeekToCurrentErrorHandler with a DeadLetterPublishingRecoverer to send error records to a different topic. The new DLT queue is created and a record is inserted but the message body is empty. I was expecting the message body to be populated with the original JSON body for future analysis. Here is the configuration I have so far. Any idea where I'm going wrong? Not sure if its to do with using kafkaTemplate<Object, Object> where as

Update Kafka commit offset after successful batch insert

时光总嘲笑我的痴心妄想 提交于 2019-12-11 03:13:00
问题 I have a spring-kafka consumer which reads records and hands them over to a cache. A scheduled task will clear the records in the cache periodically. I want to update the COMMIT OFFSET only after a batch has been successfully saved in the database. I tried passing the acknowledgment object to the cache service to invoke the acknowledge method as shown below. public class KafkaConsumer { @KafkaListener( topicPattern = "${kafka.topicpattern}", containerFactory = "kafkaListenerContainerFactory"

cant connect to kafka from external machine

人走茶凉 提交于 2019-12-11 02:43:18
问题 I´m starting with Apache Kafka and i´m facing problems when i try to conect from an external machine. With this configuration bellow, all works fine if the application and the docker are running at the same machine. but when i put the application in machine A and docker at machine B, the application cant connect. My spring Kafka @Configuration have this line to @Bean consumerFactory and producerFactory (imagine my machine with docker ip = 10.10.10.10) props.put(ConsumerConfig.BOOTSTRAP

Spring-Kafka Concurrency Property

自古美人都是妖i 提交于 2019-12-11 02:42:52
问题 I am progressing on writing my first Kafka Consumer by using Spring-Kafka. Had a look at the different options provided by framework, and have few doubts on the same. Can someone please clarify below if you have already worked on it. Question - 1 : As per Spring-Kafka documentation, there are 2 ways to implement Kafka-Consumer; "You can receive messages by configuring a MessageListenerContainer and providing a message listener or by using the @KafkaListener annotation". Can someone tell when

Error to serialize message when sending to kafka topic

[亡魂溺海] 提交于 2019-12-11 02:06:12
问题 i need to test a message, which contains headers, so i need to use MessageBuilder, but I can not serialize. I tried adding the serialization settings on the producer props but it did not work. Can someone help me? this error: org.apache.kafka.common.errors.SerializationException: Can't convert value of class org.springframework.messaging.support.GenericMessage to class org.apache.kafka.common.serialization.StringSerializer specified in value.serializer My test class: public class

Unable to unit test a @KafkaListener annotated method

こ雲淡風輕ζ 提交于 2019-12-11 01:57:40
问题 I'm trying to unit test a kafka consumer class, in Spring. I want to know that if a kafka message is sent to it's topic, the listener method was called correctly. My consumer class is annotated like this: @KafkaListener(topics = "${kafka.topics.myTopic}") public void myKafkaMessageEvent(final String message) { ... If I @Autowire a consumer, when I send a kafka message, the listener method is called correctly, but I can't assert that the method was called because the class isn't a mock. If I

Reactive Kafka : Exactly Once Processing with Transaction

孤者浪人 提交于 2019-12-11 00:34:58
问题 Initially triggered via api call 1. Service A produces m1 to topic1 (non transactional send) 2. Service B consumes topic1 and does some processing (begin tx) 3. Service B produces m2 to topic2 (commit tx) 4. Service A consumes topic2 (begin tx) Here is my producer config: final Map<String, Object> props = Maps.newConcurrentMap(); props.put(ProducerConfig.BOOTSTRAP_SERVERS_CONFIG, bootstrapServers); props.put(ProducerConfig.KEY_SERIALIZER_CLASS_CONFIG, StringSerializer.class); props.put

ClassNotFoundException with Kafka consumer

旧时模样 提交于 2019-12-11 00:24:10
问题 I have a Kafka consumer application, written with Spring Boot 2.0.2. When I receive the message in my listener, I get the following error: Caused by: org.springframework.messaging.converter.MessageConversionException: failed to resolve class name. Class not found [com.test.demo.domain.Account]; nested exception is java.lang.ClassNotFoundException: com.test.demo.domain.Account The class name of the object in the Producer is " com.test.demo.domain.Account " but I have a different package and

Handle failure in case the Kafka Broker is down

时光总嘲笑我的痴心妄想 提交于 2019-12-11 00:04:08
问题 I have a Kafka broker running where messages are consumed successfully but I want to handle the case where Kafka Broker is down on the Kafka Consumer end. I have read this thread but came to know that the logs are shown at DEBUG level. I was wondering if I can handle this manually on an event trigger may be because I want to handle the failure of Kafka broker myself. Does Spring Kafka provide something to handle this situation? Please tell me if any more details are needed. I would highly

Spring Boot - Getting the hostname in application.properties for Spring-Kafka client Id

陌路散爱 提交于 2019-12-10 22:23:38
问题 I am working on a project with Spring-Kafka and Boot and am wanting to get the hostname in the application.properties for the property spring.kafka.consumer.client-Id so that each of my consumers can be distinguished in the server side logs should there be an issue. Is there a way i could do that? I check on the spring boot reference guide and java.lang.System class but could not find fruitful pointers. 回答1: Here's one way - add an EnvironmentAware bean to your config...