Spring Cloud Stream Partitioning Sample
========================================

These sample apps demonstrate how partitioning works in Spring Cloud Stream with Apache Kafka.
Sample producer and consumer are provided.

## Quick introduction

The producer used in the sample produces messages with text that has a length of 1, 2, 3 or 4.
There is a configuration in the producer's application.yml file for `partition-key-expression` that uses the length of the payload minus 1 as the partition key expression to use.
This value will be used by the binder for selecting the correct partition based on the total number of partitions configured on the destination at the broker.
We use 4 partitions for this demo.

## Running the samples

The following instructions assume that you are running Kafka as a Docker image.

* `docker-compose up -d`

* Ensure that you are in the directory `kafka-partitioning`

* `./mvnw clean package`

* `java -jar partitioning-consumer-sample-kafka/target/partitioning-consumer-sample-kafka-0.0.1-SNAPSHOT.jar --server.port=9008`

On another termimal start another instance of the consumer.

* `java -jar partitioning-consumer-sample-kafka/target/partitioning-consumer-sample-kafka-0.0.1-SNAPSHOT.jar --server.port=9009`

On another terminal start the producer.

* `java -jar partitioning-producer-sample-kafka/target/partitioning-producer-sample-kafka-0.0.1-SNAPSHOT.jar --server.port=9010`

Producer sends messages randomly that has string length of 1, 2, 3, or 4.
Watch the consumer console logs and verify that the correct partitions are receiving the messages.
The log message has the payload and partition information in it.

Once you are done testing, stop all the instances.

* `docker-compose down`
