Skip to content

5. 远程调用(客户端)

常用的几种RPC调用方式包括http client、RestTemplate、openFigen

此处演示HttpComponents和普通的RestTemplate,下一章演示RestTemplate集合Eureka做负载均衡、以及openFigen方式远程调用

  • 创建modules(cloud-rpc-clients)
  • 修改pom
<dependencies>
        <!-- 提供web 内嵌的Tomcat-->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>

        <!--测试框架 -->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
        </dependency>

        <!--热部署的工具 -->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-devtools</artifactId>
        </dependency>

        <!-- https://mvnrepository.com/artifact/org.apache.httpcomponents/httpclient -->
        <dependency>
            <groupId>org.apache.httpcomponents</groupId>
            <artifactId>httpclient</artifactId>
        </dependency>

    </dependencies>

Released under the MIT License.