Git Product home page Git Product logo

akkastreams-kafka-example's Introduction

akka-streams-kafka-example

An example project using Akka Streams with Kafka and a Schema Registry.

It uses the Alpakka Kafka Connector to write messages in Avro format.

The Alpakka Kafka Connector documentation provides clear examples on how to use Akka Streams with Kafka. It doesn't provide an example on how to use Akka Streams with Avro and a Schema Registry.

This project provides an example on how to do this.

Kafka itself is agnostic in regard to the message format, but Avro with a Schema Registry is the preferred solution. A message format with a schema like e.g. Avro and a Schema Registry or Protocol buffers compared to a message format without a schema like JSON has the advantage that it is known what the message contains. Also backwards compatiblity can be maintained when evolving the schema.

Using Avro with a Schema Registry has the advantage that the schema definition doesn't has to be added to every single message, but the schema is registered in the Schema Registry and a reference to the schema is stored in the messages.

avro4s is used in this example project to automatically generate the schema from the Scala case class and to serialize and deserialize the case class.

Running the project

To run the project, you need to have Docker Compose installed. In the root directory of the project you do a docker-compose up and wait until Zookeeper, Kafka and the Schema Registry have been started. Do a docker ps to verify that you have a running Zookeeper, Kafka, and Schema Registry.

After that you can start the producer with sbt "runMain KafkaProducer" and the consumer with sbt "runMain KafkaConsumer".

The sample producer KafkaProducer will create a few instances of SampleEvent and serialize them in Avro format and send them to the Kafka topic mytopic.

The sample consumer KafkaConsumer will read from the topic mytopic and deserialize the messages into instances of SampleEvent and log these instances.

In this example project the consumer will automatically stop after 30 seconds.

akkastreams-kafka-example'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.