支持easyopen

pull/1/head
tanghc 5 years ago
parent 6d240ef243
commit e1bfbbb645
  1. 22
      sop-example/sop-easyopen/pom.xml
  2. 2
      sop-example/sop-easyopen/src/main/java/com/gitee/easyopen/server/api/GoodsApi.java
  3. 2
      sop-example/sop-easyopen/src/main/java/com/gitee/easyopen/server/config/SopConfig.java
  4. 7
      sop-example/sop-easyopen/src/main/resources/application-dev.properties
  5. 23
      sop-example/sop-easyopen/src/main/resources/application-dev.yml
  6. 1
      sop-example/sop-easyopen/src/main/resources/application.properties
  7. 3
      sop-example/sop-easyopen/src/main/resources/application.yml
  8. 1
      sop-gateway/src/main/java/com/gitee/sop/gateway/config/ZuulConfig.java
  9. 2
      sop-test/src/test/java/com/gitee/sop/test/EasyopenClientPostTest.java
  10. 18
      sop-website/website-server/src/main/java/com/gitee/sop/websiteserver/manager/DocDiscovery.java

@ -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>
<groupId>com.alibaba.nacos</groupId>
<artifactId>nacos-client</artifactId>
<version>1.1.0</version>
</dependency> </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

@ -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)) {

Loading…
Cancel
Save