#!/bin/bash
-IMAGE=juplo/simple-producer:1.0-SNAPSHOT
+IMAGE=juplo/simple-producer:1.0-auditheaders-SNAPSHOT
if [ "$1" = "cleanup" ]
then
fi
docker compose -f docker/docker-compose.yml up -d --remove-orphans kafka-1 kafka-2 kafka-3
-docker compose -f docker/docker-compose.yml rm -svf producer
+docker compose -f docker/docker-compose.yml rm -svf setup peter ute
if [[
$(docker image ls -q $IMAGE) == "" ||
docker compose -f docker/docker-compose.yml up --remove-orphans setup || exit 1
-docker compose -f docker/docker-compose.yml up -d producer
-sleep 5
+docker compose -f docker/docker-compose.yml up -d peter ute
+sleep 10
-docker compose -f docker/docker-compose.yml exec cli kafkacat -b kafka:9092 -t test -c 20 -f'topic=%t\tpartition=%p\toffset=%o\tkey=%k\tvalue=%s\n'
-docker compose -f docker/docker-compose.yml stop producer
-docker compose -f docker/docker-compose.yml exec cli kafkacat -b kafka:9092 -t test -e -f'topic=%t\tpartition=%p\toffset=%o\tkey=%k\tvalue=%s\n'
-docker compose -f docker/docker-compose.yml logs producer
+echo
+echo "Empfangen:"
+docker compose -f docker/docker-compose.yml exec cli kafkacat -b kafka:9092 -t test -e -c 100
+
+echo
+echo "Empfangen (mit Headern!):"
+docker compose -f docker/docker-compose.yml exec cli kafkacat -b kafka:9092 -t test -e -c 100 -J
- kafka-3
producer:
- image: juplo/simple-producer:1.0-SNAPSHOT
+ image: juplo/simple-producer:1.0-auditheaders-SNAPSHOT
command: kafka:9092 test producer
+ foo:
+ image: juplo/simple-producer:1.0-auditheaders-SNAPSHOT
+ command: kafka:9092 test foo
+
+ bar:
+ image: juplo/simple-producer:1.0-auditheaders-SNAPSHOT
+ command: kafka:9092 test bar
+
+ consumer:
+ image: juplo/simple-consumer:1.0-SNAPSHOT
+ command: kafka:9092 test my-group consumer
+
+ peter:
+ image: juplo/simple-consumer:1.0-SNAPSHOT
+ command: kafka:9092 test my-group peter
+
+ ute:
+ image: juplo/simple-consumer:1.0-SNAPSHOT
+ command: kafka:9092 test my-group ute
+
volumes:
zookeeper-data:
zookeeper-log:
<artifactId>simple-producer</artifactId>
<name>Super Simple Producer</name>
<description>A Simple Producer, programmed with pure Java, that sends messages via Kafka</description>
- <version>1.0-SNAPSHOT</version>
+ <version>1.0-auditheaders-SNAPSHOT</version>
<properties>
<java.version>21</java.version>
import org.apache.kafka.clients.producer.ProducerRecord;
import org.apache.kafka.common.serialization.StringSerializer;
+import java.math.BigInteger;
import java.util.Properties;
@Slf4j
public class ExampleProducer
{
+ public final static String HEADER_ID = "id";
+ public final static String HEADER_PRODUCED = "#";
+
private final String id;
private final String topic;
private final Producer<String, String> producer;
value // Value
);
+ record
+ .headers()
+ .add(HEADER_ID, id.getBytes())
+ .add(HEADER_PRODUCED, BigInteger.valueOf(produced).toByteArray());
+
producer.send(record, (metadata, e) ->
{
long now = System.currentTimeMillis();