15 Ocak 2023 Pazar

SpringKafka Consumer DeadLetterPublishingRecoverer Sınıfı

Giriş
Şu satırı dahil ederiz
import org.springframework.kafka.listener.DeadLetterPublishingRecoverer;
Şöyle yaparız
@Bean(name = "invoiceDltContainerFactory")
public ConcurrentKafkaListenerContainerFactory<Object, Object> listenerContainerFactory(
  ConcurrentKafkaListenerContainerFactoryConfigurer configurer, 
  KafkaTemplate<String, String> kafkaTemplate) {


  var factory = new ConcurrentKafkaListenerContainerFactory<Object, Object>();
  configurer.configure(factory, consumerFactory());

  
  var recoverer = new DeadLetterPublishingRecoverer(kafkaTemplate, 
    (record, ex) -> new TopicPartition("t-invoice-dead", record.partition()));

  factory.setCommonErrorHandler(new DefaultErrorHandler(recoverer, new FixedBackOff(1000,5)));

  return factory;
}


Hiç yorum yok:

Yorum Gönder