https://github.com/furiouspws002/mini-rpc
简化版RPC,使用netty实现远程调用与响应
https://github.com/furiouspws002/mini-rpc
netty netty-rpc rpc rpc-client rpc-server
Last synced: 4 months ago
JSON representation
简化版RPC,使用netty实现远程调用与响应
- Host: GitHub
- URL: https://github.com/furiouspws002/mini-rpc
- Owner: FuriousPws002
- License: apache-2.0
- Created: 2024-05-06T14:05:10.000Z (about 2 years ago)
- Default Branch: main
- Last Pushed: 2024-05-06T14:37:58.000Z (about 2 years ago)
- Last Synced: 2025-02-10T23:51:12.383Z (over 1 year ago)
- Topics: netty, netty-rpc, rpc, rpc-client, rpc-server
- Language: Java
- Homepage: https://github.com/FuriousPws002/mini-rpc
- Size: 14.6 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# mini-rpc
简化版RPC,使用netty实现远程调用与响应,包含如下功能
1. 自定义协议
2. 编码/解码实现
3. 同步方式调用
单元测试
```java
public class ProviderConsumerTest {
@Test
@SneakyThrows
public void test() {
int threadNum = 20;
CountDownLatch latch = new CountDownLatch(threadNum);
//server
ProviderServiceRegistry.INSTANCE.register(HelloService.class, new HelloServiceImpl());
Provider provider = new Provider();
provider.start();
//client
ConsumerServiceDiscovery discovery = new ConsumerServiceDiscovery("localhost", 8888);
HelloService helloService = discovery.get(HelloService.class);
final AtomicInteger atomic = new AtomicInteger();
for (int i = 0; i < threadNum; i++) {
new Thread(() -> {
String req = "hhh_" + atomic.incrementAndGet();
String resp = helloService.sayHello(req);
System.err.println("req:" + req + " resp:" + resp);
latch.countDown();
}).start();
}
latch.await();
provider.close();
discovery.close();
}
}
```