add request response
This commit is contained in:
22
pom.xml
22
pom.xml
@@ -2,6 +2,7 @@
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<parent>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-parent</artifactId>
|
||||
@@ -26,6 +27,7 @@
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-web</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-data-rest</artifactId>
|
||||
@@ -85,6 +87,26 @@
|
||||
|
||||
</dependencies>
|
||||
|
||||
<!-- <repositories>-->
|
||||
<!-- <repository>-->
|
||||
<!-- <id>eventstorming</id>-->
|
||||
<!-- <url>https://pkgs.dev.azure.com/eventstorming/_packaging/eventstorming/maven/v1</url>-->
|
||||
<!-- <releases>-->
|
||||
<!-- <enabled>true</enabled>-->
|
||||
<!-- </releases>-->
|
||||
<!-- <snapshots>-->
|
||||
<!-- <enabled>true</enabled>-->
|
||||
<!-- </snapshots>-->
|
||||
<!-- </repository>-->
|
||||
<!-- </repositories>-->
|
||||
<!-- <distributionManagement>-->
|
||||
<!-- <repository>-->
|
||||
<!-- <id>eventstorming</id>-->
|
||||
<!-- <url>https://pkgs.dev.azure.com/eventstorming/_packaging/eventstorming/maven/v1</url>-->
|
||||
<!-- </repository>-->
|
||||
<!-- </distributionManagement>-->
|
||||
|
||||
|
||||
<dependencyManagement>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
|
||||
10
settings_maven.xml
Normal file
10
settings_maven.xml
Normal file
@@ -0,0 +1,10 @@
|
||||
<settings xmlns="http://maven.apache.org/SETTINGS/1.1.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.1.0 http://maven.apache.org/xsd/settings-1.1.0.xsd">
|
||||
<servers>
|
||||
<server>
|
||||
<id>eventstorming</id>
|
||||
<username>eventstorming</username>
|
||||
<password>k6hx3hjbjnxw2g6avk2j4skr6md2ruanva7ryjfraqaqn2bwcvsq</password>
|
||||
</server>
|
||||
</servers>
|
||||
</settings>
|
||||
@@ -55,7 +55,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 ){
|
||||
|
||||
/**
|
||||
|
||||
@@ -32,7 +32,7 @@ public class Product {
|
||||
@PostPersist @PostUpdate
|
||||
private void publishStart() {
|
||||
ProductChanged productChanged = new ProductChanged(this);
|
||||
productChanged.sendMessage(productChanged.toJson());
|
||||
productChanged.publish();
|
||||
}
|
||||
|
||||
public Long getId() {
|
||||
|
||||
@@ -14,9 +14,7 @@ public class ProductChanged extends AbstractEvent{
|
||||
private String imageUrl;
|
||||
|
||||
public ProductChanged(){
|
||||
this.setEventType(this.getClass().getSimpleName());
|
||||
SimpleDateFormat defaultSimpleDateFormat = new SimpleDateFormat("YYYYMMddHHmmss");
|
||||
this.timestamp = defaultSimpleDateFormat.format(new Date());
|
||||
super();
|
||||
}
|
||||
|
||||
public ProductChanged(Product product){
|
||||
|
||||
@@ -1,14 +1,31 @@
|
||||
package com.example.template;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
@RestController
|
||||
public class ProductController {
|
||||
|
||||
|
||||
private static final String RESPONSE_STRING_FORMAT = "product change from '%s': %d";
|
||||
private final Logger logger = LoggerFactory.getLogger(getClass());
|
||||
|
||||
@Autowired
|
||||
ProductService productService;
|
||||
|
||||
private int count = 0;
|
||||
|
||||
private static final String HOSTNAME = parseContainerIdFromHostname(
|
||||
System.getenv().getOrDefault("HOSTNAME", "deliveries"));
|
||||
|
||||
static String parseContainerIdFromHostname(String hostname) {
|
||||
return hostname.replaceAll("deliveries-v\\d+-", "");
|
||||
}
|
||||
|
||||
|
||||
@GetMapping("/product/{productId}")
|
||||
Product productStockCheck(@PathVariable(value = "productId") Long productId) {
|
||||
|
||||
@@ -27,4 +44,20 @@ public class ProductController {
|
||||
System.out.println(data);
|
||||
return this.productService.save(data);
|
||||
}
|
||||
|
||||
|
||||
@PatchMapping("/product/{productId}")
|
||||
ResponseEntity<String> fakeProductPatch(@PathVariable(value = "productId") Long productId, @RequestBody String data) {
|
||||
|
||||
count++;
|
||||
logger.info(String.format("product start from %s: %d", HOSTNAME, count));
|
||||
|
||||
try {
|
||||
Thread.sleep(500);
|
||||
} catch (InterruptedException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
return ResponseEntity.ok(String.format(RESPONSE_STRING_FORMAT, HOSTNAME, count));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user