Giter VIP home page Giter VIP logo

clojure-kafka-examples's Introduction

About

A selection of examples using Kafka and Kafka Streams with Clojure. I wanted to learn the real Kafka API via Clojure not via a Clojure wrapper so here are examples of using the raw API, which is clean and means you do not need to wait for Clojure wrapper libraries to upgrade Kafka.

A guide to the examples can be find in this post here.

Prerequisites

Expected to be able to set up Zookeeper and Kafka Broker to run the examples. Or use the Confluent platform. The Kafka Stream Examples all have relevant tests rather than running a Jar. Please check individual module README to check how to run.

Unit Test

Check out the unit tests for each file to see it in action without the need for running with Zookeeper and Kafka.

Examples

  • Kafka Producer and Consumer in Clojure using Java interop.
  • Search a Topic and return records that match a Key from beginning to current point in time.
  • Kafka Streaming example to upper case of strings.
  • Kafka Streaming testing example.
  • Kafka Streaming join with two Streams (Left Join, Inner Join, Outer Join)
  • Kafka Streaming join with KTABLE.
  • Avro Kafka deserialization and serialization.
  • KStreamGroup Aggregate
  • TopologyTestDriver
  • More examples to come regularly watch this space ...

Integration Testcontainers

Testcontainers provide the ability to test applications that have docker interactions simply by starting up your containers in our examples Kafka we can then start our applications up against this container and run the tests in a fully integrated test with Kafka. Awesome!

Kafka and Zookeeper

We have provided our own docker-compose file that will start Kafka and Zookeeper via localhost, so other containers or local apps can access the broker.

Start this using the command docker-compose up -d

version: '3'
services:
  zookeeper:
    image: confluentinc/cp-zookeeper:5.4.1
    hostname: zookeeper
    container_name: zookeeper
    ports:
      - "2181:2181"
    environment:
      ZOOKEEPER_CLIENT_PORT: 2181
      ZOOKEEPER_TICK_TIME: 2000
  broker:
    image: confluentinc/cp-enterprise-kafka:5.4.1
    hostname: broker
    container_name: broker
    depends_on:
      - zookeeper
    ports:
      - "29092:29092"
      - "9092:9092"
    environment:
      KAFKA_BROKER_ID: 1
      KAFKA_ZOOKEEPER_CONNECT: 'zookeeper:2181'
      KAFKA_LISTENER_SECURITY_PROTOCOL_MAP: PLAINTEXT:PLAINTEXT,PLAINTEXT_HOST:PLAINTEXT
      KAFKA_ADVERTISED_LISTENERS: PLAINTEXT://broker:29092,PLAINTEXT_HOST://localhost:9092
      KAFKA_OFFSETS_TOPIC_REPLICATION_FACTOR: 1
      KAFKA_GROUP_INITIAL_REBALANCE_DELAY_MS: 0

Contributions

  • Please get involved and get recognition. If you want to add more examples then raise a PR. Or raise issues for ideas on examples that would be beneficial.

clojure-kafka-examples's People

Contributors

perkss 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.