Giter VIP home page Giter VIP logo

bottle-events's Introduction

Kafka Event Sourcing Python POC

This project is a proof-of-concept of an event sourcing system with Kafka and Python.

The project handles wine bottles ๐Ÿพ and their tasting review. It is composed of 3 services:

  • buyer-service: it purchases a new bottle every 5 seconds and it produces the new purchase event to the channel bottle-purchase.
  • taster-service: it waits for a new purchase by consuming from the channel bottle-purchase, then it tastes the wine and produces a review event to the channel bottle-review.
  • news-service: it waits for a new review by consuming from the channel bottle-review and print it.

Kafka

Kafka is run in a couple of Docker container managed with docker-compose. In order to run it with Docker on Mac:

$ export DOCKERHOST=$(ifconfig | grep -E "([0-9]{1,3}\.){3}[0-9]{1,3}" | grep -v 127.0.0.1 | awk '{ print $2 }' | cut -f2 -d: | head -n1)
$ docker-compose up

See: wurstmeister/kafka-docker#17 (comment)

Basic Kafka admin commands

Connect to a (Docker) kafka cli:

$ docker exec -ti kafka_kafka_1 bash

All the following command are meant to be run in a (Docker) kafka cli:

# List topics:
$ kafka-topics.sh --bootstrap-server :9092 --list

# Create a topic:
$ kafka-topics.sh --bootstrap-server :9092 --create --topic t1 --replication-factor 1 --partitions 1
# Describe a topic:
$ kafka-topics.sh --bootstrap-server :9092 --describe --topic t1

# Connect with the Kafka (interactive) console CONSUMER:
$ kafka-console-consumer.sh --bootstrap-server :9092 --topic t1
# add `--from-beginning` to consume also old messages.
# Connect with the Kafka (interactive) console PRODUCER:
$ kafka-console-producer.sh --broker-list :9092 --topic t1 --property "parse.key=true" --property "key.separator=:"
> b1:Prosecco 1990

Services

Install the requirements:

$ pip install -r requirements.txt

Then run the services in 3 different consoles:

$ cd taster-service
$ python main.py

$ cd news-service
$ python main.py

$ cd buyer-service
$ python main.py

Expect an output like: Console

bottle-events's People

Watchers

 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.