Giter Site home page Giter Site logo

embedded-kafka's Introduction

embedded-kafka

Circle CI

A library to run an in-process Kafka broker (and the necessary Zookeeper).

At Mayvenn we use this library alongside tests that integrate with Kafka without needing the Kafka/Zookeeper to be running separately. The test broker is created in a temp directory that is deleted each time the broker is recreated, making sure to avoid test pollution. Embedding these dependencies also allows these tests to work on CI as well without requiring any extra setup.

This library is a slightly simplified/extracted version of what is used in clj-kafka for it to test itself. In the spirit of more end-to-end tests, we've found it quite useful to add just that part as a development dependency to most of our projects.

Usage

The main functions simply create an in-process broker or zookeeper. Most of the time, the convenience macro with-test-broker is all that is used. This macro provides a producer and consumer that have the appropriate configuration for the in-process broker. If instantiating your own consumer/producers, the config is available as kafka-config in order to communicate with the appropriate broker. This config is declared ^:dynamic in case there's a need to customize.

(ns ...
  (:require [embedded-kafka.core :refer [with-test-broker]]
            [gregor.core :as gregor]))

(with-test-broker producer consumer
  (gregor/subscribe consumer ["test-topic"])
  (gregor/create-topic {:connection-string "127.0.0.1:2182"} "test-topic" {})
  (.get (gregor/send producer "test-topic" "message-content"))
  (->> (gregor/poll consumer 15000)
       (take 1)
       first
       :value
       String.)) ;; "message-content"

License

This project is released under EPL, which is viewable HERE.

embedded-kafka's People

Contributors

dotemacs avatar jeffh avatar sheelc avatar

Watchers

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