Spring Kafka, fixing some errors
authorGustavo Martin Morcuende <gu.martinm@gmail.com>
Wed, 25 Jan 2017 22:02:20 +0000 (23:02 +0100)
committerGustavo Martin Morcuende <gu.martinm@gmail.com>
Wed, 25 Jan 2017 22:02:20 +0000 (23:02 +0100)
SpringJava/Kafka/SpringKafka/gradle.properties
SpringJava/Kafka/SpringKafka/spring-kafka-consumer-example/src/main/java/de/example/spring/kafka/Application.java
SpringJava/Kafka/SpringKafka/spring-kafka-consumer-example/src/main/java/de/example/spring/kafka/SenderConfig.java
SpringJava/Kafka/SpringKafka/spring-kafka-consumer-example/src/main/resources/application.yml
SpringJava/Kafka/SpringKafka/spring-kafka-producer-example/src/main/java/de/example/spring/kafka/Application.java
SpringJava/Kafka/SpringKafka/spring-kafka-producer-example/src/main/java/de/example/spring/kafka/Receiver.java
SpringJava/Kafka/SpringKafka/spring-kafka-producer-example/src/main/resources/application.yml

index 7d4fd97..ac10763 100644 (file)
@@ -1,3 +1,3 @@
-theGroup='de.example.spring.kafka'
-theName='spring-kafka-example'
-theVersion='1.0-SNAPSHOT'
+theGroup=de.example.spring.kafka
+theName=spring-kafka-example
+theVersion=1.0-SNAPSHOT
index 7448902..34409bf 100644 (file)
@@ -15,7 +15,7 @@ public class Application {
   @Bean
   CommandLineRunner lookup(Sender sender) {
     return args -> {
-      String topic = "example.topic";
+      String topic = "test";
       String message = "example message";
 
 
index 79db5d0..c82bac7 100644 (file)
@@ -5,6 +5,7 @@ import org.apache.kafka.common.serialization.IntegerSerializer;
 import org.apache.kafka.common.serialization.StringSerializer;
 import org.springframework.beans.factory.annotation.Value;
 import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Configuration;
 import org.springframework.kafka.core.DefaultKafkaProducerFactory;
 import org.springframework.kafka.core.KafkaTemplate;
 import org.springframework.kafka.core.ProducerFactory;
@@ -12,6 +13,7 @@ import org.springframework.kafka.core.ProducerFactory;
 import java.util.HashMap;
 import java.util.Map;
 
+@Configuration
 public class SenderConfig {
 
   @Value("${kafka.bootstrap.servers}")
index 3c88f0a..8c533c5 100644 (file)
@@ -15,14 +15,7 @@ public class Application {
   @Bean
   CommandLineRunner lookup(Receiver receiver) {
     return args -> {
-      String sleepTime = "60000";
 
-
-      if (args.length > 0) {
-        sleepTime = args[0];
-      }
-
-      Thread.sleep(Long.valueOf(sleepTime));
     };
   }
 
index b606e95..c969cb2 100644 (file)
@@ -4,21 +4,13 @@ import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.springframework.kafka.annotation.KafkaListener;
 
-import java.util.concurrent.CountDownLatch;
-
 public class Receiver {
 
   private static final Logger LOGGER = LoggerFactory.getLogger(Receiver.class);
 
-  private CountDownLatch latch = new CountDownLatch(1);
-
-  @KafkaListener(topics = "example.topic")
+  @KafkaListener(topics = "test")
   public void receiveMessage(String message) {
     LOGGER.info("received message='{}'", message);
-    latch.countDown();
   }
 
-  public CountDownLatch getLatch() {
-    return latch;
-  }
 }