Coder Social home page Coder Social logo

clojure-kafka-graalvm-native-image's Introduction

clojure-kafka-graavm-native-image

It turns out that it is possible to compile Kafka Producer and Consumer with GraalVM native-image and the demo is all in Clojure.

TL;DR

make build-clj-kafka && ./clj-kafka

Demo

It will start a background thread with a Kafka Producer that every second sends a message to the Kafka. And in the main thread it'll launch a Kafka Consumer that polls for messages from the same topic as is used by the producer. Process doesn't stop.

Cool thing is that the binary starts instantly and use ~28 mb of RAM.

./clj-kafka   0.01s  user 0.02s system 0% cpu 4.168 total
avg shared (code):         0 KB
avg unshared (data/stack): 0 KB
total (sum):               0 KB
max memory:                28 MB
page faults from disk:     0
other page faults:         1488

Params

Environment variables are used:

  • BOOTSTRAP_SERVERS_CONFIG: Kafka brokers, default value "127.0.0.1:9092"
  • TOPIC: kafka topic name, default value "test"

Optional

Start Kafka cluster in docker-compose in another terminal:

make run-dev-env

Requirements

Linux, Docker, docker-compose, clojure.

For MacOS download GraalVM, install native-image, set JAVA_HOME, add native-image to PATH and run:

clojure -A:native-image

Or in one step:

(JAVA_HOME=/home/user/graalvm-ce-java11-20.0.0/ && PATH=/home/user/graalvm-ce-java11-20.0.0/bin:$PATH && clojure -A:native-image)

License

Copyright © 2020 Dainius Jocas.

Distributed under the The Apache License, Version 2.0.

clojure-kafka-graalvm-native-image's People

Contributors

dainiusjocas avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

clojure-kafka-graalvm-native-image's Issues

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.