add request response
This commit is contained in:
@@ -56,7 +56,10 @@ public class AbstractEvent {
|
||||
return json;
|
||||
}
|
||||
|
||||
public void sendMessage(String json){
|
||||
public void publish(){
|
||||
this.publish(this.toJson());
|
||||
}
|
||||
public void publish(String json){
|
||||
if( json != null ){
|
||||
|
||||
/**
|
||||
|
||||
@@ -75,7 +75,7 @@ public class Order {
|
||||
@ExceptionHandler(OrderException.class)
|
||||
private void publishOrderPlaced(){
|
||||
OrderPlaced orderPlaced = new OrderPlaced(this);
|
||||
orderPlaced.sendMessage(orderPlaced.toJson());
|
||||
orderPlaced.publish();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -91,7 +91,7 @@ public class Order {
|
||||
Order order = orderOptional.get();
|
||||
|
||||
OrderCancelled orderCancelled = new OrderCancelled(order);
|
||||
orderCancelled.sendMessage(orderCancelled.toJson());
|
||||
orderCancelled.publish();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -16,9 +16,7 @@ public class OrderCancelled extends AbstractEvent{
|
||||
private String customerName;
|
||||
|
||||
public OrderCancelled(){
|
||||
this.setEventType(this.getClass().getSimpleName());
|
||||
SimpleDateFormat defaultSimpleDateFormat = new SimpleDateFormat("YYYYMMddHHmmss");
|
||||
this.timestamp = defaultSimpleDateFormat.format(new Date());
|
||||
super();
|
||||
}
|
||||
|
||||
public OrderCancelled(Order order){
|
||||
|
||||
@@ -20,13 +20,13 @@ public class OrderController {
|
||||
@Autowired
|
||||
RestTemplate restTemplate;
|
||||
|
||||
@Value("${delivery.api.url:http://delivery:8080/startDelivery}")
|
||||
@Value("${delivery.api.url:http://delivery:8080}")
|
||||
private String remoteURL;
|
||||
|
||||
@GetMapping("/order")
|
||||
ResponseEntity<String> fakeOrder() {
|
||||
@PostMapping("/order")
|
||||
ResponseEntity<String> fakeOrder(@RequestBody String data) {
|
||||
try {
|
||||
ResponseEntity<String> responseEntity = restTemplate.getForEntity(remoteURL, String.class);
|
||||
ResponseEntity<String> responseEntity = restTemplate.postForEntity(remoteURL + "/startDelivery", data, String.class);
|
||||
String response = responseEntity.getBody();
|
||||
return ResponseEntity.ok(String.format(RESPONSE_STRING_FORMAT, response.trim()));
|
||||
} catch (Exception ex) {
|
||||
|
||||
@@ -18,9 +18,7 @@ public class OrderPlaced extends AbstractEvent{
|
||||
private String customerAddr;
|
||||
|
||||
public OrderPlaced(){
|
||||
this.setEventType(this.getClass().getSimpleName());
|
||||
SimpleDateFormat defaultSimpleDateFormat = new SimpleDateFormat("YYYYMMddHHmmss");
|
||||
this.timestamp = defaultSimpleDateFormat.format(new Date());
|
||||
super();
|
||||
}
|
||||
|
||||
public OrderPlaced(Order order){
|
||||
|
||||
@@ -39,6 +39,9 @@ spring:
|
||||
# org.springframework.cloud: debug
|
||||
|
||||
productUrl: http://localhost:8085
|
||||
delivery:
|
||||
api:
|
||||
url: http://localhost:8082
|
||||
|
||||
server:
|
||||
port: 8081
|
||||
|
||||
@@ -31,7 +31,8 @@ import java.util.Collections;
|
||||
// provide the [group-id]:[artifact-id]
|
||||
@AutoConfigureStubRunner(stubsMode = StubRunnerProperties.StubsMode.LOCAL, ids = "com.example:boot-camp-products")
|
||||
//@AutoConfigureStubRunner(
|
||||
// repositoryRoot="http://34.85.54.161:8081/repository/maven-snapshots/",
|
||||
// repositoryRoot="https://pkgs.dev.azure.com/eventstorming/_packaging/eventstorming/maven/v1/",
|
||||
//// repositoryRoot="http://34.85.54.161:8081/repository/maven-snapshots/",
|
||||
// ids = "com.example:boot-camp-products:+:stubs:8090",
|
||||
// stubsMode = StubRunnerProperties.StubsMode.REMOTE
|
||||
//)
|
||||
|
||||
Reference in New Issue
Block a user