diff --git a/pom.xml b/pom.xml index a2362e8..e2d34af 100644 --- a/pom.xml +++ b/pom.xml @@ -22,7 +22,7 @@ UTF-8 UTF-8 Greenwich.SR1 - 2.7.1 + 2.7.2 @@ -47,7 +47,7 @@ org.apache.dubbo dubbo-spring-boot-starter - ${dubbo.version} + 2.7.1 @@ -59,7 +59,7 @@ org.apache.dubbo dubbo-dependencies-zookeeper - ${dubbo.version} + 2.7.1 pom @@ -98,4 +98,4 @@ usergw-service - \ No newline at end of file + diff --git a/usergw-service/src/main/java/cn/ecpark/service/usergw/biz/filters/DubboFilter.java b/usergw-service/src/main/java/cn/ecpark/service/usergw/biz/filters/DubboFilter.java index 48b2736..3b91c0e 100644 --- a/usergw-service/src/main/java/cn/ecpark/service/usergw/biz/filters/DubboFilter.java +++ b/usergw-service/src/main/java/cn/ecpark/service/usergw/biz/filters/DubboFilter.java @@ -1,47 +1,56 @@ package cn.ecpark.service.usergw.biz.filters; import java.nio.ByteBuffer; -import java.util.Map; + +import com.alibaba.fastjson.JSON; import org.apache.dubbo.config.ApplicationConfig; -import org.apache.dubbo.config.ProtocolConfig; import org.apache.dubbo.config.ReferenceConfig; -import org.apache.dubbo.config.RegistryConfig; import org.apache.dubbo.config.utils.ReferenceConfigCache; import org.apache.dubbo.rpc.service.GenericService; +import org.springframework.beans.factory.annotation.Autowired; import org.springframework.cloud.gateway.filter.GatewayFilterChain; import org.springframework.cloud.gateway.filter.GlobalFilter; +import org.springframework.context.ApplicationContext; import org.springframework.core.Ordered; import org.springframework.http.server.reactive.ServerHttpResponse; import org.springframework.stereotype.Component; import org.springframework.web.server.ServerWebExchange; -import com.alibaba.fastjson.*; +import io.netty.util.Recycler; import reactor.core.publisher.Mono; @Component public class DubboFilter implements GlobalFilter, Ordered { + @Autowired + private ApplicationContext appContext; + @Override public int getOrder() { return Ordered.LOWEST_PRECEDENCE; } + ReferenceConfigCache cache = ReferenceConfigCache.getCache(); + @Override public Mono filter(ServerWebExchange exchange, GatewayFilterChain chain) { - exchange.getRequest(); + // exchange.getRequest(); ReferenceConfig reference = new ReferenceConfig(); // 该实例很重量,里面封装了所有与注册中心及服务提供方连接,请缓存 - + reference.setApplication(new ApplicationConfig("dubbo-exchange")); // reference.setRegistry(new RegistryConfig("zookeeper://127.0.0.1:2181")); + reference.setGroup("group"); reference.setInterface("ocean.demo.api.IExchange"); // 弱类型接口名 reference.setVersion("1.0.0"); reference.setGeneric(true); // 声明为泛化接口 - ReferenceConfigCache cache = ReferenceConfigCache.getCache(); - GenericService gs = cache.get(reference); + Recycler a; + + GenericService gs = cache.get(reference); Object result = gs.$invoke("Hello", new String[] {}, new Object[] {}); + if (result != null) { ServerHttpResponse response = exchange.getResponse(); return response.writeWith( diff --git a/usergw-service/src/main/java/cn/ecpark/service/usergw/biz/filters/bean/GenericServicePool.java b/usergw-service/src/main/java/cn/ecpark/service/usergw/biz/filters/bean/GenericServicePool.java new file mode 100644 index 0000000..34afeaf --- /dev/null +++ b/usergw-service/src/main/java/cn/ecpark/service/usergw/biz/filters/bean/GenericServicePool.java @@ -0,0 +1,93 @@ +package cn.ecpark.service.usergw.biz.filters.bean; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.LinkedList; +import java.util.List; +import java.util.concurrent.TimeUnit; +import java.util.concurrent.locks.Condition; +import java.util.concurrent.locks.Lock; +import java.util.concurrent.locks.ReentrantLock; + +import org.apache.dubbo.config.ReferenceConfig; +import org.apache.dubbo.rpc.service.GenericService; + +import lombok.extern.slf4j.Slf4j; + +/** + * GenericServicePool + */ +@Slf4j +public class GenericServicePool { + + private class GenericServiceManager { + + Lock lock = new ReentrantLock(); + + LinkedList idle = new LinkedList<>(); + LinkedList busy = new LinkedList<>(); + + private String key; + + @Override + public int hashCode() { + return this.key.hashCode(); + } + + /** + * @return String return the key + */ + public String getKey() { + return key; + } + + /** + * @param key the key to set + */ + public void setKey(String key) { + this.key = key; + } + + public GenericService get() { + try { + if(lock.tryLock(15L, TimeUnit.SECONDS)) { + return idle.pop(); + } else { + log.error(this.key + ": 超时{}秒", 15); + } + } catch (Exception e) { + //TODO: handle exception + } finally { + lock.unlock(); + } + return null; + } + + + + + public GenericServiceManager() { + idle = new LinkedList<>(); + busy = new LinkedList<>(); + } + + } + + + HashMap gsDictionary; + + public GenericServicePool() { + gsDictionary = new HashMap(); + } + + + + public GenericService get(String key) { + + } + + public GenericService add(String key, Object genericService) { + + } + +} \ No newline at end of file diff --git a/usergw-service/src/main/resources/application.properties b/usergw-service/src/main/resources/application.properties index bfb7c87..a0b2c1d 100644 --- a/usergw-service/src/main/resources/application.properties +++ b/usergw-service/src/main/resources/application.properties @@ -4,6 +4,8 @@ dubbo.scan.base-packages=cn.ecpark.service.usergw.impl dubbo.protocol.name=dubbo dubbo.protocol.port=20999 dubbo.registry.address=zookeeper://127.0.0.1:2181 +dubbo.config-center.address=zookeeper://127.0.0.1:2181 +dubbo.metadata-report.address=zookeeper://127.0.0.1:2181 server.port=8888 -logging.level.org.springframework.cloud.gateway=debug +# logging.level.org.springframework.cloud.gateway=debug