mirror of
https://github.com/tiennm99/zfoo.git
synced 2026-08-07 06:30:17 +00:00
perf[module]:网关转发消息到Provider注释
This commit is contained in:
@@ -196,6 +196,8 @@ public class Router implements IRouter {
|
||||
|
||||
try {
|
||||
SignalBridge.addSignalAttachment(clientSignalAttachment);
|
||||
|
||||
// 里面调用的依然是:send方法发送消息
|
||||
send(session, packet, clientSignalAttachment);
|
||||
|
||||
IPacket responsePacket = clientSignalAttachment.getResponseFuture().get(DEFAULT_TIMEOUT, TimeUnit.MILLISECONDS);
|
||||
|
||||
@@ -31,6 +31,8 @@ import java.util.concurrent.Executors;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
|
||||
/**
|
||||
* 这是客户端连接网关,网关转发到服务提供者的测试用例
|
||||
*
|
||||
* @author jaysunxiao
|
||||
* @version 3.0
|
||||
*/
|
||||
@@ -40,7 +42,12 @@ public class GatewayTest {
|
||||
private static final Logger logger = LoggerFactory.getLogger(GatewayTest.class);
|
||||
|
||||
/**
|
||||
* 启动zookeeper,依次运行下面的测试方法启动服务提供者,网关,然后运行clientTest,消息会通过网关转发到服务提供者
|
||||
* 启动zookeeper,依次运行下面的测试方法启动:
|
||||
* 1.服务提供者
|
||||
* 2.网关
|
||||
* 3.然后运行clientTest
|
||||
* <p>
|
||||
* 消息会通过网关转发到服务提供者
|
||||
*/
|
||||
@Test
|
||||
public void startProvider0() {
|
||||
@@ -63,6 +70,9 @@ public class GatewayTest {
|
||||
ThreadUtils.sleep(Long.MAX_VALUE);
|
||||
}
|
||||
|
||||
/**
|
||||
* 这是网关
|
||||
*/
|
||||
@Test
|
||||
public void startGateway() {
|
||||
var context = new ClassPathXmlApplicationContext("gateway/gateway_consistent_session_config.xml");
|
||||
@@ -72,11 +82,15 @@ public class GatewayTest {
|
||||
ThreadUtils.sleep(Long.MAX_VALUE);
|
||||
}
|
||||
|
||||
/**
|
||||
* 这里是客户端,客户端先请求数据到到网关(毕竟自己连接的就是网关)
|
||||
*/
|
||||
@Test
|
||||
public void clientTest() {
|
||||
var context = new ClassPathXmlApplicationContext("gateway/gateway_client_config.xml");
|
||||
SessionUtils.printSessionInfo();
|
||||
|
||||
// 这里的地址是网关的地址
|
||||
var client = new TcpClient(HostAndPort.valueOf("127.0.0.1:9000"));
|
||||
var session = client.start();
|
||||
|
||||
@@ -91,6 +105,7 @@ public class GatewayTest {
|
||||
var thread = new Thread(() -> {
|
||||
for (int j = 0; j < 10000; j++) {
|
||||
try {
|
||||
// 注意:这里的ask请求参数是 xxxRequest,不是xxxAsk
|
||||
var response = NetContext.getRouter().syncAsk(session, request, GatewayToProviderResponse.class, null).packet();
|
||||
logger.info("客户端请求[{}]收到消息[{}]", atomicInteger.incrementAndGet(), JsonUtils.object2String(response));
|
||||
} catch (Exception e) {
|
||||
|
||||
@@ -24,12 +24,9 @@
|
||||
<net:address name="firstZookeeper" url="127.0.0.1:2181"/>
|
||||
</net:registry>
|
||||
|
||||
<!-- <net:consumer load-balancer="consistent-hash">-->
|
||||
<!-- <net:module name="providerTest"/>-->
|
||||
<!-- </net:consumer>-->
|
||||
|
||||
<!--1.声明自己是个消费者 2.指明自己可以消费的接口是providerTest中声明的接口 3.消费的接口是服务提供者是myProvider1提供的具体实现-->
|
||||
<net:consumers>
|
||||
<net:consumer protocol-module="test" consumer="myProvider1" load-balancer="consistent-hash"/>
|
||||
<net:consumer protocol-module="providerTest" consumer="myProvider1"/>
|
||||
</net:consumers>
|
||||
|
||||
</net:config>
|
||||
|
||||
@@ -24,6 +24,7 @@
|
||||
<net:address name="${registry.address.name}" url="${registry.address.url}"/>
|
||||
</net:registry>
|
||||
|
||||
<!--1.这里声明自己是服务提供者 2.提供接口是providerTest模块下的接口 3.提供者的名字是myProvider1-->
|
||||
<net:providers task-dispatch="consistent-hash">
|
||||
<net:provider protocol-module="providerTest" provider="myProvider1"/>
|
||||
<net:provider protocol-module="providerTest" provider="myProvider2"/>
|
||||
|
||||
Reference in New Issue
Block a user