RPC 远程调用

    • 配置
    • 开始使用
    • 高级功能

    例如 :

    • jboot.rpc.type : RPC 的类型,不配置默认为 Dubbo
    • jboot.rpc.callMode : RPC 的调用方式
      • direct : 直联模式
      • registry : 注册中心模式(服务注册和服务发现)
    • jboot.rpc.directUrl : 当 callMode 为 direct 直联模式时,需要配置直联模式的服务器 IP 地址和端口号。

    一般情况下,RPC 调用需要以下几个步骤:

    • 1、定义接口
    • 2、编写实现类
    • 3、启动 Server 暴露服务
    1. public interface BlogService {
    2. public String findById();
    3. public List<String> findAll();
    4. }

    编写实现类

    启动 Server 暴露服务

    1. public class DubboServer {
    2. public static void main(String[] args) {
    3. System.out.println("DubboServer started...");
    4. }

    启动客户端、通过 RPC 调用 Server 提供的服务

    • @RPCBean,标示当前服务于RPC服务
    • @RPCInject,RPC注入赋值

    虽然以上示例中,@RPCBean@RPCInject 没有添加任何的参数,但实际是他们提供了非常丰富的配置。

    以下分别是 @RPCBean@RPCInject 的定义:

    RPCBean :

    1. public @interface RPCBean {
    2. int port() default 0;
    3. int timeout() default -1;
    4. int actives() default -1;
    5. String group() default "";
    6. String version() default "";
    7. //当一个Service类实现对个接口的时候,
    8. //可以通过这个排除不暴露某个实现接口
    9. Class[] exclude() default Void.class;
    10. }