* Problem: Beendet sich nicht sauber...
* Grund: Die Endlosschleife läuft _in_ der Initialisierungs-Phase!
#!/bin/bash
-IMAGE=juplo/supersimple-producer:1.0-SNAPSHOT
+IMAGE=juplo/endless-spring-producer:1.0-SNAPSHOT
if [ "$1" = "cleanup" ]
then
docker-compose -f docker/docker-compose.yml up -t0 -d cli
docker-compose -f docker/docker-compose.yml ps
-docker-compose -f docker/docker-compose.yml up producer
+docker-compose -f docker/docker-compose.yml up -d producer
-# tag::kafkacat[]
-kafkacat -b :9092 -t test -e -f'topic=%t\tpartition=%p\toffset=%o\tkey=%k\tvalue=%s\n'
-# end::kafkacat[]
+kafkacat -b :9092 -t test -c 100 -f'topic=%t\tpartition=%p\toffset=%o\tkey=%k\tvalue=%s\n'
+
+docker-compose stop producer
</parent>
<groupId>de.juplo.kafka</groupId>
- <artifactId>supersimple-producer</artifactId>
- <name>Super Simple Producer</name>
- <description>Most minimal Kafka Producer ever!</description>
+ <artifactId>endless-spring-producer</artifactId>
+ <name>Super Simple Endless Producer</name>
+ <description>Most minimal endless Kafka Producer ever!</description>
<version>1.0-SNAPSHOT</version>
<properties>
import org.springframework.util.concurrent.ListenableFuture;
-// tag::supersimple[]
@Slf4j
@SpringBootApplication
public class Application implements ApplicationRunner
@Override
public void run(ApplicationArguments args)
{
- for (int i = 0; i < 100; i++)
+ for (int i = 0; true; i++)
{
- // end::supersimple[]
- // tag::callback[]
ListenableFuture<SendResult<String, String>> listenableFuture =
- // tag::supersimple[]
kafkaTemplate.sendDefault(Long.toString(i%10), Long.toString(i));
- // end::supersimple[]
listenableFuture.addCallback(
result -> log.info(
result.getRecordMetadata().partition(),
result.getRecordMetadata().offset()),
e -> log.error("ERROR sendig message", e));
- // end::callback[]
- // tag::supersimple[]
}
}
SpringApplication.run(Application.class, args);
}
}
-// end::supersimple[]