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.autoconfigure.kafka.KafkaProperties;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
-import org.springframework.util.Assert;
-
-import java.util.concurrent.Executors;
+import org.springframework.kafka.annotation.EnableKafka;
+import org.springframework.kafka.core.KafkaTemplate;
@SpringBootApplication
-@EnableConfigurationProperties(ApplicationProperties.class)
+@EnableConfigurationProperties({ KafkaProperties.class, ApplicationProperties.class })
+@EnableKafka
public class Application
{
- @Autowired
- ApplicationProperties properties;
-
-
@Bean
- public EndlessProducer producer()
+ public RestGateway restGateway(
+ ApplicationProperties applicationProperties,
+ KafkaProperties kafkaProperties,
+ KafkaTemplate<String, Integer> kafkaTemplate)
{
- Assert.hasText(properties.getBootstrapServer(), "producer.bootstrap-server must be set");
- Assert.hasText(properties.getClientId(), "producer.client-id must be set");
- Assert.hasText(properties.getTopic(), "producer.topic must be set");
-
- EndlessProducer producer =
- new EndlessProducer(
- Executors.newFixedThreadPool(1),
- properties.getBootstrapServer(),
- properties.getClientId(),
- properties.getTopic(),
- properties.getAcks(),
- properties.getThrottleMs());
-
- producer.start();
-
- return producer;
+ return
+ new RestGateway(
+ kafkaProperties.getClientId(),
+ applicationProperties.getTopic(),
+ applicationProperties.getPartition(),
+ kafkaTemplate);
}
+
public static void main(String[] args)
{
SpringApplication.run(Application.class, args);