GithubHelp home page GithubHelp logo

patrickjkennedy / kafka-error-handling Goto Github PK

View Code? Open in Web Editor NEW

This project forked from bakdata/kafka-error-handling

0.0 0.0 0.0 169 KB

A library for error handling in Kafka Streams.

License: MIT License

Java 99.45% Kotlin 0.55%

kafka-error-handling's Introduction

Build Status Sonarcloud status Code coverage Maven

kafka-error-handling

A library for error handling in Kafka Streams.

Getting Started

You can add kafka-error-handling via Maven Central.

Gradle

compile group: 'com.bakdata.kafka', name: 'error-handling', version: '1.0.0'

Maven

<dependency>
    <groupId>com.bakdata.kafka</groupId>
    <artifactId>error-handling</artifactId>
    <version>1.0.0</version>
</dependency>

For other build tools or versions, refer to the latest version in MvnRepository.

Usage

If you use Kafka Streams to process your data, you will sooner or later get to the point where processing of a message throws an exception. In case your streams application is configured to process every message at least once, which is the case most times, your application will crash upon encountering an error and retry processing the erroneous message. If the error was just temporary, processing will continue as if nothing has happened. However, if the error is related to the specific message, then your streams application will be stuck processing the record. For such cases we developed three solutions that help handling errors in your Kafka Streams application.

Consider the following Topology:

final KeyValueMapper<Integer, String, KeyValue<Double, Long>> mapper = …
final KStream<Integer, String> input =
       builder.stream(INPUT_TOPIC, Consumed.with(Serdes.Integer(), Serdes.String()));

final KStream<Double, Long> mapped = input.map(mapper);
mapped.to(OUTPUT_TOPIC, Produced.with(Serdes.Double(), Serdes.Long()));

You can simply add a dead letter queue to your topology with our library:

final KeyValueMapper<Integer, String, KeyValue<Double, Long>> mapper = …
final KStream<Integer, String> input =
       builder.stream(INPUT_TOPIC, Consumed.with(Serdes.Integer(), Serdes.String()));

final KStream<Double, ProcessedKeyValue<Integer, String, Long>> mappedWithErrors =
       input.map(captureErrors(mapper));
mappedWithErrors.flatMap(ProcessedKeyValue::getErrors)
       .transformValues(DeadLetterTransformer.createDeadLetter("A good description where the pipeline broke"))
       .to(ERROR_TOPIC);

final KStream<Double, Long> mapped = mappedWithErrors.flatMapValues(ProcessedKeyValue::getValues);
mapped.to(OUTPUT_TOPIC, Produced.with(Serdes.Double(), Serdes.Long()));

Successfully processed messages are sent to the output topic as before. However, errors are sent to a specific error topic. This error topic contains dead letters describing the input value, error message and stack trace of any error that is raised in that part of your topology.

Development

If you want to contribute to this project, you can simply clone the repository and build it via Gradle. All dependencies should be included in the Gradle files, there are no external prerequisites.

> git clone [email protected]:bakdata/kafka-error-handling.git
> cd kafka-error-handling && ./gradlew build

Please note, that we have code styles for Java. They are basically the Google style guide, with some small modifications.

Contributing

We are happy if you want to contribute to this project. If you find any bugs or have suggestions for improvements, please open an issue. We are also happy to accept your PRs. Just open an issue beforehand and let us know what you want to do and why.

License

This project is licensed under the MIT license. Have a look at the LICENSE for more details.

kafka-error-handling's People

Contributors

bakdata-bot avatar philipp94831 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.