设为首页收藏本站

LUPA开源社区

 找回密码
 注册
文章 帖子 博客
LUPA开源社区 首页 业界资讯 软件追踪 查看内容

fastRPC v0.1发布,基于AIO的RPC调用框架

2016-4-11 22:48| 发布者: joejoe0332| 查看: 518| 评论: 0|原作者: oschina|来自: oschina

摘要: 基于java AIO实现的RPC调用框架,封装完全屏蔽IO通信层,使用者就像调用本地API一样调用RPC接口RPC服务端初始化?1234567publicstaticvoidmain(Stringargs)throwsException{newFastRpcServer().threadSize(20).regist ...

基于java AIO实现的RPC调用框架,封装完全屏蔽IO通信层,使用者就像调用本地API一样调用RPC接口

RPC服务端初始化

1
2
3
4
5
6
7
public static void main(String[] args) throws Exception {
        new FastRpcServer()
                .threadSize(20)
                .register("test"new TestService())
                .bind(4567)
                .start();
    }
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
public class TestService implements ITestService {
 
    private final Logger log = LoggerFactory.getLogger(getClass());
 
    @Override
    public String say(String what) {
        String result = "say " + what;
        log.debug(result);
        return result;
    }
 
    @Override
    public String name() {
        log.debug("call name");
        return "call name";
    }
 
    @Override
    public void ok(String ok) {
        log.debug("call ok");
        log.debug("param:{}", ok);
    }
 
    @Override
    public void none() {
        log.debug("call none");
    }
 
    @Override
    public User doUser(User user) {
        log.debug("收到user:" + user);
        user.setAge(user.getAge() - 1);
        user.setName("hello " + user.getName());
        user.setSex(!user.isSex());
        return user;
    }
}

RPC客户端初始化

1
2
3
4
5
6
7
8
9
10
public static void main(String[] args) {
        try(IClient client = new FastRpcClient()) {
            client.connect(new InetSocketAddress("127.0.0.1"4567));
            ITestService service = client.getService("test", ITestService.class);
            String say = service.say("Hello!");
            System.out.println(say);
        catch (Exception e) {
            e.printStackTrace();
        }
    }
1
2
3
4
5
6
7
8
9
10
11
12
public interface ITestService {
 
    String say(String what);
 
    String name();
 
    void ok(String ok);
 
    void none();
 
    User doUser(User user);
}

酷毙

雷人

鲜花

鸡蛋

漂亮
  • 快毕业了,没工作经验,
    找份工作好难啊?
    赶紧去人才芯片公司磨练吧!!

最新评论

关于LUPA|人才芯片工程|人才招聘|LUPA认证|LUPA教育|LUPA开源社区 ( 浙B2-20090187 浙公网安备 33010602006705号   

返回顶部