GithubHelp home page GithubHelp logo

julianpistorius / clojure-es-kafka Goto Github PK

View Code? Open in Web Editor NEW

This project forked from dackerman/clojure-es-kafka

0.0 2.0 0.0 156 KB

Event Sourcing example using Clojure and a Kafka queue for events

License: Eclipse Public License 1.0

Shell 4.84% Clojure 95.16%

clojure-es-kafka's Introduction

Codeship Status for dackerman/clojure-es-kafka

clojure-es-kafka

Example code running an Event Sourcing implementation with a Kafka queue integrated.

Installation

Download from https://github.com/dackerman/clojure-es-kafka.

Usage

It's easiest to run from lein. First you need to start up a kafka instance for this to work. If you install kafka in ~/programs/kafka_2.10-0.8.1.1/ then this will "just work", otherwise you need to update the shell scripts manually to point to your instance.

First, start the zookeeper instance in one process:

$ ./start-zk.sh

Then, start kafka:

$ ./start-kafka.sh

After that, you will want to create the topic "events" if you don't have auto-create setup.

$ ./create-topic.sh

Now you can run the program:

$ lein run {produce, consume}

Options

  • produce: start a producer that takes commands as input and creates events based on a clojure domain model. It applies them to the in-memory event store and publishes those events to a kafka stream.
  • consume: start a kafka consumer and transform the events to a projection as data comes in.

Examples

This example starts up a producer and creates a "case", then "closes" it. Imagine "cases" as tasks to be assigned to a fraud investigator.

[dackerman@stacktrace clojure-kafka]$ lein run produce
Ready for input
ReferCase 1234 dave
 #domain.cases.Case{:case-key 2b67ca4b-958c-417c-bde1-d8708536bc8b, :primary-entity 1234, :assignee dave, :status :open}
CloseCase 2b67ca4b-958c-417c-bde1-d8708536bc8b
#domain.cases.Case{:case-key 2b67ca4b-958c-417c-bde1-d8708536bc8b, :primary-entity 1234, :assignee dave, :status :closed}
events
#eventstore.eventstore.Event{:id 0, :aggregate-key "2b67ca4b-958c-417c-bde1-d8708536bc8b", :aggregate-version 0, :type domain.cases.CaseReferredEvent, :payload #domain.cases.CaseReferredEvent{:case-key "2b67ca4b-958c-417c-bde1-d8708536bc8b", :claim-number "1234", :assignee "dave"}}
#eventstore.eventstore.Event{:id 1, :aggregate-key "2b67ca4b-958c-417c-bde1-d8708536bc8b", :aggregate-version 1, :type  domain.cases.CaseClosedEvent, :payload #domain.cases.CaseClosedEvent{}}

Here's an example of using the consumer:

[dackerman@stacktrace clojure-kafka]$ lein run consume events
------------------------------------

{:open (), :closed ("2b67ca4b-958c-417c-bde1-d8708536bc8b")}
 nil

------------------------------------

{:open ("2b67ca4b-958c-417c-bde1-d8708536bc8b"),
 :closed ("2b67ca4b-958c-417c-bde1-d8708536bc8b")}
 nil

License

Copyright © 2014 David Ackerman

Distributed under the Eclipse Public License either version 1.0 or (at your option) any later version.

clojure-es-kafka's People

Contributors

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