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>
|
||||
</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>
|
||||
|
||||
@ -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 {
|
||||
|
||||
@ -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 {
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
@ -11,4 +11,6 @@ spring.redis.host=localhost
|
||||
spring.redis.port=6379
|
||||
|
||||
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