+++ /dev/null
-#!/bin/bash
-
-IMAGE=juplo/spring-producer:1.0-json-SNAPSHOT
-
-if [ "$1" = "cleanup" ]
-then
- docker compose -f docker/docker-compose.yml down -t0 -v --remove-orphans
- mvn clean
- exit
-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
-
-if [[
- $(docker image ls -q $IMAGE) == "" ||
- "$1" = "build"
-]]
-then
- mvn clean install || exit
-else
- echo "Using image existing images:"
- docker image ls $IMAGE
-fi
-
-docker compose -f docker/docker-compose.yml up --remove-orphans setup || exit 1
-
-
-docker compose -f docker/docker-compose.yml up -d producer
-docker compose -f docker/docker-compose.yml up -d peter ute
-sleep 15
-
-docker compose -f docker/docker-compose.yml stop producer
-
-echo
-echo "Von peter empfangen:"
-docker compose -f docker/docker-compose.yml logs peter | grep '\ test\/.'
-echo
-echo "Von ute empfangen:"
-docker compose -f docker/docker-compose.yml logs ute | grep '\ test\/.'
-
-docker compose -f docker/docker-compose.yml stop peter ute
public ExampleProducer exampleProducer(
@Value("${spring.kafka.client-id}") String clientId,
ApplicationProperties properties,
- Producer<String, SumupMessage> kafkaProducer,
+ Producer<String, String> kafkaProducer, // << TODO: Typisierung anpassen
ConfigurableApplicationContext applicationContext)
{
return
private final String id;
private final String topic;
private final Duration throttle;
- private final Producer<String, SumupMessage> producer;
+ private final Producer<String, String> producer;
private final Thread workerThread;
private final Runnable closeCallback;
String id,
String topic,
Duration throttle,
- Producer<String, SumupMessage> producer,
+ Producer<String, String> producer, // << TODO: Typisierung anpassen
Runnable closeCallback)
{
this.id = id;
? new CalculateSumMessage(number)
: new AddNumberMessage(number, i);
- send(Long.toString(number), message);
-
- if (throttle.isPositive())
- {
- try
- {
- Thread.sleep(throttle);
- }
- catch (InterruptedException e)
- {
- log.warn("{} - Interrupted while throttling!", e);
- }
- }
+ // TODO: Versenden aus Ihrer bisherigen Implementierung (inkl. Logging & Zählen)
+ // ABER: Anstatt der Zahl soll "message" als JSON serialisiert verschickt werden
}
}
catch (Exception e)
}
}
- void send(String key, SumupMessage value)
- {
- final long time = System.currentTimeMillis();
-
- final ProducerRecord<String, SumupMessage> record = new ProducerRecord<>(
- topic, // Topic
- key, // Key
- value // Value
- );
-
- producer.send(record, (metadata, e) ->
- {
- long now = System.currentTimeMillis();
- if (e == null)
- {
- // HANDLE SUCCESS
- log.debug(
- "{} - Sent message {}={}, partition={}, offset={}, timestamp={}, latency={}ms",
- id,
- key,
- value,
- metadata.partition(),
- metadata.offset(),
- metadata.timestamp(),
- now - time
- );
- }
- else
- {
- // HANDLE ERROR
- log.error(
- "{} - ERROR for message {}={}, latency={}ms: {}",
- id,
- key,
- value,
- now - time,
- e.toString()
- );
- }
- });
-
- long now = System.currentTimeMillis();
- produced++;
- log.trace(
- "{} - Queued message {}={}, latency={}ms",
- id,
- key,
- value,
- now - time
- );
- }
-
public void shutdown() throws InterruptedException
{