An open API service indexing awesome lists of open source software.

https://github.com/lmxy1990/slimrpc

一个精简的rpc框架
https://github.com/lmxy1990/slimrpc

dynamic netty-rpc rpc rpc-framework

Last synced: 3 months ago
JSON representation

一个精简的rpc框架

Awesome Lists containing this project

README

          

# slimrpc
---
基于netty,jdk本身的动态代理.结合spring封装出一个简单高可靠性的rpc框架.
目标:一切从简,轻量级,高可维护性.
使用只需要依赖jar包,简单配置即可.

## 特点
1. 简洁
2. 高效
3. 去中心化
4. 双向调用
5. 客户端/服务端双向认证

## demo
---

1.添加依赖

```

io.github.lmxy1990
slimrpc-core
1.0.0

```

2.创建接口

```
public interface UserService {

String sayHello(String name) ;

UserResult login(UserOption userOption) ;

}
```
3.服务端实现接口

```
@Component
@EnableSlimRpc
public class UserServiceImpl implements UserService {

@Override
public String sayHello(String name) {
return "hello ," + name;
}

@Override
public UserResult login(UserOption userOption) {

System.out.println("用户:" + userOption.getName());
System.out.println("年龄:" + userOption.getAge() + "正在请求登录");
UserResult result = new UserResult();
result.setName(userOption.getName());
result.setLoginInfo("登录信息:" + RandomStringUtils.randomAlphabetic(20));
return result;
}
}

```

4. 服务端,添加配置

```





```

5. 客户端,添加配置

```




6300








```

6. 启动服务端

```
@ContextConfiguration({"/spring-context-server.xml"})
public class TestServer extends AbstractJUnit4SpringContextTests {

@Test
public void testStartServer(){

try {
Thread.sleep(100000000);
} catch (InterruptedException e) {
e.printStackTrace();
}

}

}

```

7.客户端发起请求

```
@ContextConfiguration({"/spring-context-client.xml"})
public class TestClient extends AbstractJUnit4SpringContextTests {

@Autowired
@Qualifier("userService")
private UserService userService ;


@Test
public void testSayHello(){

String mayun = userService.sayHello("mayun");

System.out.println(mayun);

}


@Test
public void testMyClassParam() {
UserOption option = new UserOption("zhangsan","32") ;

UserResult login = userService.login(option);

System.out.println(login.getLoginInfo());

}


}

```