--- /dev/null
+package de.juplo.kafka;
+
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.boot.SpringApplication;
+import org.springframework.boot.autoconfigure.SpringBootApplication;
+import org.springframework.boot.context.event.ApplicationReadyEvent;
+import org.springframework.context.event.EventListener;
+import org.springframework.scheduling.annotation.EnableAsync;
+
+
+@SpringBootApplication
+@EnableAsync
+public class Application
+{
+ @Autowired
+ ExampleProducer producer;
+
+ @EventListener(ApplicationReadyEvent.class)
+ public void onApplicationReady()
+ {
+ producer.run();
+ }
+
+ public static void main(String[] args)
+ {
+ SpringApplication.run(ExampleProducer.class, args);
+ }
+}
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.boot.ApplicationArguments;
-import org.springframework.boot.ApplicationRunner;
-import org.springframework.boot.SpringApplication;
-import org.springframework.boot.autoconfigure.SpringBootApplication;
-import org.springframework.boot.context.event.ApplicationReadyEvent;
-import org.springframework.context.event.EventListener;
import org.springframework.kafka.core.KafkaTemplate;
import org.springframework.kafka.support.SendResult;
import org.springframework.scheduling.annotation.Async;
-import org.springframework.scheduling.annotation.EnableAsync;
+import org.springframework.stereotype.Component;
import java.util.concurrent.CompletableFuture;
@Slf4j
-@EnableAsync
// tag::supersimple[]
-@SpringBootApplication
+@Component
public class ExampleProducer
{
@Autowired
KafkaTemplate<String, String> kafkaTemplate;
- // end::supersimple[]
@Async
- // tag::supersimple[]
public void run()
{
for (int i = 0; true; i++)
// tag::supersimple[]
}
}
- // end::supersimple[]
-
- @EventListener(ApplicationReadyEvent.class)
- public void onApplicationReady() {
- this.run();
- }
-
- // tag::supersimple[]
- public static void main(String[] args)
- {
- SpringApplication.run(ExampleProducer.class, args);
- }
}
// end::supersimple[]