RPC 远程调用
- 配置
- 开始使用
- 高级功能
例如 :
- jboot.rpc.type : RPC 的类型,不配置默认为 Dubbo
- jboot.rpc.callMode : RPC 的调用方式
- direct : 直联模式
- registry : 注册中心模式(服务注册和服务发现)
- jboot.rpc.directUrl : 当 callMode 为 direct 直联模式时,需要配置直联模式的服务器 IP 地址和端口号。
一般情况下,RPC 调用需要以下几个步骤:
- 1、定义接口
- 2、编写实现类
- 3、启动 Server 暴露服务
public interface BlogService {
public String findById();
public List<String> findAll();
}
编写实现类
启动 Server 暴露服务
public class DubboServer {
public static void main(String[] args) {
System.out.println("DubboServer started...");
}
启动客户端、通过 RPC 调用 Server 提供的服务
- @RPCBean,标示当前服务于RPC服务
- @RPCInject,RPC注入赋值
虽然以上示例中,@RPCBean
和 @RPCInject
没有添加任何的参数,但实际是他们提供了非常丰富的配置。
以下分别是 @RPCBean
和 @RPCInject
的定义:
RPCBean :
public @interface RPCBean {
int port() default 0;
int timeout() default -1;
int actives() default -1;
String group() default "";
String version() default "";
//当一个Service类实现对个接口的时候,
//可以通过这个排除不暴露某个实现接口
Class[] exclude() default Void.class;
}