topicname 일괄 변경

This commit is contained in:
kimscott
2019-09-02 15:49:00 +09:00
parent 8d25923887
commit 4badc0e3ab
2 changed files with 5 additions and 2 deletions

View File

@@ -4,6 +4,7 @@ import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.apache.kafka.clients.producer.ProducerRecord;
import org.springframework.beans.BeanUtils;
import org.springframework.core.env.Environment;
import org.springframework.kafka.core.KafkaTemplate;
import javax.persistence.*;
@@ -38,7 +39,9 @@ public class Product {
}
if( json != null ){
ProducerRecord producerRecord = new ProducerRecord<>("eventTopic", json);
Environment env = Application.applicationContext.getEnvironment();
String topicName = env.getProperty("eventTopic");
ProducerRecord producerRecord = new ProducerRecord<>(topicName, json);
kafkaTemplate.send(producerRecord);
}
}

View File

@@ -18,7 +18,7 @@ public class ProductService {
@Autowired
ProductRepository productRepository;
@KafkaListener(topics = "eventTopic")
@KafkaListener(topics = "${eventTopic}")
public void onListener(@Payload String message, ConsumerRecord<?, ?> consumerRecord) {
System.out.println("##### listener : " + message);