1.使用方法

1.1添加依赖

  1. <dependency>
  2. <groupId>com.xy</groupId>
  3. <artifactId>xy-core-framework-common-dubbo</artifactId>
  4. <version>${xy-core-framework.version}</version>
  5. <exclusions>
  6. <exclusion>
  7. <groupId>log4j</groupId>
  8. <artifactId>log4j</artifactId>
  9. </exclusion>
  10. </exclusions>
  11. </dependency>
  12. <dependency>
  13. <groupId>com.alibaba.spring</groupId>
  14. <artifactId>spring-context-support</artifactId>
  15. <version>${alibaba.spring.context-support.version}</version>
  16. </dependency>

1.2添加配置

具体参见dubbo-common.properties

  1. #dubbo.service.com.trendsi.trace.TraceServiceApi1111.version=2.0.5
  2. #dubbo.reference.org.apache.dubbo.samples.api.DemoService.version=1.0.0
  3. #dubbo.reference.org.apache.dubbo.samples.api.DemoService.timeout=6000
  4. #dubbo.reference.org.apache.dubbo.samples.api.DemoService.sayHello.timeout=7000

1.3定义接口与实现

  1. public interface DemoServiceApi {
  2. RemoteResult<EchoDto> echo(EchoQueryDto queryDto);
  3. }
  1. @Slf4j
  2. @DubboService(methods = {@Method(name = "echo", timeout = 3000, retries = 0)},version = "${dubbo.service.com.company.demo.DemoServiceApi.version:1.0.0}")
  3. @RefreshScope
  4. @Api(value = "测试模块", tags = {"dubbo"})
  5. @RequiredArgsConstructor(onConstructor = @__(@Autowired))
  6. public class DemoServiceApiImpl implements DemoServiceApi {
  7. @Override
  8. @RequestMapping(value = "/echo", method = RequestMethod.GET)
  9. public RemoteResult<EchoDto> echo(EchoQueryDto queryDto) {
  10. EchoDto echoDto = new EchoDto();
  11. echoDto.setContent("----" + queryDto.getName());
  12. return RemoteResult.success(echoDto);
  13. }
  14. }

@DubboService(methods = {@Method(name = “echo”, timeout = 3000, retries = 0)},version = “${dubbo.service.com.company.demo.DemoServiceApi.version:1.0.0}”)

服务提供方暴露服务

后续可能做系统的灰度发布,对接dubbo的接口灰度,采用版本号的方式实现(consumer,provider相同)

(后续trace系统中可能会添加其他的灰度方式,比如ip)

@Method

对接口中的方法进行细粒度配置,

通常配置超时和重试次数,

对于查询操作,默认推荐重试2次(供3次),

对于update操作,为保证一致性和准确性,建议关闭重试,即retries = 0

备注:

@RefreshScope

@RestController

@Api(value = “测试模块”, tags = {“dubbo”})

这三个注解,与dubbo自身并无关系,只是将dubbo接口作为restful接口一并暴露。实际使用中,不推荐此操作

2.功能说明

2.1 扩展SPI-ExecutorRepository

dubbo2.7.5之后的版本,对线程池做了优化。具体实现在DefaultExecutorRepository类中。但是类中将线程池变量私有化,对其监控只能通过反射。

  1. private ConcurrentMap<String, ConcurrentMap<Integer, ExecutorService>> data = new ConcurrentHashMap<>()

�于是重写了框架本身的DefaultExecutorRepository,在完全覆盖其功能的情况下,添加线程池暴露方法。

详细请参考监控相关dubbo的部分。

2.2扩展SPI-Filter

对常见参数和服务提供方,消费方添加日志和链路TraceId