이벤트 프로세스 수정
This commit is contained in:
@@ -1,15 +1,33 @@
|
||||
package com.example.template;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.context.annotation.Lazy;
|
||||
|
||||
import javax.annotation.PostConstruct;
|
||||
|
||||
@SpringBootApplication
|
||||
public class Application {
|
||||
|
||||
public static ApplicationContext applicationContext;
|
||||
protected static ApplicationContext applicationContext;
|
||||
public static void main(String[] args) {
|
||||
applicationContext = SpringApplication.run(Application.class, args);
|
||||
|
||||
ProductRepository productRepository = applicationContext.getBean(ProductRepository.class);
|
||||
// 초기 상품 셋팅
|
||||
String[] products = {"TV", "RADIO", "NOTEBOOK", "TABLE", "CLOCK"};
|
||||
int i = 1;
|
||||
for(String p : products){
|
||||
Product product = new Product();
|
||||
product.setName(p);
|
||||
product.setPrice(i*10000);
|
||||
product.setStock(i*10);
|
||||
product.setImageUrl("https://github.githubassets.com/images/modules/profile/profile-joined-github.png");
|
||||
i++;
|
||||
productRepository.save(product);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -19,6 +19,7 @@ public class Product {
|
||||
String name;
|
||||
int price;
|
||||
int stock;
|
||||
String imageUrl;
|
||||
|
||||
@PostPersist @PostUpdate
|
||||
private void publishStart() {
|
||||
@@ -32,6 +33,7 @@ public class Product {
|
||||
productChanged.setProductName(this.name);
|
||||
productChanged.setProductPrice(this.price);
|
||||
productChanged.setProductStock(this.stock);
|
||||
productChanged.setImageUrl(this.imageUrl);
|
||||
try {
|
||||
json = objectMapper.writeValueAsString(productChanged);
|
||||
} catch (JsonProcessingException e) {
|
||||
@@ -46,6 +48,14 @@ public class Product {
|
||||
}
|
||||
}
|
||||
|
||||
public Long getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(Long id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
@@ -69,4 +79,12 @@ public class Product {
|
||||
public void setStock(int stock) {
|
||||
this.stock = stock;
|
||||
}
|
||||
|
||||
public String getImageUrl() {
|
||||
return imageUrl;
|
||||
}
|
||||
|
||||
public void setImageUrl(String imageUrl) {
|
||||
this.imageUrl = imageUrl;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,8 @@
|
||||
package com.example.template;
|
||||
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Date;
|
||||
|
||||
public class ProductChanged extends AbstractEvent{
|
||||
|
||||
private String stateMessage = "상품 변경이 발생함";
|
||||
@@ -9,9 +12,12 @@ public class ProductChanged extends AbstractEvent{
|
||||
private String productName;
|
||||
private int productPrice;
|
||||
private int productStock;
|
||||
private String imageUrl;
|
||||
|
||||
public ProductChanged(){
|
||||
this.setEventType(this.getClass().getSimpleName());
|
||||
SimpleDateFormat defaultSimpleDateFormat = new SimpleDateFormat("YYYYMMddHHmmss");
|
||||
this.timestamp = defaultSimpleDateFormat.format(new Date());
|
||||
}
|
||||
|
||||
public String getStateMessage() {
|
||||
@@ -53,4 +59,12 @@ public class ProductChanged extends AbstractEvent{
|
||||
public void setProductStock(int productStock) {
|
||||
this.productStock = productStock;
|
||||
}
|
||||
|
||||
public String getImageUrl() {
|
||||
return imageUrl;
|
||||
}
|
||||
|
||||
public void setImageUrl(String imageUrl) {
|
||||
this.imageUrl = imageUrl;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,6 +8,7 @@ import org.springframework.kafka.annotation.KafkaListener;
|
||||
import org.springframework.messaging.handler.annotation.Payload;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import javax.annotation.PostConstruct;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
|
||||
@@ -1,4 +0,0 @@
|
||||
insert into Product(id, name, price, stock) values (1, 'TV', 1000, 100);
|
||||
insert into Product(id, name, price, stock) values (2, 'RADIO', 500, 100);
|
||||
insert into Product(id, name, price, stock) values (3, 'PHONE', 100, 50);
|
||||
insert into Product(id, name, price, stock) values (4, 'NOTEBOOK', 2000, 100);
|
||||
Reference in New Issue
Block a user