NettyRpc

A simple RPC framework based on Netty, ZooKeeper and Spring

Github stars Tracking Chart

NettyRpc

An RPC framework based on Netty, ZooKeeper and Spring
中文详情:Chinese Details

Features:

  • Simple code and framework
  • Non-blocking asynchronous call and Synchronous call support
  • Long lived persistent connection
  • High availability, load balance and failover
  • Service Discovery support by ZooKeeper

Design:

design

How to use

  1. Define an interface:

     public interface HelloService { 
     	String hello(String name); 
     	String hello(Person person);
     }
    
  2. Implement the interface with annotation @RpcService:

     @RpcService(HelloService.class)
     public class HelloServiceImpl implements HelloService {
     	public HelloServiceImpl(){}
    
     	@Override
     	public String hello(String name) {
     		return "Hello! " + name;
     	}
    
     	@Override
     	public String hello(Person person) {
     		return "Hello! " + person.getFirstName() + " " + person.getLastName();
     	}
     }
    
  3. Run zookeeper

    For example: zookeeper is running on 127.0.0.1:2181

  4. Start server:

    Start server with spring: RpcBootstrap

    Start server without spring: RpcBootstrapWithoutSpring

  5. Use the client:

     ServiceDiscovery serviceDiscovery = new ServiceDiscovery("127.0.0.1:2181");
     final RpcClient rpcClient = new RpcClient(serviceDiscovery);
     // Sync call
     HelloService helloService = rpcClient.create(HelloService.class);
     String result = helloService.hello("World");
     // Async call
     IAsyncObjectProxy client = rpcClient.createAsync(HelloService.class);
     RPCFuture helloFuture = client.call("hello", "World");
     String result = (String) helloFuture.get(3000, TimeUnit.MILLISECONDS);

Overview

Name With Ownerluxiaoxun/NettyRpc
Primary LanguageJava
Program languageJava (Language Count: 1)
Platform
License:
Release Count3
Last Release NameNettyRpc-1.2 (Posted on 2020-09-09 11:24:11)
First Release NameNettyRpc-1.0 (Posted on )
Created At2016-03-13 05:24:45
Pushed At2024-02-04 01:58:43
Last Commit At2024-02-04 09:58:36
Stargazers Count2.3k
Watchers Count156
Fork Count1.2k
Commits Count108
Has Issues Enabled
Issues Count30
Issue Open Count5
Pull Requests Count15
Pull Requests Open Count0
Pull Requests Close Count9
Has Wiki Enabled
Is Archived
Is Fork
Is Locked
Is Mirror
Is Private
To the top