1.使用方法
1.1添加依赖
<dependency>
<groupId>com.xy</groupId>
<artifactId>xy-core-framework-common-dubbo</artifactId>
<version>${xy-core-framework.version}</version>
<exclusions>
<exclusion>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>com.alibaba.spring</groupId>
<artifactId>spring-context-support</artifactId>
<version>${alibaba.spring.context-support.version}</version>
</dependency>
1.2添加配置
具体参见dubbo-common.properties
#dubbo.service.com.trendsi.trace.TraceServiceApi1111.version=2.0.5
#dubbo.reference.org.apache.dubbo.samples.api.DemoService.version=1.0.0
#dubbo.reference.org.apache.dubbo.samples.api.DemoService.timeout=6000
#dubbo.reference.org.apache.dubbo.samples.api.DemoService.sayHello.timeout=7000
1.3定义接口与实现
public interface DemoServiceApi {
RemoteResult<EchoDto> echo(EchoQueryDto queryDto);
}
@Slf4j
@DubboService(methods = {@Method(name = "echo", timeout = 3000, retries = 0)},version = "${dubbo.service.com.company.demo.DemoServiceApi.version:1.0.0}")
@RefreshScope
@Api(value = "测试模块", tags = {"dubbo"})
@RequiredArgsConstructor(onConstructor = @__(@Autowired))
public class DemoServiceApiImpl implements DemoServiceApi {
@Override
@RequestMapping(value = "/echo", method = RequestMethod.GET)
public RemoteResult<EchoDto> echo(EchoQueryDto queryDto) {
EchoDto echoDto = new EchoDto();
echoDto.setContent("----" + queryDto.getName());
return RemoteResult.success(echoDto);
}
}
@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类中。但是类中将线程池变量私有化,对其监控只能通过反射。
private ConcurrentMap<String, ConcurrentMap<Integer, ExecutorService>> data = new ConcurrentHashMap<>()
�于是重写了框架本身的DefaultExecutorRepository,在完全覆盖其功能的情况下,添加线程池暴露方法。
详细请参考监控相关dubbo的部分。
2.2扩展SPI-Filter
对常见参数和服务提供方,消费方添加日志和链路TraceId