+++ /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 consumer-1 consumer-2
-sleep 15
-
-docker compose -f docker/docker-compose.yml stop producer
-
-echo
-echo "Von consumer-1 empfangen:"
-docker compose -f docker/docker-compose.yml logs consumer-1 | grep '\ test\/.'
-echo
-echo "Von consumer-2 empfangen:"
-docker compose -f docker/docker-compose.yml logs consumer-2 | grep '\ test\/.'
-
-docker compose -f docker/docker-compose.yml stop consumer-1 consumer-2
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
-import org.springframework.kafka.support.serializer.JsonSerializer;
import java.time.Duration;
import java.util.Properties;
@Bean
public ExampleProducer exampleProducer(
ApplicationProperties properties,
- Producer<String, SumupMessage> kafkaProducer,
+ Producer<String, String> kafkaProducer,
ConfigurableApplicationContext applicationContext)
{
return
}
@Bean(destroyMethod = "")
- public KafkaProducer<String, SumupMessage> kafkaProducer(ApplicationProperties properties)
+ public KafkaProducer<String, String> kafkaProducer(ApplicationProperties properties)
{
Properties props = new Properties();
props.put("bootstrap.servers", properties.getBootstrapServer());
props.put("linger.ms", properties.getProducerProperties().getLinger().toMillis());
props.put("compression.type", properties.getProducerProperties().getCompressionType());
props.put("key.serializer", StringSerializer.class.getName());
- props.put("value.serializer", JsonSerializer.class.getName());
- props.put("spring.json.type.mapping", "ADD:de.juplo.kafka.AddNumberMessage,CALC:de.juplo.kafka.CalculateSumMessage");
+ props.put("value.serializer", StringSerializer.class.getName());
return new KafkaProducer<>(props);
}
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,
Runnable closeCallback)
{
this.id = id;
? new CalculateSumMessage(number)
: new AddNumberMessage(number, i);
- send(Long.toString(number), message);
+ send(Long.toString(number), message.toString());
if (throttle.isPositive())
{
}
}
- void send(String key, SumupMessage value)
+ void send(String key, String value)
{
final long time = System.currentTimeMillis();
- final ProducerRecord<String, SumupMessage> record = new ProducerRecord<>(
+ final ProducerRecord<String, String> record = new ProducerRecord<>(
topic, // Topic
key, // Key
value // Value