topicname 일괄 변경
This commit is contained in:
@@ -4,6 +4,7 @@ import com.fasterxml.jackson.core.JsonProcessingException;
|
|||||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||||
import org.apache.kafka.clients.producer.ProducerRecord;
|
import org.apache.kafka.clients.producer.ProducerRecord;
|
||||||
import org.springframework.beans.BeanUtils;
|
import org.springframework.beans.BeanUtils;
|
||||||
|
import org.springframework.core.env.Environment;
|
||||||
import org.springframework.kafka.core.KafkaTemplate;
|
import org.springframework.kafka.core.KafkaTemplate;
|
||||||
|
|
||||||
import javax.persistence.*;
|
import javax.persistence.*;
|
||||||
@@ -38,7 +39,9 @@ public class Product {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if( json != null ){
|
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);
|
kafkaTemplate.send(producerRecord);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -18,7 +18,7 @@ public class ProductService {
|
|||||||
@Autowired
|
@Autowired
|
||||||
ProductRepository productRepository;
|
ProductRepository productRepository;
|
||||||
|
|
||||||
@KafkaListener(topics = "eventTopic")
|
@KafkaListener(topics = "${eventTopic}")
|
||||||
public void onListener(@Payload String message, ConsumerRecord<?, ?> consumerRecord) {
|
public void onListener(@Payload String message, ConsumerRecord<?, ?> consumerRecord) {
|
||||||
System.out.println("##### listener : " + message);
|
System.out.println("##### listener : " + message);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user