Giter VIP home page Giter VIP logo

with-kafka's Introduction

with-kafka

About

This repository is a study in event sourcing and CQRS architectures. See this blog post for details. It is an implementation of a distributed calculator.

There are two commands availiable:

  • POST /values accepts {"value" : <f64>} returns HTTP/202 and an id (UUID) of the accepted value.
  • PUT /values/{id} accepts ={"operation" : <OPERATION>, "value" : 3} where OPERATION can be ADD or MULTIPLY, it returns HTTP/202

There is one query path constructed from the events:

  • GET /values/{id} returns {"value" : <current-value>}

Prerequisites

Install confluent hub client:

curl -O http://client.hub.confluent.io/confluent-hub-client-latest.tar.gz
# add to .bashrc:
export PATH="<path-to>/confluent-hub-client-latest/bin:$PATH"
# test
confluent-hub help

Architecture

[Client]

package "API" {
  package "/queries" {
  [queries]
  [subscriptions]
  }
  package "/commands" {
    [Commander]
  }
}

database "Message store" {
  folder "Retention: forever" {
    [commands topic] as ct
  }  
  [events topic] as et
  [other topics]
}

package "Command Processor" {
  [Command Handler] as CH
  database "state" {
    [Business model]
  }
}

node "Aggregate views" {
  [consumers]
  database "views" {
  }
}

Client .down.> Commander
Client .down.> subscriptions
Client .down.> queries
queries <.down. views

Commander .down.> ct : Commands 
ct ..> CH : business logic
CH ..> et : Events

et .> subscriptions

et .> consumers
consumers .> views

Development

Start docker containers:

docker-compose -f docker-compose.yml up

Start watcher

cargo watch -s "cargo run"

Send some commands:

curl -d '{"value": 2}' -H "Content-Type: application/json" -X POST http://localhost:3030/values
# => 2753b941-eb10-497c-b58c-2b3dec1eeeef
curl -d '{"operation": "ADD", "value": 2}' -H "Content-Type: application/json" -X PUT http://localhost:3030/values/2753b941-eb10-497c-b58c-2b3dec1eeeef
curl -d '{"operation": "MULTIPLY", "value": 3}' -H "Content-Type: application/json" -X PUT http://localhost:3030/values/2753b941-eb10-497c-b58c-2b3dec1eeeef

Query the materialized view:

curl -X GET -H "Content-Type: application/json" http://localhost:3030/values/2753b941-eb10-497c-b58c-2b3dec1eeeef

with-kafka's People

Contributors

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