5.26 sentinel
This commit is contained in:
parent
bf50a915d7
commit
08e52ae9c8
@ -65,6 +65,11 @@
|
|||||||
<groupId>org.springframework.cloud</groupId>
|
<groupId>org.springframework.cloud</groupId>
|
||||||
<artifactId>spring-cloud-starter-bootstrap</artifactId>
|
<artifactId>spring-cloud-starter-bootstrap</artifactId>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
<!--sentinel-->
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.alibaba.cloud</groupId>
|
||||||
|
<artifactId>spring-cloud-starter-alibaba-sentinel</artifactId>
|
||||||
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
<build>
|
<build>
|
||||||
<finalName>${project.artifactId}</finalName>
|
<finalName>${project.artifactId}</finalName>
|
||||||
|
@ -1,12 +1,14 @@
|
|||||||
package com.hmall.cart;
|
package com.hmall.cart;
|
||||||
|
|
||||||
|
import com.hmall.api.config.DefaultFeignConfig;
|
||||||
import org.mybatis.spring.annotation.MapperScan;
|
import org.mybatis.spring.annotation.MapperScan;
|
||||||
import org.springframework.boot.SpringApplication;
|
import org.springframework.boot.SpringApplication;
|
||||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||||
import org.springframework.cloud.openfeign.EnableFeignClients;
|
import org.springframework.cloud.openfeign.EnableFeignClients;
|
||||||
|
|
||||||
@MapperScan("com.hmall.cart.mapper")
|
@MapperScan("com.hmall.cart.mapper")
|
||||||
@EnableFeignClients(basePackages= "com.hmall.api.client")
|
@EnableFeignClients(basePackages= "com.hmall.api.client",defaultConfiguration = DefaultFeignConfig
|
||||||
|
.class)
|
||||||
@SpringBootApplication
|
@SpringBootApplication
|
||||||
public class CartApplication {
|
public class CartApplication {
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
hm:
|
hm:
|
||||||
db:
|
db:
|
||||||
host: 124.71.159.195 # 修改为你自己的虚拟机IP地址
|
host: localhost # 修改为你自己的虚拟机IP地址
|
||||||
pw: 123456 # 修改为docker中的MySQL密码
|
pw: 123456 # 修改为docker中的MySQL密码
|
@ -1,8 +1,15 @@
|
|||||||
server:
|
server:
|
||||||
port: 8082
|
port: 8082
|
||||||
|
tomcat:
|
||||||
|
threads:
|
||||||
|
max: 50
|
||||||
|
accept-count: 50
|
||||||
|
max-connections: 100
|
||||||
feign:
|
feign:
|
||||||
httpclient:
|
httpclient:
|
||||||
enabled: true # 使用 Apache HttpClient(默认关闭)
|
enabled: true # 使用 Apache HttpClient(默认关闭)
|
||||||
|
sentinel:
|
||||||
|
enabled: true # 开启feign对sentinel的支持
|
||||||
|
|
||||||
hm:
|
hm:
|
||||||
swagger:
|
swagger:
|
||||||
|
@ -5,10 +5,11 @@ spring:
|
|||||||
active: local
|
active: local
|
||||||
cloud:
|
cloud:
|
||||||
nacos:
|
nacos:
|
||||||
server-addr: 124.71.159.195:8848 # nacos地址
|
server-addr: localhost:8848 # nacos地址
|
||||||
config:
|
config:
|
||||||
file-extension: yaml # 文件后缀名
|
file-extension: yaml # 文件后缀名
|
||||||
shared-configs: # 共享配置
|
shared-configs: # 共享配置
|
||||||
- dataId: shared_jdbc.yaml # 共享mybatis配置
|
- dataId: shared_jdbc.yaml # 共享mybatis配置
|
||||||
- dataId: shared_log.yaml # 共享日志配置
|
- dataId: shared_log.yaml # 共享日志配置
|
||||||
- dataId: shared_swagger.yaml # 共享日志配置
|
- dataId: shared_swagger.yaml # 共享日志配置
|
||||||
|
- dataId: shared_sentinel.yaml #共享sentinel控制台
|
@ -1,5 +1,6 @@
|
|||||||
package com.hmall.api.client;
|
package com.hmall.api.client;
|
||||||
|
|
||||||
|
import com.hmall.api.client.fallback.ItemClientFallbackFactory;
|
||||||
import com.hmall.api.dto.ItemDTO;
|
import com.hmall.api.dto.ItemDTO;
|
||||||
import com.hmall.api.dto.OrderDetailDTO;
|
import com.hmall.api.dto.OrderDetailDTO;
|
||||||
import org.springframework.cloud.openfeign.FeignClient;
|
import org.springframework.cloud.openfeign.FeignClient;
|
||||||
@ -11,7 +12,7 @@ import org.springframework.web.bind.annotation.RequestParam;
|
|||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
@FeignClient("item-service")
|
@FeignClient(value = "item-service",fallbackFactory = ItemClientFallbackFactory.class)
|
||||||
public interface ItemClient {
|
public interface ItemClient {
|
||||||
|
|
||||||
@GetMapping("/items")
|
@GetMapping("/items")
|
||||||
|
@ -0,0 +1,33 @@
|
|||||||
|
package com.hmall.api.client.fallback;
|
||||||
|
|
||||||
|
import com.hmall.api.client.ItemClient;
|
||||||
|
import com.hmall.api.dto.ItemDTO;
|
||||||
|
import com.hmall.api.dto.OrderDetailDTO;
|
||||||
|
import com.hmall.common.exception.BizIllegalException;
|
||||||
|
import com.hmall.common.utils.CollUtils;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.springframework.cloud.openfeign.FallbackFactory;
|
||||||
|
|
||||||
|
import java.util.Collection;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
@Slf4j
|
||||||
|
public class ItemClientFallbackFactory implements FallbackFactory<ItemClient> {
|
||||||
|
@Override
|
||||||
|
public ItemClient create(Throwable cause) {
|
||||||
|
return new ItemClient() {
|
||||||
|
@Override
|
||||||
|
public List<ItemDTO> queryItemByIds(Collection<Long> ids) {
|
||||||
|
log.error("远程调用ItemClient#queryItemByIds方法出现异常,参数:{}", ids, cause);
|
||||||
|
// 查询购物车允许失败,查询失败,返回空集合
|
||||||
|
return CollUtils.emptyList();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void deductStock(List<OrderDetailDTO> items) {
|
||||||
|
// 库存扣减业务需要触发事务回滚,查询失败,抛出异常
|
||||||
|
throw new BizIllegalException(cause);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
@ -1,5 +1,6 @@
|
|||||||
package com.hmall.api.config;
|
package com.hmall.api.config;
|
||||||
|
|
||||||
|
import com.hmall.api.client.fallback.ItemClientFallbackFactory;
|
||||||
import com.hmall.common.utils.UserContext;
|
import com.hmall.common.utils.UserContext;
|
||||||
import feign.RequestInterceptor;
|
import feign.RequestInterceptor;
|
||||||
import feign.RequestTemplate;
|
import feign.RequestTemplate;
|
||||||
@ -22,4 +23,9 @@ public class DefaultFeignConfig {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Bean
|
||||||
|
public ItemClientFallbackFactory itemClientFallbackFactory(){
|
||||||
|
return new ItemClientFallbackFactory();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -42,7 +42,16 @@
|
|||||||
<artifactId>spring-boot-configuration-processor</artifactId>
|
<artifactId>spring-boot-configuration-processor</artifactId>
|
||||||
<optional>true</optional>
|
<optional>true</optional>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
<!--nacos配置管理-->
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.alibaba.cloud</groupId>
|
||||||
|
<artifactId>spring-cloud-starter-alibaba-nacos-config</artifactId>
|
||||||
|
</dependency>
|
||||||
|
<!--读取bootstrap文件-->
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.springframework.cloud</groupId>
|
||||||
|
<artifactId>spring-cloud-starter-bootstrap</artifactId>
|
||||||
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
<build>
|
<build>
|
||||||
<finalName>${project.artifactId}</finalName>
|
<finalName>${project.artifactId}</finalName>
|
||||||
|
@ -0,0 +1,77 @@
|
|||||||
|
package com.hmall.gateway.routers;
|
||||||
|
|
||||||
|
import cn.hutool.json.JSONUtil;
|
||||||
|
import com.alibaba.cloud.nacos.NacosConfigManager;
|
||||||
|
import com.alibaba.nacos.api.config.listener.Listener;
|
||||||
|
import com.alibaba.nacos.api.exception.NacosException;
|
||||||
|
import com.hmall.common.utils.CollUtils;
|
||||||
|
import lombok.RequiredArgsConstructor;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.springframework.cloud.gateway.route.RouteDefinition;
|
||||||
|
import org.springframework.cloud.gateway.route.RouteDefinitionWriter;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
import reactor.core.publisher.Mono;
|
||||||
|
|
||||||
|
import javax.annotation.PostConstruct;
|
||||||
|
import java.util.HashSet;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Set;
|
||||||
|
import java.util.concurrent.Executor;
|
||||||
|
|
||||||
|
@Slf4j
|
||||||
|
@Component
|
||||||
|
@RequiredArgsConstructor
|
||||||
|
public class DynamicRouteLoader {
|
||||||
|
|
||||||
|
private final RouteDefinitionWriter writer;
|
||||||
|
private final NacosConfigManager nacosConfigManager;
|
||||||
|
|
||||||
|
// 路由配置文件的id和分组
|
||||||
|
private final String dataId = "gateway-routes.json";
|
||||||
|
private final String group = "DEFAULT_GROUP";
|
||||||
|
// 保存更新过的路由id
|
||||||
|
private final Set<String> routeIds = new HashSet<>();
|
||||||
|
|
||||||
|
@PostConstruct
|
||||||
|
public void initRouteConfigListener() throws NacosException {
|
||||||
|
// 1.注册监听器并首次拉取配置
|
||||||
|
String configInfo = nacosConfigManager.getConfigService()
|
||||||
|
.getConfigAndSignListener(dataId, group, 5000, new Listener() {
|
||||||
|
@Override
|
||||||
|
public Executor getExecutor() {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void receiveConfigInfo(String configInfo) {
|
||||||
|
updateConfigInfo(configInfo);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
// 2.首次启动时,更新一次配置
|
||||||
|
updateConfigInfo(configInfo);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void updateConfigInfo(String configInfo) {
|
||||||
|
log.debug("监听到路由配置变更,{}", configInfo);
|
||||||
|
// 1.反序列化
|
||||||
|
List<RouteDefinition> routeDefinitions = JSONUtil.toList(configInfo, RouteDefinition.class);
|
||||||
|
// 2.更新前先清空旧路由
|
||||||
|
// 2.1.清除旧路由
|
||||||
|
for (String routeId : routeIds) {
|
||||||
|
writer.delete(Mono.just(routeId)).subscribe();
|
||||||
|
}
|
||||||
|
routeIds.clear();
|
||||||
|
// 2.2.判断是否有新的路由要更新
|
||||||
|
if (CollUtils.isEmpty(routeDefinitions)) {
|
||||||
|
// 无新路由配置,直接结束
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
// 3.更新路由
|
||||||
|
routeDefinitions.forEach(routeDefinition -> {
|
||||||
|
// 3.1.更新路由
|
||||||
|
writer.save(Mono.just(routeDefinition)).subscribe();
|
||||||
|
// 3.2.记录路由id,方便将来删除
|
||||||
|
routeIds.add(routeDefinition.getId());
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
@ -1,33 +1,5 @@
|
|||||||
server:
|
server:
|
||||||
port: 8080
|
port: 8080
|
||||||
spring:
|
|
||||||
application:
|
|
||||||
name: gateway
|
|
||||||
cloud:
|
|
||||||
nacos:
|
|
||||||
server-addr: 124.71.159.195:8848
|
|
||||||
gateway:
|
|
||||||
routes:
|
|
||||||
- id: item # 路由规则id,自定义,唯一
|
|
||||||
uri: lb://item-service # 路由的目标服务,lb代表负载均衡,会从注册中心拉取服务列表
|
|
||||||
predicates: # 路由断言,判断当前请求是否符合当前规则,符合则路由到目标服务
|
|
||||||
- Path=/items/**,/search/** # 这里是以请求路径作为判断规则
|
|
||||||
- id: cart
|
|
||||||
uri: lb://cart-service
|
|
||||||
predicates:
|
|
||||||
- Path=/carts/**
|
|
||||||
- id: user
|
|
||||||
uri: lb://user-service
|
|
||||||
predicates:
|
|
||||||
- Path=/users/**,/addresses/**
|
|
||||||
- id: trade
|
|
||||||
uri: lb://trade-service
|
|
||||||
predicates:
|
|
||||||
- Path=/orders/**
|
|
||||||
- id: pay
|
|
||||||
uri: lb://pay-service
|
|
||||||
predicates:
|
|
||||||
- Path=/pay-orders/**
|
|
||||||
hm:
|
hm:
|
||||||
jwt:
|
jwt:
|
||||||
location: classpath:hmall.jks
|
location: classpath:hmall.jks
|
||||||
|
12
hm-gateway/src/main/resources/bootstrap.yaml
Normal file
12
hm-gateway/src/main/resources/bootstrap.yaml
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
spring:
|
||||||
|
application:
|
||||||
|
name: gateway # 服务名称
|
||||||
|
profiles:
|
||||||
|
active: local
|
||||||
|
cloud:
|
||||||
|
nacos:
|
||||||
|
server-addr: localhost:8848 # nacos地址
|
||||||
|
config:
|
||||||
|
file-extension: yaml # 文件后缀名
|
||||||
|
shared-configs: # 共享配置
|
||||||
|
- dataId: shared_log.yaml # 共享日志配置
|
@ -54,6 +54,20 @@
|
|||||||
<groupId>com.alibaba.cloud</groupId>
|
<groupId>com.alibaba.cloud</groupId>
|
||||||
<artifactId>spring-cloud-starter-alibaba-nacos-discovery</artifactId>
|
<artifactId>spring-cloud-starter-alibaba-nacos-discovery</artifactId>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
<!--nacos配置管理-->
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.alibaba.cloud</groupId>
|
||||||
|
<artifactId>spring-cloud-starter-alibaba-nacos-config</artifactId>
|
||||||
|
</dependency>
|
||||||
|
<!--读取bootstrap文件-->
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.springframework.cloud</groupId>
|
||||||
|
<artifactId>spring-cloud-starter-bootstrap</artifactId>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.alibaba.cloud</groupId>
|
||||||
|
<artifactId>spring-cloud-starter-alibaba-sentinel</artifactId>
|
||||||
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
<build>
|
<build>
|
||||||
<finalName>${project.artifactId}</finalName>
|
<finalName>${project.artifactId}</finalName>
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
package com.hmall.item.controller;
|
package com.hmall.item.controller;
|
||||||
|
import cn.hutool.core.thread.ThreadUtil;
|
||||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||||
import com.hmall.api.dto.ItemDTO;
|
import com.hmall.api.dto.ItemDTO;
|
||||||
import com.hmall.api.dto.OrderDetailDTO;
|
import com.hmall.api.dto.OrderDetailDTO;
|
||||||
@ -34,6 +35,8 @@ public class ItemController {
|
|||||||
@ApiOperation("根据id批量查询商品")
|
@ApiOperation("根据id批量查询商品")
|
||||||
@GetMapping
|
@GetMapping
|
||||||
public List<ItemDTO> queryItemByIds(@RequestParam("ids") List<Long> ids){
|
public List<ItemDTO> queryItemByIds(@RequestParam("ids") List<Long> ids){
|
||||||
|
//模拟线程延迟
|
||||||
|
ThreadUtil.sleep(500);
|
||||||
return itemService.queryItemByIds(ids);
|
return itemService.queryItemByIds(ids);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
hm:
|
hm:
|
||||||
db:
|
db:
|
||||||
host: 124.71.159.195 # 修改为你自己的虚拟机IP地址
|
host: localhost # 修改为你自己的虚拟机IP地址
|
||||||
pw: 123456 # 修改为docker中的MySQL密码
|
pw: 123456 # 修改为docker中的MySQL密码
|
@ -1,57 +1,12 @@
|
|||||||
server:
|
server:
|
||||||
port: 8081
|
port: 8081
|
||||||
spring:
|
feign:
|
||||||
application:
|
httpclient:
|
||||||
name: item-service
|
enabled: true # 使用 Apache HttpClient(默认关闭)
|
||||||
cloud:
|
|
||||||
nacos:
|
|
||||||
server-addr: 124.71.159.195:8848 # nacos地址
|
|
||||||
|
|
||||||
profiles:
|
hm:
|
||||||
active: local
|
swagger:
|
||||||
datasource:
|
title: 商品管理接口文档
|
||||||
url: jdbc:mysql://${hm.db.host}:3307/hm-item?useUnicode=true&characterEncoding=UTF-8&serverTimezone=Asia/Shanghai
|
package: com.hmall.item.controller
|
||||||
driver-class-name: com.mysql.cj.jdbc.Driver
|
db:
|
||||||
username: root
|
database: hm-item
|
||||||
password: ${hm.db.pw}
|
|
||||||
hikari:
|
|
||||||
# 比你数据库空闲断连时间再小一点,这里示例用 20 分钟
|
|
||||||
max-lifetime: 1200000 # 20 分钟,单位 ms
|
|
||||||
idle-timeout: 600000 # 10 分钟,长时间不用就回收
|
|
||||||
connection-timeout: 30000 # 30 秒 等待可用连接
|
|
||||||
minimum-idle: 5 # 保持最少 5 个空闲
|
|
||||||
maximum-pool-size: 10 # 池中最大连接数,根据并发量调整
|
|
||||||
validation-timeout: 5000 # 验证一个连接可用时的超时时间
|
|
||||||
# (可选)强制每次从池里拿连接前跑一下简单检查:
|
|
||||||
connection-test-query: SELECT 1
|
|
||||||
mybatis-plus:
|
|
||||||
configuration:
|
|
||||||
default-enum-type-handler: com.baomidou.mybatisplus.core.handlers.MybatisEnumTypeHandler
|
|
||||||
global-config:
|
|
||||||
db-config:
|
|
||||||
update-strategy: not_null
|
|
||||||
id-type: auto
|
|
||||||
logging:
|
|
||||||
level:
|
|
||||||
com.hmall: debug
|
|
||||||
pattern:
|
|
||||||
dateformat: HH:mm:ss:SSS
|
|
||||||
file:
|
|
||||||
path: "logs/${spring.application.name}"
|
|
||||||
knife4j:
|
|
||||||
enable: true
|
|
||||||
openapi:
|
|
||||||
title: 黑马商城商品管理接口文档
|
|
||||||
description: "黑马商城商品管理接口文档"
|
|
||||||
email: zhangsan@itcast.cn
|
|
||||||
concat: 宇哥
|
|
||||||
url: https://www.itcast.cn
|
|
||||||
version: v1.0.0
|
|
||||||
group:
|
|
||||||
default:
|
|
||||||
group-name: default
|
|
||||||
api-rule: package
|
|
||||||
api-rule-resources:
|
|
||||||
- com.hmall.item.controller
|
|
||||||
|
|
||||||
# keytool -genkeypair -alias hmall -keyalg RSA -keypass hmall123 -keystore hmall.jks -storepass hmall123
|
|
15
item-service/src/main/resources/bootstrap.yaml
Normal file
15
item-service/src/main/resources/bootstrap.yaml
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
spring:
|
||||||
|
application:
|
||||||
|
name: item-service # 服务名称
|
||||||
|
profiles:
|
||||||
|
active: local
|
||||||
|
cloud:
|
||||||
|
nacos:
|
||||||
|
server-addr: localhost:8848 # nacos地址
|
||||||
|
config:
|
||||||
|
file-extension: yaml # 文件后缀名
|
||||||
|
shared-configs: # 共享配置
|
||||||
|
- dataId: shared_jdbc.yaml # 共享mybatis配置
|
||||||
|
- dataId: shared_log.yaml # 共享日志配置
|
||||||
|
- dataId: shared_swagger.yaml # 共享日志配置
|
||||||
|
- dataId: shared_sentinel.yaml #共享sentinel控制台
|
@ -54,6 +54,20 @@
|
|||||||
<groupId>com.alibaba.cloud</groupId>
|
<groupId>com.alibaba.cloud</groupId>
|
||||||
<artifactId>spring-cloud-starter-alibaba-nacos-discovery</artifactId>
|
<artifactId>spring-cloud-starter-alibaba-nacos-discovery</artifactId>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
<!--nacos配置管理-->
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.alibaba.cloud</groupId>
|
||||||
|
<artifactId>spring-cloud-starter-alibaba-nacos-config</artifactId>
|
||||||
|
</dependency>
|
||||||
|
<!--读取bootstrap文件-->
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.springframework.cloud</groupId>
|
||||||
|
<artifactId>spring-cloud-starter-bootstrap</artifactId>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.alibaba.cloud</groupId>
|
||||||
|
<artifactId>spring-cloud-starter-alibaba-sentinel</artifactId>
|
||||||
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
<build>
|
<build>
|
||||||
<finalName>${project.artifactId}</finalName>
|
<finalName>${project.artifactId}</finalName>
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
hm:
|
hm:
|
||||||
db:
|
db:
|
||||||
host: 124.71.159.195 # 修改为你自己的虚拟机IP地址
|
host: localhost # 修改为你自己的虚拟机IP地址
|
||||||
pw: 123456 # 修改为docker中的MySQL密码
|
pw: 123456 # 修改为docker中的MySQL密码
|
@ -1,61 +1,14 @@
|
|||||||
server:
|
server:
|
||||||
port: 8086
|
port: 8086
|
||||||
spring:
|
|
||||||
application:
|
|
||||||
name: pay-service
|
|
||||||
cloud:
|
|
||||||
nacos:
|
|
||||||
server-addr: 124.71.159.195:8848 # nacos地址
|
|
||||||
profiles:
|
|
||||||
active: local
|
|
||||||
datasource:
|
|
||||||
url: jdbc:mysql://${hm.db.host}:3307/hm-pay?useUnicode=true&characterEncoding=UTF-8&serverTimezone=Asia/Shanghai
|
|
||||||
driver-class-name: com.mysql.cj.jdbc.Driver
|
|
||||||
username: root
|
|
||||||
password: ${hm.db.pw}
|
|
||||||
hikari:
|
|
||||||
# 比你数据库空闲断连时间再小一点,这里示例用 20 分钟
|
|
||||||
max-lifetime: 1200000 # 20 分钟,单位 ms
|
|
||||||
idle-timeout: 600000 # 10 分钟,长时间不用就回收
|
|
||||||
connection-timeout: 30000 # 30 秒 等待可用连接
|
|
||||||
minimum-idle: 5 # 保持最少 5 个空闲
|
|
||||||
maximum-pool-size: 10 # 池中最大连接数,根据并发量调整
|
|
||||||
validation-timeout: 5000 # 验证一个连接可用时的超时时间
|
|
||||||
# (可选)强制每次从池里拿连接前跑一下简单检查:
|
|
||||||
connection-test-query: SELECT 1
|
|
||||||
mybatis-plus:
|
|
||||||
configuration:
|
|
||||||
default-enum-type-handler: com.baomidou.mybatisplus.core.handlers.MybatisEnumTypeHandler
|
|
||||||
global-config:
|
|
||||||
db-config:
|
|
||||||
update-strategy: not_null
|
|
||||||
id-type: auto
|
|
||||||
logging:
|
|
||||||
level:
|
|
||||||
com.hmall: debug
|
|
||||||
pattern:
|
|
||||||
dateformat: HH:mm:ss:SSS
|
|
||||||
file:
|
|
||||||
path: "logs/${spring.application.name}"
|
|
||||||
knife4j:
|
|
||||||
enable: true
|
|
||||||
openapi:
|
|
||||||
title: 黑马商城支付服务接口文档
|
|
||||||
description: "黑马商城支付服务接口文档"
|
|
||||||
email: zhangsan@itcast.cn
|
|
||||||
concat: 宇哥
|
|
||||||
url: https://www.itcast.cn
|
|
||||||
version: v1.0.0
|
|
||||||
group:
|
|
||||||
default:
|
|
||||||
group-name: default
|
|
||||||
api-rule: package
|
|
||||||
api-rule-resources:
|
|
||||||
- com.hmall.pay.controller
|
|
||||||
|
|
||||||
feign:
|
feign:
|
||||||
httpclient:
|
httpclient:
|
||||||
enabled: true # 使用 Apache HttpClient(默认关闭)
|
enabled: true # 使用 Apache HttpClient(默认关闭)
|
||||||
|
hm:
|
||||||
|
swagger:
|
||||||
|
title: 支付管理接口文档
|
||||||
|
package: com.hmall.pay.controller
|
||||||
|
db:
|
||||||
|
database: hm-pay
|
||||||
|
|
||||||
# keytool -genkeypair -alias hmall -keyalg RSA -keypass hmall123 -keystore hmall.jks -storepass hmall123
|
# keytool -genkeypair -alias hmall -keyalg RSA -keypass hmall123 -keystore hmall.jks -storepass hmall123
|
15
pay-service/src/main/resources/bootstrap.yaml
Normal file
15
pay-service/src/main/resources/bootstrap.yaml
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
spring:
|
||||||
|
application:
|
||||||
|
name: pay-service # 服务名称
|
||||||
|
profiles:
|
||||||
|
active: local
|
||||||
|
cloud:
|
||||||
|
nacos:
|
||||||
|
server-addr: localhost:8848 # nacos地址
|
||||||
|
config:
|
||||||
|
file-extension: yaml # 文件后缀名
|
||||||
|
shared-configs: # 共享配置
|
||||||
|
- dataId: shared_jdbc.yaml # 共享mybatis配置
|
||||||
|
- dataId: shared_log.yaml # 共享日志配置
|
||||||
|
- dataId: shared_swagger.yaml # 共享日志配置
|
||||||
|
- dataId: shared_sentinel.yaml #共享sentinel控制台
|
@ -54,6 +54,20 @@
|
|||||||
<groupId>com.alibaba.cloud</groupId>
|
<groupId>com.alibaba.cloud</groupId>
|
||||||
<artifactId>spring-cloud-starter-alibaba-nacos-discovery</artifactId>
|
<artifactId>spring-cloud-starter-alibaba-nacos-discovery</artifactId>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
<!--nacos配置管理-->
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.alibaba.cloud</groupId>
|
||||||
|
<artifactId>spring-cloud-starter-alibaba-nacos-config</artifactId>
|
||||||
|
</dependency>
|
||||||
|
<!--读取bootstrap文件-->
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.springframework.cloud</groupId>
|
||||||
|
<artifactId>spring-cloud-starter-bootstrap</artifactId>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.alibaba.cloud</groupId>
|
||||||
|
<artifactId>spring-cloud-starter-alibaba-sentinel</artifactId>
|
||||||
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
<build>
|
<build>
|
||||||
<finalName>${project.artifactId}</finalName>
|
<finalName>${project.artifactId}</finalName>
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
hm:
|
hm:
|
||||||
db:
|
db:
|
||||||
host: 124.71.159.195 # 修改为你自己的虚拟机IP地址
|
host: localhost # 修改为你自己的虚拟机IP地址
|
||||||
pw: 123456 # 修改为docker中的MySQL密码
|
pw: 123456 # 修改为docker中的MySQL密码
|
@ -1,61 +1,15 @@
|
|||||||
server:
|
server:
|
||||||
port: 8085
|
port: 8085
|
||||||
spring:
|
|
||||||
application:
|
|
||||||
name: trade-service
|
|
||||||
cloud:
|
|
||||||
nacos:
|
|
||||||
server-addr: 124.71.159.195:8848 # nacos地址
|
|
||||||
profiles:
|
|
||||||
active: local
|
|
||||||
datasource:
|
|
||||||
url: jdbc:mysql://${hm.db.host}:3307/hm-trade?useUnicode=true&characterEncoding=UTF-8&serverTimezone=Asia/Shanghai
|
|
||||||
driver-class-name: com.mysql.cj.jdbc.Driver
|
|
||||||
username: root
|
|
||||||
password: ${hm.db.pw}
|
|
||||||
hikari:
|
|
||||||
# 比你数据库空闲断连时间再小一点,这里示例用 20 分钟
|
|
||||||
max-lifetime: 1200000 # 20 分钟,单位 ms
|
|
||||||
idle-timeout: 600000 # 10 分钟,长时间不用就回收
|
|
||||||
connection-timeout: 30000 # 30 秒 等待可用连接
|
|
||||||
minimum-idle: 5 # 保持最少 5 个空闲
|
|
||||||
maximum-pool-size: 10 # 池中最大连接数,根据并发量调整
|
|
||||||
validation-timeout: 5000 # 验证一个连接可用时的超时时间
|
|
||||||
# (可选)强制每次从池里拿连接前跑一下简单检查:
|
|
||||||
connection-test-query: SELECT 1
|
|
||||||
mybatis-plus:
|
|
||||||
configuration:
|
|
||||||
default-enum-type-handler: com.baomidou.mybatisplus.core.handlers.MybatisEnumTypeHandler
|
|
||||||
global-config:
|
|
||||||
db-config:
|
|
||||||
update-strategy: not_null
|
|
||||||
id-type: auto
|
|
||||||
logging:
|
|
||||||
level:
|
|
||||||
com.hmall: debug
|
|
||||||
pattern:
|
|
||||||
dateformat: HH:mm:ss:SSS
|
|
||||||
file:
|
|
||||||
path: "logs/${spring.application.name}"
|
|
||||||
knife4j:
|
|
||||||
enable: true
|
|
||||||
openapi:
|
|
||||||
title: 黑马商城交易服务接口文档
|
|
||||||
description: "黑马商城交易服务接口文档"
|
|
||||||
email: zhangsan@itcast.cn
|
|
||||||
concat: 宇哥
|
|
||||||
url: https://www.itcast.cn
|
|
||||||
version: v1.0.0
|
|
||||||
group:
|
|
||||||
default:
|
|
||||||
group-name: default
|
|
||||||
api-rule: package
|
|
||||||
api-rule-resources:
|
|
||||||
- com.hmall.trade.controller
|
|
||||||
|
|
||||||
feign:
|
feign:
|
||||||
httpclient:
|
httpclient:
|
||||||
enabled: true # 使用 Apache HttpClient(默认关闭)
|
enabled: true # 使用 Apache HttpClient(默认关闭)
|
||||||
|
|
||||||
|
hm:
|
||||||
|
swagger:
|
||||||
|
title: 交易管理接口文档
|
||||||
|
package: com.hmall.trade.controller
|
||||||
|
db:
|
||||||
|
database: hm-trade
|
||||||
|
|
||||||
# keytool -genkeypair -alias hmall -keyalg RSA -keypass hmall123 -keystore hmall.jks -storepass hmall123
|
# keytool -genkeypair -alias hmall -keyalg RSA -keypass hmall123 -keystore hmall.jks -storepass hmall123
|
15
trade-service/src/main/resources/bootstrap.yaml
Normal file
15
trade-service/src/main/resources/bootstrap.yaml
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
spring:
|
||||||
|
application:
|
||||||
|
name: trade-service # 服务名称
|
||||||
|
profiles:
|
||||||
|
active: local
|
||||||
|
cloud:
|
||||||
|
nacos:
|
||||||
|
server-addr: localhost:8848 # nacos地址
|
||||||
|
config:
|
||||||
|
file-extension: yaml # 文件后缀名
|
||||||
|
shared-configs: # 共享配置
|
||||||
|
- dataId: shared_jdbc.yaml # 共享mybatis配置
|
||||||
|
- dataId: shared_log.yaml # 共享日志配置
|
||||||
|
- dataId: shared_swagger.yaml # 共享日志配置
|
||||||
|
- dataId: shared_sentinel.yaml #共享sentinel控制台
|
@ -54,6 +54,20 @@
|
|||||||
<groupId>com.alibaba.cloud</groupId>
|
<groupId>com.alibaba.cloud</groupId>
|
||||||
<artifactId>spring-cloud-starter-alibaba-nacos-discovery</artifactId>
|
<artifactId>spring-cloud-starter-alibaba-nacos-discovery</artifactId>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
<!--nacos配置管理-->
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.alibaba.cloud</groupId>
|
||||||
|
<artifactId>spring-cloud-starter-alibaba-nacos-config</artifactId>
|
||||||
|
</dependency>
|
||||||
|
<!--读取bootstrap文件-->
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.springframework.cloud</groupId>
|
||||||
|
<artifactId>spring-cloud-starter-bootstrap</artifactId>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.alibaba.cloud</groupId>
|
||||||
|
<artifactId>spring-cloud-starter-alibaba-sentinel</artifactId>
|
||||||
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
<build>
|
<build>
|
||||||
<finalName>${project.artifactId}</finalName>
|
<finalName>${project.artifactId}</finalName>
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
hm:
|
hm:
|
||||||
db:
|
db:
|
||||||
host: 124.71.159.195 # 修改为你自己的虚拟机IP地址
|
host: localhost # 修改为你自己的虚拟机IP地址
|
||||||
pw: 123456 # 修改为docker中的MySQL密码
|
pw: 123456 # 修改为docker中的MySQL密码
|
@ -1,63 +1,16 @@
|
|||||||
server:
|
server:
|
||||||
port: 8084
|
port: 8084
|
||||||
spring:
|
|
||||||
application:
|
|
||||||
name: user-service
|
|
||||||
cloud:
|
|
||||||
nacos:
|
|
||||||
server-addr: 124.71.159.195:8848 # nacos地址
|
|
||||||
profiles:
|
|
||||||
active: local
|
|
||||||
datasource:
|
|
||||||
url: jdbc:mysql://${hm.db.host}:3307/hm-user?useUnicode=true&characterEncoding=UTF-8&serverTimezone=Asia/Shanghai
|
|
||||||
driver-class-name: com.mysql.cj.jdbc.Driver
|
|
||||||
username: root
|
|
||||||
password: ${hm.db.pw}
|
|
||||||
hikari:
|
|
||||||
# 比你数据库空闲断连时间再小一点,这里示例用 20 分钟
|
|
||||||
max-lifetime: 1200000 # 20 分钟,单位 ms
|
|
||||||
idle-timeout: 600000 # 10 分钟,长时间不用就回收
|
|
||||||
connection-timeout: 30000 # 30 秒 等待可用连接
|
|
||||||
minimum-idle: 5 # 保持最少 5 个空闲
|
|
||||||
maximum-pool-size: 10 # 池中最大连接数,根据并发量调整
|
|
||||||
validation-timeout: 5000 # 验证一个连接可用时的超时时间
|
|
||||||
# (可选)强制每次从池里拿连接前跑一下简单检查:
|
|
||||||
connection-test-query: SELECT 1
|
|
||||||
mybatis-plus:
|
|
||||||
configuration:
|
|
||||||
default-enum-type-handler: com.baomidou.mybatisplus.core.handlers.MybatisEnumTypeHandler
|
|
||||||
global-config:
|
|
||||||
db-config:
|
|
||||||
update-strategy: not_null
|
|
||||||
id-type: auto
|
|
||||||
logging:
|
|
||||||
level:
|
|
||||||
com.hmall: debug
|
|
||||||
pattern:
|
|
||||||
dateformat: HH:mm:ss:SSS
|
|
||||||
file:
|
|
||||||
path: "logs/${spring.application.name}"
|
|
||||||
knife4j:
|
|
||||||
enable: true
|
|
||||||
openapi:
|
|
||||||
title: 黑马商城用户服务接口文档
|
|
||||||
description: "黑马商城用户服务接口文档"
|
|
||||||
email: zhangsan@itcast.cn
|
|
||||||
concat: 宇哥
|
|
||||||
url: https://www.itcast.cn
|
|
||||||
version: v1.0.0
|
|
||||||
group:
|
|
||||||
default:
|
|
||||||
group-name: default
|
|
||||||
api-rule: package
|
|
||||||
api-rule-resources:
|
|
||||||
- com.hmall.user.controller
|
|
||||||
|
|
||||||
feign:
|
feign:
|
||||||
httpclient:
|
httpclient:
|
||||||
enabled: true # 使用 Apache HttpClient(默认关闭)
|
enabled: true # 使用 Apache HttpClient(默认关闭)
|
||||||
|
|
||||||
hm:
|
hm:
|
||||||
|
swagger:
|
||||||
|
title: 用户管理接口文档
|
||||||
|
package: com.hmall.user.controller
|
||||||
|
db:
|
||||||
|
database: hm-user
|
||||||
jwt:
|
jwt:
|
||||||
location: classpath:hmall.jks
|
location: classpath:hmall.jks
|
||||||
alias: hmall
|
alias: hmall
|
||||||
|
15
user-service/src/main/resources/bootstrap.yaml
Normal file
15
user-service/src/main/resources/bootstrap.yaml
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
spring:
|
||||||
|
application:
|
||||||
|
name: user-service # 服务名称
|
||||||
|
profiles:
|
||||||
|
active: local
|
||||||
|
cloud:
|
||||||
|
nacos:
|
||||||
|
server-addr: localhost:8848 # nacos地址
|
||||||
|
config:
|
||||||
|
file-extension: yaml # 文件后缀名
|
||||||
|
shared-configs: # 共享配置
|
||||||
|
- dataId: shared_jdbc.yaml # 共享mybatis配置
|
||||||
|
- dataId: shared_log.yaml # 共享日志配置
|
||||||
|
- dataId: shared_swagger.yaml # 共享日志配置
|
||||||
|
- dataId: shared_sentinel.yaml #共享sentinel控制台
|
Loading…
x
Reference in New Issue
Block a user