Coder Social home page Coder Social logo

datanerds-io / verteiler Goto Github PK

View Code? Open in Web Editor NEW
7.0 10.0 3.0 33 KB

Meine dispatcher says there's something wrong mit deine Kabel. Java 8 BlockingQueue Kafka Consumer with automatically maintained offset.

License: Apache License 2.0

Java 100.00%
kafka java kafka-consumer consumer

verteiler's Introduction

Build Status

Maven Central

Verteiler (fɛɐˈtailɐ)

"Verteiler" is german and translates to distributor. When you are using the (new) kafka-clients consumer introduced with v0.9.0, you will face the issue that Consumer.poll(...) can only be called from one thread. Verteiler leverages the kafka-client consumer implementation to distribute messages from assigned partitions to BlockingQueues. Each assigned partition will relay its messages to its own internal queue. These queues have worker threads which process the message leveraging a user defined consumer. Once a message has been processed successfully its offset will be committed asynchronously after poll(...) has finished. This way only the offset of processed messages is committed.

How to use verteiler

BlockingQueueConsumer

Parameters

String topic: Name of the topic you want to consume messages from.

Properties kafkaConfig: Regular consumer config. By default verteiler will disable auto offset commit and set a client id when not given.

int queueSize: Size of the internal queue, which depends on your needs.

java.util.function.Consumer<V> action: The function which will handle a message.

Example

Simple message counter:

Properties props = new Properties();
props.setProperty(BOOTSTRAP_SERVERS_CONFIG, "127.0.0.1:9092");
...
AtomicInteger messageCounter = new AtomicInteger();
Consumer<String> action = (message) -> messageCounter.incrementAndGet();

BlockingQueueConsumer<String, String> consumer = new BlockingQueueConsumer<>("my_topic", props, 42, action);
consumer.start();

For a full example take a look at BlockingQueueConsumerTest.

Build

gradle build will build the project. The integration tests will start embedded zookeeper & kafka instances.

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.