Giter VIP home page Giter VIP logo

faust-docker-compose-example's Introduction

Faust-Docker-Compose

Build Status License

An example to show how to include a faust project as a service using docker compose, with Kafka, Zookeeper and Schema Registry

Notice that everything runs using docker-compose, including the faust example application. For local development is preferable to run the kafka cluster separate from the faust app.

If you want to generate a faust project from scratch, please use the cookiecutter-faust

Read more about Faust here: https://github.com/robinhood/faust

Project

The project skeleton is defined as a medium/large project according to faust layout

The setup.py has the entrypoint to resolve the entrypoint problem

Applications

Faust Project Dockerfile

The Dockerfile is based on python:3.7-slim. The most important here is that the entrypoint will wait for kafka too be ready and after that execute the script run.sh

Docker compose

docker-compose.yaml includes zookeepeer, kafka and schema-registry based on confluent-inc. For more information you can go to confluentinc and see the docker compose example here

Useful ENVIRONMENT variables that you may change:

Variable description example
WORKER Entrypoint in setup.py example
WORKER_PORT Worker port 6066
KAFKA_BOOSTRAP_SERVER Kafka servers kafka://kafka:9092
KAFKA_BOOSTRAP_SERVER_NAME Kafka server name kafka
KAFKA_BOOSTRAP_SERVER_PORT Kafka server port 9092
SCHEMA_REGISTRY_SERVER Schema registry server name schema-registry
SCHEMA_REGISTRY_SERVER_PORT Schema registry server port 8081
SCHEMA_REGISTRY_URL Schema Registry Server url http://schema-registry:8081

Commands

  • Start application: make run-dev. This command start both the Page Views and Leader Election applications
  • Stop and remove containers: make clean
  • List topics: make list-topics
  • Send events to page_view topic/agent: make send-page-view-event payload='{"id": "foo", "user": "bar"}'

Avro Schemas, Custom Codecs and Serializers

Because we want to be sure that the message that we encode are valid we use Avro Schemas. Avro is used to define the data schema for a record's value. This schema describes the fields allowed in the value, along with their data types.

For our demostration in the Users application we are using the following schema:

{
    "type": "record",
    "namespace": "com.example",
    "name": "AvroUsers",
    "fields": [
        {"name": "first_name", "type": "string"},
        {"name": "last_name", "type": "string"}
    ]
}

In order to use avro schemas with Faust we need to define a custom codec, a custom serializer and be able to talk with the schema-registry. You can find the custom codec called avro_users registered using the codec registation approach described by faust. The AvroSerializer is in charge to encode and decode messages using the schema registry client.

Now the final step is to integrate the faust model with the AvroSerializer.

# users.models

class UserModel(faust.Record, serializer='avro_users'):
    first_name: str
    last_name: str

Now our application is able to send and receive message using arvo schemas!!!! :-)

Tests

Run tests with tox. Make sure that you have installed it.

tox

Achievements

  • Application examples
  • Integration with Schma Registry
  • Schema Registry Client
  • Custom codecs
  • Custom Serializers
  • Avro Schemas
  • Make Schema Registry Client and Serializers a python package

faust-docker-compose-example's People

Contributors

georgi-tide avatar marcosschroh avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

faust-docker-compose-example's Issues

Add Faust application that can interact with schema-registry

We should add another application that can read the avro schemas, serialize and read message.

Describe the solution you'd like
The docker-compose is ready, the app can get the schema-registry URL, we are missing how Faust will get the schemas. There is a piece of code under utils which probably will do the work. Also, we should create some schemas and mounted when docker compose is up.

Can't run it...

> make run-dev

Log:
...
faust-project_1 | DNS fwd/rev mismatch: schema-registry != schema-registry.faust-docker-compose-example_default
faust-project_1 | schema-registry [172.23.0.4] 8081 (tproxy) open
faust-project_1 | Schema Registry is up - executing command
faust-project_1 | Executing command ./run.sh
faust-project_1 | + export SIMPLE_SETTINGS=settings
faust-project_1 | + example worker --web-port=6066
faust-project_1 | Traceback (most recent call last):
faust-project_1 | File "/usr/local/bin/example", line 10, in
faust-project_1 | from importlib.metadata import distribution
faust-project_1 | ModuleNotFoundError: No module named 'importlib.metadata'
faust-project_1 |
faust-project_1 | During handling of the above exception, another exception occurred:
faust-project_1 |
faust-project_1 | Traceback (most recent call last):
faust-project_1 | File "/usr/local/bin/example", line 13, in
faust-project_1 | from importlib_metadata import distribution
faust-project_1 | ModuleNotFoundError: No module named 'importlib_metadata'
faust-project_1 |
faust-project_1 | During handling of the above exception, another exception occurred:
faust-project_1 |
faust-project_1 | Traceback (most recent call last):
faust-project_1 | File "/usr/local/lib/python3.7/site-packages/pkg_resources/init.py", line 567, in _build_master
faust-project_1 | ws.require(requires)
faust-project_1 | File "/usr/local/lib/python3.7/site-packages/pkg_resources/init.py", line 884, in require
faust-project_1 | needed = self.resolve(parse_requirements(requirements))
faust-project_1 | File "/usr/local/lib/python3.7/site-packages/pkg_resources/init.py", line 775, in resolve
faust-project_1 | raise VersionConflict(dist, req).with_context(dependent_req)
faust-project_1 | pkg_resources.ContextualVersionConflict: (fastavro 0.22.3 (/usr/local/lib/python3.7/site-packages), Requirement.parse('fastavro<0.25,>=0.24'), {'python-schema-registry-client'})
faust-project_1 |
faust-project_1 | During handling of the above exception, another exception occurred:
faust-project_1 |
faust-project_1 | Traceback (most recent call last):
faust-project_1 | File "/usr/local/bin/example", line 15, in
faust-project_1 | from pkg_resources import load_entry_point
faust-project_1 | File "/usr/local/lib/python3.7/site-packages/pkg_resources/init.py", line 3238, in
faust-project_1 | @_call_aside
faust-project_1 | File "/usr/local/lib/python3.7/site-packages/pkg_resources/init.py", line 3222, in _call_aside
faust-project_1 | f(*args, **kwargs)
faust-project_1 | File "/usr/local/lib/python3.7/site-packages/pkg_resources/init.py", line 3251, in _initialize_master_working_set
faust-project_1 | working_set = WorkingSet._build_master()
faust-project_1 | File "/usr/local/lib/python3.7/site-packages/pkg_resources/init.py", line 569, in _build_master
faust-project_1 | return cls._build_from_requirements(requires)
faust-project_1 | File "/usr/local/lib/python3.7/site-packages/pkg_resources/init.py", line 582, in _build_from_requirements
faust-project_1 | dists = ws.resolve(reqs, Environment())
faust-project_1 | File "/usr/local/lib/python3.7/site-packages/pkg_resources/init.py", line 775, in resolve
faust-project_1 | raise VersionConflict(dist, req).with_context(dependent_req)
faust-project_1 | pkg_resources.ContextualVersionConflict: (fastavro 0.22.3 (/usr/local/lib/python3.7/site-packages), Requirement.parse('fastavro<0.25,>=0.24'), {'python-schema-registry-client'})
faust-docker-compose-example_faust-project_1 exited with code 1

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.