Skip to content

Instantly share code, notes, and snippets.

@schroedermatt
Created January 7, 2020 22:05
Show Gist options
  • Select an option

  • Save schroedermatt/923756374efc9f5afc685f089211acaa to your computer and use it in GitHub Desktop.

Select an option

Save schroedermatt/923756374efc9f5afc685f089211acaa to your computer and use it in GitHub Desktop.
A custom implementation of a Kafka Streams ProductionExceptionHandler that uses a SpringContext bridge to access beans.
public class CustomExceptionHandler implements ProductionExceptionHandler {
private ExceptionService exceptionService;
public ProductionExceptionHandlerResponse handle(final ProducerRecord<byte[], byte[]> record, final Exception exception) {
boolean shouldContinue = exceptionService.handleProductionException(record, exception);
return shouldContinue ? CONTINUE : FAIL;
}
@Override
public void configure(Map<String, ?> configs) {
// tap into SpringContext to get the ExceptionService bean
this.exceptionService = SpringContext.getBean(ExceptionService.class);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment