From d748747ed48301c6810d5e1f3e94537ec2f7e002 Mon Sep 17 00:00:00 2001 From: Gustavo Martin Morcuende Date: Wed, 25 Jan 2017 23:02:20 +0100 Subject: [PATCH] Spring Kafka, fixing some errors --- SpringJava/Kafka/SpringKafka/gradle.properties | 6 +++--- .../src/main/java/de/example/spring/kafka/Application.java | 2 +- .../src/main/java/de/example/spring/kafka/SenderConfig.java | 2 ++ .../src/main/resources/application.yml | 5 ++--- .../src/main/java/de/example/spring/kafka/Application.java | 7 ------- .../src/main/java/de/example/spring/kafka/Receiver.java | 10 +--------- .../src/main/resources/application.yml | 5 ++--- 7 files changed, 11 insertions(+), 26 deletions(-) diff --git a/SpringJava/Kafka/SpringKafka/gradle.properties b/SpringJava/Kafka/SpringKafka/gradle.properties index 7d4fd97..ac10763 100644 --- a/SpringJava/Kafka/SpringKafka/gradle.properties +++ b/SpringJava/Kafka/SpringKafka/gradle.properties @@ -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 diff --git a/SpringJava/Kafka/SpringKafka/spring-kafka-consumer-example/src/main/java/de/example/spring/kafka/Application.java b/SpringJava/Kafka/SpringKafka/spring-kafka-consumer-example/src/main/java/de/example/spring/kafka/Application.java index 7448902..34409bf 100644 --- a/SpringJava/Kafka/SpringKafka/spring-kafka-consumer-example/src/main/java/de/example/spring/kafka/Application.java +++ b/SpringJava/Kafka/SpringKafka/spring-kafka-consumer-example/src/main/java/de/example/spring/kafka/Application.java @@ -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"; diff --git a/SpringJava/Kafka/SpringKafka/spring-kafka-consumer-example/src/main/java/de/example/spring/kafka/SenderConfig.java b/SpringJava/Kafka/SpringKafka/spring-kafka-consumer-example/src/main/java/de/example/spring/kafka/SenderConfig.java index 79db5d0..c82bac7 100644 --- a/SpringJava/Kafka/SpringKafka/spring-kafka-consumer-example/src/main/java/de/example/spring/kafka/SenderConfig.java +++ b/SpringJava/Kafka/SpringKafka/spring-kafka-consumer-example/src/main/java/de/example/spring/kafka/SenderConfig.java @@ -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}") diff --git a/SpringJava/Kafka/SpringKafka/spring-kafka-consumer-example/src/main/resources/application.yml b/SpringJava/Kafka/SpringKafka/spring-kafka-consumer-example/src/main/resources/application.yml index a04f533..db957d5 100644 --- a/SpringJava/Kafka/SpringKafka/spring-kafka-consumer-example/src/main/resources/application.yml +++ b/SpringJava/Kafka/SpringKafka/spring-kafka-consumer-example/src/main/resources/application.yml @@ -1,9 +1,8 @@ logging: level: org: - springframework: - ws: debug - ROOT: debug + springframework: info + ROOT: info spring: main: diff --git a/SpringJava/Kafka/SpringKafka/spring-kafka-producer-example/src/main/java/de/example/spring/kafka/Application.java b/SpringJava/Kafka/SpringKafka/spring-kafka-producer-example/src/main/java/de/example/spring/kafka/Application.java index 3c88f0a..8c533c5 100644 --- a/SpringJava/Kafka/SpringKafka/spring-kafka-producer-example/src/main/java/de/example/spring/kafka/Application.java +++ b/SpringJava/Kafka/SpringKafka/spring-kafka-producer-example/src/main/java/de/example/spring/kafka/Application.java @@ -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)); }; } diff --git a/SpringJava/Kafka/SpringKafka/spring-kafka-producer-example/src/main/java/de/example/spring/kafka/Receiver.java b/SpringJava/Kafka/SpringKafka/spring-kafka-producer-example/src/main/java/de/example/spring/kafka/Receiver.java index b606e95..c969cb2 100644 --- a/SpringJava/Kafka/SpringKafka/spring-kafka-producer-example/src/main/java/de/example/spring/kafka/Receiver.java +++ b/SpringJava/Kafka/SpringKafka/spring-kafka-producer-example/src/main/java/de/example/spring/kafka/Receiver.java @@ -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; - } } diff --git a/SpringJava/Kafka/SpringKafka/spring-kafka-producer-example/src/main/resources/application.yml b/SpringJava/Kafka/SpringKafka/spring-kafka-producer-example/src/main/resources/application.yml index a04f533..db957d5 100644 --- a/SpringJava/Kafka/SpringKafka/spring-kafka-producer-example/src/main/resources/application.yml +++ b/SpringJava/Kafka/SpringKafka/spring-kafka-producer-example/src/main/resources/application.yml @@ -1,9 +1,8 @@ logging: level: org: - springframework: - ws: debug - ROOT: debug + springframework: info + ROOT: info spring: main: -- 2.1.4