准备准备

This commit is contained in:
huangsimin 2019-06-28 18:52:20 +08:00
parent 2c0e118623
commit 606dde8aba
4 changed files with 33 additions and 2 deletions

View File

@ -58,6 +58,12 @@
<artifactId>snakeyaml</artifactId>
<version>1.21</version>
</dependency>
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>fastjson</artifactId>
<version>1.2.58</version>
</dependency>
<dependency>
<groupId>cn.ecpark.service</groupId>

View File

@ -1,18 +1,31 @@
package cn.ecpark.service.usergw.biz.filters;
import java.nio.ByteBuffer;
import java.util.Map;
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.cloud.gateway.filter.GatewayFilterChain;
import org.springframework.cloud.gateway.filter.GlobalFilter;
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 reactor.core.publisher.Mono;
@Component
public class DubboFilter implements GlobalFilter, Ordered {
@ -32,11 +45,19 @@ public class DubboFilter implements GlobalFilter, Ordered {
reference.setInterface("ocean.demo.api.IExchange"); // 弱类型接口名
reference.setVersion("1.0.0");
reference.setGeneric(true); // 声明为泛化接口
GenericService gs = reference.get();
ReferenceConfigCache cache = ReferenceConfigCache.getCache();
GenericService gs = cache.get(reference);
Object result = gs.$invoke("Hello", new String[]{}, new Object[]{});
return null;
if (result != null) {
ServerHttpResponse response = exchange.getResponse();
return response.writeWith( Mono.just(response.bufferFactory().wrap(ByteBuffer.wrap(JSON.toJSONString(result).getBytes()))));
}
return chain.filter(exchange);
}
}

View File

@ -25,6 +25,8 @@ public class VerifyFilter implements GlobalFilter {
if(true) return chain.filter(exchange);
ServerHttpRequest request = exchange.getRequest();
HttpHeaders header = request.getHeaders();

View File

@ -5,3 +5,5 @@ dubbo.protocol.name=dubbo
dubbo.protocol.port=20999
dubbo.registry.address=zookeeper://127.0.0.1:2181
server.port=8888
logging.level.org.springframework.cloud.gateway=debug