set up nacos

This commit is contained in:
Jincheng Lu 2025-09-17 01:47:12 +08:00
parent 03d361dd08
commit 64d60634e2
6 changed files with 30 additions and 12 deletions

View File

@ -61,6 +61,13 @@
<version>20250517</version>
</dependency>
<dependency>
<groupId>com.alibaba.cloud</groupId>
<artifactId>spring-cloud-starter-alibaba-nacos-config</artifactId>
<version>2025.0.0.0-preview</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>

View File

@ -6,6 +6,8 @@ import com.ljc42.product.Exceptions.ProductExitsException;
import com.ljc42.product.Exceptions.ProductNotFoundException;
import com.ljc42.product.Service.ProductService;
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.ResponseEntity;
import org.springframework.web.bind.annotation.*;
@ -14,14 +16,23 @@ import java.util.Map;
import java.util.Objects;
@RestController
@RefreshScope
public class ProductController {
private final ProductService productService;
@Value(value = "${product.service.welcome-message}")
private String welcomeMessage;
public ProductController(ProductService productService) {
this.productService = productService;
}
@GetMapping("/api/v1/hello")
public ResponseEntity<String> hello() {
return new ResponseEntity<>(welcomeMessage, HttpStatus.OK);
}
@GetMapping("/api/v1/product/{name}")
public ResponseEntity<ResponseDTO> getProducts(@PathVariable String name) {
try {

View File

@ -1,9 +0,0 @@
package com.ljc42.product;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
@Configuration
public class RocketMQConfig {
}

View File

@ -32,8 +32,8 @@ public class ProductService {
} else {
redisTemplate.delete(productDTO.getName());
this.productRepository.save(ProductMapper.DTOtoProduct(productDTO));
rocketMQTemplate.getProducer().setSendMsgTimeout(10000);
rocketMQTemplate.convertAndSend("PRODUCT_CREATE_TOPIC", productDTO.getName());
// rocketMQTemplate.getProducer().setSendMsgTimeout(10000);
// rocketMQTemplate.convertAndSend("PRODUCT_CREATE_TOPIC", productDTO.getName());
return productDTO;
}
}

View File

@ -12,3 +12,5 @@ spring.redis.port=6379
rocketmq.name-server=localhost:9876
rocketmq.producer.group=my_producer_group
spring.config.import=nacos:nacosConfig.yaml

View File

@ -0,0 +1,7 @@
spring:
cloud:
nacos:
serverAddr: 10.10.2.71:8848
config:
import:
- nacos:demo.properties?refreshEnabled=true