GithubHelp home page GithubHelp logo

lxzw / gd-rpc Goto Github PK

View Code? Open in Web Editor NEW

This project forked from goudai/gd-rpc

0.0 2.0 0.0 284 KB

goudai-rpc encapsulated using java the basic fundamental, minimize dependence, simple is the core idea

Java 100.00%

gd-rpc's Introduction

###Nio实现细节架构图

Nio 架构图

单机RPC调用

rpc server

    public class ServerBootstrapTest {
        static {
            //1 init context
            Serializer serializer = new JavaSerializer();
            Context.<Request, Response>builder()
                    .decoder(new DefaultDecoder<>(serializer))
                    .encoder(new DefaultEncoder<>(serializer))
                    .serializer(serializer)
                    .channelHandler(new RequestHandler())
                    .executorService(Executors.newFixedThreadPool(20, new NamedThreadFactory()))
                    .build()
                    .init();
        }

        public static void main(String[] args) throws Exception {
            // 2 init rpc server
            ServerBootstrap serverBootstrap = new ServerBootstrap(9999);
            //3 registry shutdown clean hook
            Runtime.getRuntime().addShutdownHook(new Thread(serverBootstrap::shutdown));
            //4 registry services..
            serverBootstrap.registry(UserService.class, new SimpleUserService());
            //5 started rpc server and await thread
            serverBootstrap.startup();


        }
    }

rpc client

    public class BootstrapTest {
        static {
            //1 init
            Serializer serializer = new JavaSerializer();
            Context.<Request, Response>builder()
                    .decoder(new DefaultDecoder<>(serializer))
                    .encoder(new DefaultEncoder<>(serializer))
                    .serializer(serializer)
                    .channelHandler(new ResponseHandler())
                    .executorService(Executors.newFixedThreadPool(20, new NamedThreadFactory()))
                    .build()
                    .init();
        }

        public static void main(String[] args) throws Exception {
            //2 create client
            Bootstrap bootstrap = new Bootstrap("localhost", 9999);
            //3 started client
            bootstrap.startup();
            //4 get proxy service
            UserService service = bootstrap.getService(UserService.class);
            //5 remote invoker
            User add = service.add(new User());
            // out result
            System.out.println(add);
            //7 shutdown
            bootstrap.shutdown();

        }
    }

gd-rpc's People

Contributors

qingmu-io avatar ufohjl avatar jinkora avatar

Watchers

James Cloos avatar forthedeal avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.