mirror of
https://gitee.com/durcframework/SOP.git
synced 2025-08-12 07:02:14 +08:00
支持easyopen
This commit is contained in:
@@ -7,7 +7,7 @@
|
||||
<version>1.0.0-SNAPSHOT</version>
|
||||
<packaging>jar</packaging>
|
||||
|
||||
<name>easyopen-server-empty</name>
|
||||
<name>easyopen-server</name>
|
||||
<description>easyopen Demo project for Spring Boot</description>
|
||||
|
||||
<parent>
|
||||
@@ -31,10 +31,28 @@
|
||||
<artifactId>sop-service-common</artifactId>
|
||||
<version>1.15.2-SNAPSHOT</version>
|
||||
</dependency>
|
||||
|
||||
<!-- 使用nacos注册中心
|
||||
版本 0.2.x.RELEASE 对应的是 Spring Boot 2.x 版本,版本 0.1.x.RELEASE 对应的是 Spring Boot 1.x 版本。
|
||||
https://mvnrepository.com/artifact/org.springframework.cloud/spring-cloud-starter-alibaba-nacos-discovery
|
||||
-->
|
||||
<dependency>
|
||||
<groupId>org.springframework.cloud</groupId>
|
||||
<artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
|
||||
<artifactId>spring-cloud-starter-alibaba-nacos-discovery</artifactId>
|
||||
<version>0.2.2.RELEASE</version>
|
||||
<exclusions>
|
||||
<exclusion>
|
||||
<groupId>com.alibaba.nacos</groupId>
|
||||
<artifactId>nacos-client</artifactId>
|
||||
</exclusion>
|
||||
</exclusions>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.alibaba.nacos</groupId>
|
||||
<artifactId>nacos-client</artifactId>
|
||||
<version>1.1.0</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>net.oschina.durcframework</groupId>
|
||||
<artifactId>easyopen</artifactId>
|
||||
|
@@ -18,7 +18,7 @@ import java.math.BigDecimal;
|
||||
@ApiDoc("商品接口")
|
||||
public class GoodsApi {
|
||||
|
||||
@Api(name = "goods.get")
|
||||
@Api(name = "easyopen.goods.get")
|
||||
@ApiDocMethod(description = "获取商品")
|
||||
Goods getGoods(GoodsParam param) {
|
||||
Goods goods = new Goods();
|
||||
|
@@ -1,7 +1,7 @@
|
||||
package com.gitee.easyopen.server.config;
|
||||
|
||||
import com.gitee.sop.servercommon.configuration.EasyopenDocSupportController;
|
||||
import com.gitee.sop.servercommon.configuration.EasyopenServiceConfiguration;
|
||||
import com.gitee.sop.servercommon.easyopen.EasyopenServiceConfiguration;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
|
||||
|
@@ -0,0 +1,7 @@
|
||||
server.port=2121
|
||||
spring.application.name=easyopen-service
|
||||
|
||||
# nacos注册中心
|
||||
spring.cloud.nacos.discovery.server-addr=127.0.0.1:8848
|
||||
|
||||
easyopen.prefix-path=/api
|
@@ -1,23 +0,0 @@
|
||||
server:
|
||||
port: 2121
|
||||
|
||||
# 指定注册中心
|
||||
eureka:
|
||||
port: 1111
|
||||
host: localhost
|
||||
client:
|
||||
serviceUrl:
|
||||
defaultZone: http://${eureka.host}:${eureka.port}/eureka/
|
||||
|
||||
spring:
|
||||
application:
|
||||
# 指定服务名
|
||||
name: easyopen-service
|
||||
|
||||
cloud:
|
||||
zookeeper:
|
||||
connect-string: localhost:2181
|
||||
|
||||
# 指定接口路径
|
||||
easyopen:
|
||||
prefix-path: /api
|
@@ -0,0 +1 @@
|
||||
spring.profiles.active=dev
|
@@ -1,3 +0,0 @@
|
||||
spring:
|
||||
profiles:
|
||||
active: dev
|
@@ -43,7 +43,6 @@ public class ZuulConfig extends AlipayZuulConfiguration {
|
||||
//@Configuration
|
||||
//public class ZuulConfig extends EasyopenZuulConfiguration {
|
||||
// static {
|
||||
// new ManagerInitializer();
|
||||
// Map<String, String> appSecretMap = new HashMap<>();
|
||||
// appSecretMap.put("easyopen_test", "G9w0BAQEFAAOCAQ8AMIIBCgKCA");
|
||||
// ApiConfig.getInstance().addAppSecret(appSecretMap);
|
||||
|
@@ -35,7 +35,7 @@ public class EasyopenClientPostTest extends TestBase {
|
||||
|
||||
// 系统参数
|
||||
Map<String, String> params = new HashMap<>();
|
||||
params.put("name", "goods.get");
|
||||
params.put("name", "easyopen.goods.get");
|
||||
params.put("app_key", appKey);
|
||||
params.put("data", json);
|
||||
params.put("timestamp", getTime());
|
||||
|
@@ -14,7 +14,9 @@ import org.springframework.util.CollectionUtils;
|
||||
import org.springframework.util.DigestUtils;
|
||||
import org.springframework.web.client.RestTemplate;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
|
||||
/**
|
||||
@@ -33,15 +35,9 @@ public class DocDiscovery {
|
||||
|
||||
private RestTemplate restTemplate = new RestTemplate();
|
||||
|
||||
private volatile long lastUpdateTime;
|
||||
private Map<String, Long> updateTimeMap = new HashMap<>(16);
|
||||
|
||||
public synchronized void refresh(DocManager docManager) {
|
||||
long now = System.currentTimeMillis();
|
||||
// 5秒内只能执行一次,解决重启应用连续加载4次问题
|
||||
if (now - lastUpdateTime < FIVE_SECONDS) {
|
||||
return;
|
||||
}
|
||||
lastUpdateTime = now;
|
||||
NamingService namingService = nacosDiscoveryProperties.namingServiceInstance();
|
||||
List<ServiceInfo> subscribes = null;
|
||||
try {
|
||||
@@ -60,6 +56,14 @@ public class DocDiscovery {
|
||||
if (Objects.equals(thisServiceId, serviceName) || "api-gateway".equalsIgnoreCase(serviceName)) {
|
||||
continue;
|
||||
}
|
||||
// nacos会不停的触发事件,这里做了一层拦截
|
||||
// 同一个serviceId5秒内允许访问一次
|
||||
Long lastUpdateTime = updateTimeMap.getOrDefault(serviceName, 0L);
|
||||
long now = System.currentTimeMillis();
|
||||
if (now - lastUpdateTime < FIVE_SECONDS) {
|
||||
continue;
|
||||
}
|
||||
updateTimeMap.put(serviceName, now);
|
||||
try {
|
||||
List<Instance> allInstances = namingService.getAllInstances(serviceName);
|
||||
if (CollectionUtils.isEmpty(allInstances)) {
|
||||
|
Reference in New Issue
Block a user