All Products
Search
Document Center

Dubbo Basics

Last Updated: Aug 17, 2020

To use a different communication protocol in SOFARPC, you just need to set Binding to the corresponding value. To use the Dubbo protocol, set Binding to Dubbo. This topic describes how to configure and use the Dubbo protocol in the Annotation mode. For more information about how to configure in other modes, see Basic usage of Bolt protocol.

Publish a service

To publish a Dubbo service, set bindingType of @SofaServiceBinding to dubbo.

  1. @Service
  2. @SofaService(bindings = {@SofaServiceBinding(bindingType = "dubbo")})
  3. public class SampleServiceImpl implements SampleService {
  4. }

Reference services

To reference a Dubbo service, set bindingType of @SofaReferenceBinding to dubbo.

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

Set the Group attribute for a Dubbo service

In a SOFARPC model, an existing attribute called Group does not exist. However, the SOFARPC model has a uniqueId attribute that can be directly mapped to the Group attribute in a Dubbo model. For example, the code below is used to publish a service whose Group is groupDemo.

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

The code below is used to reference a service whose Group is groupDemo.

  1. @SofaReference(binding = @SofaReferenceBinding(bindingType = "dubbo"), uniqueId = "groupDemo", jvmFirst = false)
  2. private SampleService sampleService;

Note: Currently, the Dubbo protocol only supports ZooKeeper as the registry.