mirror of
https://gitee.com/durcframework/SOP.git
synced 2025-08-11 21:57:56 +08:00
支持easyopen
This commit is contained in:
@@ -7,7 +7,7 @@
|
|||||||
<version>1.0.0-SNAPSHOT</version>
|
<version>1.0.0-SNAPSHOT</version>
|
||||||
<packaging>jar</packaging>
|
<packaging>jar</packaging>
|
||||||
|
|
||||||
<name>easyopen-server-empty</name>
|
<name>easyopen-server</name>
|
||||||
<description>easyopen Demo project for Spring Boot</description>
|
<description>easyopen Demo project for Spring Boot</description>
|
||||||
|
|
||||||
<parent>
|
<parent>
|
||||||
@@ -31,10 +31,28 @@
|
|||||||
<artifactId>sop-service-common</artifactId>
|
<artifactId>sop-service-common</artifactId>
|
||||||
<version>1.15.2-SNAPSHOT</version>
|
<version>1.15.2-SNAPSHOT</version>
|
||||||
</dependency>
|
</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>
|
<dependency>
|
||||||
<groupId>org.springframework.cloud</groupId>
|
<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>
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.alibaba.nacos</groupId>
|
||||||
|
<artifactId>nacos-client</artifactId>
|
||||||
|
<version>1.1.0</version>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>net.oschina.durcframework</groupId>
|
<groupId>net.oschina.durcframework</groupId>
|
||||||
<artifactId>easyopen</artifactId>
|
<artifactId>easyopen</artifactId>
|
||||||
|
@@ -18,7 +18,7 @@ import java.math.BigDecimal;
|
|||||||
@ApiDoc("商品接口")
|
@ApiDoc("商品接口")
|
||||||
public class GoodsApi {
|
public class GoodsApi {
|
||||||
|
|
||||||
@Api(name = "goods.get")
|
@Api(name = "easyopen.goods.get")
|
||||||
@ApiDocMethod(description = "获取商品")
|
@ApiDocMethod(description = "获取商品")
|
||||||
Goods getGoods(GoodsParam param) {
|
Goods getGoods(GoodsParam param) {
|
||||||
Goods goods = new Goods();
|
Goods goods = new Goods();
|
||||||
|
@@ -1,7 +1,7 @@
|
|||||||
package com.gitee.easyopen.server.config;
|
package com.gitee.easyopen.server.config;
|
||||||
|
|
||||||
import com.gitee.sop.servercommon.configuration.EasyopenDocSupportController;
|
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.context.annotation.Configuration;
|
||||||
import org.springframework.stereotype.Controller;
|
import org.springframework.stereotype.Controller;
|
||||||
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
|
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
|
//@Configuration
|
||||||
//public class ZuulConfig extends EasyopenZuulConfiguration {
|
//public class ZuulConfig extends EasyopenZuulConfiguration {
|
||||||
// static {
|
// static {
|
||||||
// new ManagerInitializer();
|
|
||||||
// Map<String, String> appSecretMap = new HashMap<>();
|
// Map<String, String> appSecretMap = new HashMap<>();
|
||||||
// appSecretMap.put("easyopen_test", "G9w0BAQEFAAOCAQ8AMIIBCgKCA");
|
// appSecretMap.put("easyopen_test", "G9w0BAQEFAAOCAQ8AMIIBCgKCA");
|
||||||
// ApiConfig.getInstance().addAppSecret(appSecretMap);
|
// ApiConfig.getInstance().addAppSecret(appSecretMap);
|
||||||
|
@@ -35,7 +35,7 @@ public class EasyopenClientPostTest extends TestBase {
|
|||||||
|
|
||||||
// 系统参数
|
// 系统参数
|
||||||
Map<String, String> params = new HashMap<>();
|
Map<String, String> params = new HashMap<>();
|
||||||
params.put("name", "goods.get");
|
params.put("name", "easyopen.goods.get");
|
||||||
params.put("app_key", appKey);
|
params.put("app_key", appKey);
|
||||||
params.put("data", json);
|
params.put("data", json);
|
||||||
params.put("timestamp", getTime());
|
params.put("timestamp", getTime());
|
||||||
|
@@ -14,7 +14,9 @@ import org.springframework.util.CollectionUtils;
|
|||||||
import org.springframework.util.DigestUtils;
|
import org.springframework.util.DigestUtils;
|
||||||
import org.springframework.web.client.RestTemplate;
|
import org.springframework.web.client.RestTemplate;
|
||||||
|
|
||||||
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -33,15 +35,9 @@ public class DocDiscovery {
|
|||||||
|
|
||||||
private RestTemplate restTemplate = new RestTemplate();
|
private RestTemplate restTemplate = new RestTemplate();
|
||||||
|
|
||||||
private volatile long lastUpdateTime;
|
private Map<String, Long> updateTimeMap = new HashMap<>(16);
|
||||||
|
|
||||||
public synchronized void refresh(DocManager docManager) {
|
public synchronized void refresh(DocManager docManager) {
|
||||||
long now = System.currentTimeMillis();
|
|
||||||
// 5秒内只能执行一次,解决重启应用连续加载4次问题
|
|
||||||
if (now - lastUpdateTime < FIVE_SECONDS) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
lastUpdateTime = now;
|
|
||||||
NamingService namingService = nacosDiscoveryProperties.namingServiceInstance();
|
NamingService namingService = nacosDiscoveryProperties.namingServiceInstance();
|
||||||
List<ServiceInfo> subscribes = null;
|
List<ServiceInfo> subscribes = null;
|
||||||
try {
|
try {
|
||||||
@@ -60,6 +56,14 @@ public class DocDiscovery {
|
|||||||
if (Objects.equals(thisServiceId, serviceName) || "api-gateway".equalsIgnoreCase(serviceName)) {
|
if (Objects.equals(thisServiceId, serviceName) || "api-gateway".equalsIgnoreCase(serviceName)) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
// nacos会不停的触发事件,这里做了一层拦截
|
||||||
|
// 同一个serviceId5秒内允许访问一次
|
||||||
|
Long lastUpdateTime = updateTimeMap.getOrDefault(serviceName, 0L);
|
||||||
|
long now = System.currentTimeMillis();
|
||||||
|
if (now - lastUpdateTime < FIVE_SECONDS) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
updateTimeMap.put(serviceName, now);
|
||||||
try {
|
try {
|
||||||
List<Instance> allInstances = namingService.getAllInstances(serviceName);
|
List<Instance> allInstances = namingService.getAllInstances(serviceName);
|
||||||
if (CollectionUtils.isEmpty(allInstances)) {
|
if (CollectionUtils.isEmpty(allInstances)) {
|
||||||
|
Reference in New Issue
Block a user