2024-08-01 10:54:13 +08:00
|
|
|
|
package com.jsowell.netty.rpc;
|
2024-07-31 16:48:29 +08:00
|
|
|
|
|
2024-08-01 16:24:52 +08:00
|
|
|
|
import com.jsowell.pile.rpc.RpcUtil;
|
|
|
|
|
|
|
2024-07-31 16:48:29 +08:00
|
|
|
|
import java.util.concurrent.TimeUnit;
|
|
|
|
|
|
|
|
|
|
|
|
public class TestRpcClient {
|
|
|
|
|
|
public static void main(String[] args) throws Exception{
|
|
|
|
|
|
//Channel channel = new RpcClient().connect("127.0.0.1", 8888);
|
|
|
|
|
|
|
|
|
|
|
|
Thread thread1 = new Thread(new Runnable() {
|
|
|
|
|
|
@Override
|
|
|
|
|
|
public void run() {
|
|
|
|
|
|
RpcRequest rpcRequest = new RpcRequest();
|
|
|
|
|
|
rpcRequest.setParam("参数1");
|
|
|
|
|
|
|
|
|
|
|
|
try {
|
2024-08-01 16:24:52 +08:00
|
|
|
|
// System.out.println("thread1发送请求");
|
|
|
|
|
|
// RpcResponse rpcResponse = RpcUtil.send(rpcRequest, 5, TimeUnit.SECONDS);
|
|
|
|
|
|
// System.out.println("thread1处理结果:" + rpcResponse);
|
2024-07-31 16:48:29 +08:00
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
|
throw new RuntimeException(e);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
Thread thread2 = new Thread(new Runnable() {
|
|
|
|
|
|
@Override
|
|
|
|
|
|
public void run() {
|
|
|
|
|
|
RpcRequest rpcRequest2 = new RpcRequest();
|
|
|
|
|
|
rpcRequest2.setParam("参数2");
|
|
|
|
|
|
|
|
|
|
|
|
try {
|
2024-08-01 16:24:52 +08:00
|
|
|
|
// System.out.println("thread2发送请求");
|
|
|
|
|
|
// RpcResponse rpcResponse = RpcUtil.send(rpcRequest2, 2, TimeUnit.SECONDS);
|
|
|
|
|
|
// System.out.println("thread2处理结果:" + rpcResponse);
|
2024-07-31 16:48:29 +08:00
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
|
throw new RuntimeException(e);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
// 休眠一下,等待客户端与服务端进行连接
|
|
|
|
|
|
Thread.sleep(1000);
|
|
|
|
|
|
|
|
|
|
|
|
thread1.start();
|
|
|
|
|
|
thread2.start();
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|