文档

Dubbo 协议的基本使用

更新时间:

在 SOFARPC 中,使用不同的通信协议只要设置使用不同的 Binding 即可。如果需要使用 Dubbo 协议,只要将 Binding 设置为 Dubbo 即可。

本文以注解的使用方式为例,其他使用方式可以参考 BOLT 协议基本使用

发布服务

发布一个 Dubbo 的服务,只需要将 @SofaServiceBindingbindingType 设置为 dubbo

@Service
@SofaService(bindings ={@SofaServiceBinding(bindingType ="dubbo")})
public class SampleServiceImpl implements SampleService{
}

引用服务

引用一个 Dubbo 的服务,只需要将 @SofaReferenceBindingbindingType 设置为 dubbo

@SofaReference(binding =@SofaReferenceBinding(bindingType ="dubbo"), jvmFirst =false)
private SampleService sampleService;

设置 Dubbo 服务的 Group

在 SOFARPC 的模型中,没有直接的字段叫做 Group,但 SOFARPC 有一个 uniqueId 模型,可以直接映射到 Dubbo 的模型中的 Group。比如下面的代码,就是发布了一个 Group 为 groupDemo 的服务。

@Service
@SofaService(bindings ={@SofaServiceBinding(bindingType ="dubbo")}, uniqueId ="groupDemo")
public class SampleServiceImpl implements SampleService{
}

如下代码引用了一个 Group 为 groupDemo 的服务。

@SofaReference(binding =@SofaReferenceBinding(bindingType ="dubbo"), uniqueId ="groupDemo", jvmFirst =false)
private SampleService sampleService;
重要

目前 Dubbo 协议只支持 Zookeeper 作为服务注册中心。

  • 本页导读 (0)
文档反馈