Giter Site home page Giter Site logo

rpc-spring-starter-demo's Introduction

rpc-spring-starter-demo

demoservice

服务接口

demoserver

实现服务接口

democlient

服务调用

本地运行

  1. 克隆rpc-spring-starter到本地install
    git clone [email protected]:PPPHUANG/rpc-spring-starter.git
    mvn clean install -DskipTests=true
  2. 启动ZK(默认地址是127.0.0.1:2128,其他ZK地址可在项目配置文件中修改)
  3. 启动demoserver
  4. 启动democlient
  5. 调用democlient服务中的HTTP接口即可
    http://localhost:8090/test
    http://localhost:8090/test2
    http://localhost:8090/test3
    
  6. 手动获取代理对象
package cn.ppphuang.democlient;

import cn.ppphuang.democlient.service.TestUnitCallBackHandler;
import cn.ppphuang.demoservice.DemoService;
import cn.ppphuang.rpcspringstarter.client.net.ClientProxyFactory;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;

@SpringBootTest
class DemoclientApplicationTests {

    @Autowired
    ClientProxyFactory clientProxyFactory;

    @Test
    void contextLoads() {
    }

    @Test
    void test() throws InterruptedException {
        DemoService proxy = clientProxyFactory.getProxy(DemoService.class);
        String ppphuang = proxy.hello("ppphuang");
        System.out.println(ppphuang);
    }

    @Test
    void testSyncGroup2Version2() throws InterruptedException {
        DemoService proxy = clientProxyFactory.getProxy(DemoService.class, "group2", "version2");
        String ppphuang = proxy.hello("ppphuang");
        System.out.println(ppphuang);
    }

    @Test
    void testSyncGroup3Version3() throws InterruptedException {
        DemoService proxy = clientProxyFactory.getProxy(DemoService.class, "group3", "version3");
        String ppphuang = proxy.hello("ppphuang");
        System.out.println(ppphuang);
    }

    @Test
    void testAsync() throws InterruptedException {
        DemoService proxy = clientProxyFactory.getProxy(DemoService.class, "group2", "version2", true);
        TestUnitCallBackHandler callBackHandler = new TestUnitCallBackHandler();
        ClientProxyFactory.setLocalAsyncContextAndAsyncReceiveHandler("context", callBackHandler);
        String ppphuang = proxy.hello("ppphuang");
        System.out.println(ppphuang);
        Thread.sleep(10000);
    }
}

rpc-spring-starter-demo's People

Contributors

ppphuang avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 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.