set up nacos
This commit is contained in:
parent
03d361dd08
commit
64d60634e2
7
pom.xml
7
pom.xml
@ -61,6 +61,13 @@
|
|||||||
<version>20250517</version>
|
<version>20250517</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.alibaba.cloud</groupId>
|
||||||
|
<artifactId>spring-cloud-starter-alibaba-nacos-config</artifactId>
|
||||||
|
<version>2025.0.0.0-preview</version>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.springframework.boot</groupId>
|
<groupId>org.springframework.boot</groupId>
|
||||||
<artifactId>spring-boot-starter-test</artifactId>
|
<artifactId>spring-boot-starter-test</artifactId>
|
||||||
|
|||||||
@ -6,6 +6,8 @@ import com.ljc42.product.Exceptions.ProductExitsException;
|
|||||||
import com.ljc42.product.Exceptions.ProductNotFoundException;
|
import com.ljc42.product.Exceptions.ProductNotFoundException;
|
||||||
import com.ljc42.product.Service.ProductService;
|
import com.ljc42.product.Service.ProductService;
|
||||||
import org.json.JSONObject;
|
import org.json.JSONObject;
|
||||||
|
import org.springframework.beans.factory.annotation.Value;
|
||||||
|
import org.springframework.cloud.context.config.annotation.RefreshScope;
|
||||||
import org.springframework.http.HttpStatus;
|
import org.springframework.http.HttpStatus;
|
||||||
import org.springframework.http.ResponseEntity;
|
import org.springframework.http.ResponseEntity;
|
||||||
import org.springframework.web.bind.annotation.*;
|
import org.springframework.web.bind.annotation.*;
|
||||||
@ -14,14 +16,23 @@ import java.util.Map;
|
|||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
|
|
||||||
@RestController
|
@RestController
|
||||||
|
@RefreshScope
|
||||||
public class ProductController {
|
public class ProductController {
|
||||||
|
|
||||||
private final ProductService productService;
|
private final ProductService productService;
|
||||||
|
|
||||||
|
@Value(value = "${product.service.welcome-message}")
|
||||||
|
private String welcomeMessage;
|
||||||
|
|
||||||
public ProductController(ProductService productService) {
|
public ProductController(ProductService productService) {
|
||||||
this.productService = productService;
|
this.productService = productService;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@GetMapping("/api/v1/hello")
|
||||||
|
public ResponseEntity<String> hello() {
|
||||||
|
return new ResponseEntity<>(welcomeMessage, HttpStatus.OK);
|
||||||
|
}
|
||||||
|
|
||||||
@GetMapping("/api/v1/product/{name}")
|
@GetMapping("/api/v1/product/{name}")
|
||||||
public ResponseEntity<ResponseDTO> getProducts(@PathVariable String name) {
|
public ResponseEntity<ResponseDTO> getProducts(@PathVariable String name) {
|
||||||
try {
|
try {
|
||||||
|
|||||||
@ -1,9 +0,0 @@
|
|||||||
package com.ljc42.product;
|
|
||||||
|
|
||||||
import org.springframework.context.annotation.Bean;
|
|
||||||
import org.springframework.context.annotation.Configuration;
|
|
||||||
|
|
||||||
@Configuration
|
|
||||||
public class RocketMQConfig {
|
|
||||||
|
|
||||||
}
|
|
||||||
@ -32,8 +32,8 @@ public class ProductService {
|
|||||||
} else {
|
} else {
|
||||||
redisTemplate.delete(productDTO.getName());
|
redisTemplate.delete(productDTO.getName());
|
||||||
this.productRepository.save(ProductMapper.DTOtoProduct(productDTO));
|
this.productRepository.save(ProductMapper.DTOtoProduct(productDTO));
|
||||||
rocketMQTemplate.getProducer().setSendMsgTimeout(10000);
|
// rocketMQTemplate.getProducer().setSendMsgTimeout(10000);
|
||||||
rocketMQTemplate.convertAndSend("PRODUCT_CREATE_TOPIC", productDTO.getName());
|
// rocketMQTemplate.convertAndSend("PRODUCT_CREATE_TOPIC", productDTO.getName());
|
||||||
return productDTO;
|
return productDTO;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -12,3 +12,5 @@ spring.redis.port=6379
|
|||||||
|
|
||||||
rocketmq.name-server=localhost:9876
|
rocketmq.name-server=localhost:9876
|
||||||
rocketmq.producer.group=my_producer_group
|
rocketmq.producer.group=my_producer_group
|
||||||
|
|
||||||
|
spring.config.import=nacos:nacosConfig.yaml
|
||||||
7
src/main/resources/nacosConfig.yaml
Normal file
7
src/main/resources/nacosConfig.yaml
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
spring:
|
||||||
|
cloud:
|
||||||
|
nacos:
|
||||||
|
serverAddr: 10.10.2.71:8848
|
||||||
|
config:
|
||||||
|
import:
|
||||||
|
- nacos:demo.properties?refreshEnabled=true
|
||||||
Loading…
Reference in New Issue
Block a user