How Uniformed Services Invocation Framework?

Introduction:

current Spring Cloud and Dubbo systems are widely used in the field of micro-Java services. Different users will choose the appropriate architecture according to needs of the project. However, in some cross-system scenarios will involve mixed calls between the two systems. How to do minor modification and support mix calls Spring Cloud Dubbo both systems? This article will introduce you to our Spring CLoud and unified framework Dubbo call service in case of minor modifications.

Currently Spring Cloud and Dubbo system development are more mature, many customers have been using some of the systems they developed. Good micro-services development platform needs to support both systems. Unified development experience and reduce development complexity while retaining the advantages of the two systems each.

Existing enterprise IT infrastructure

Service call Scene


IT companies have different status and technology roadmap based on different systems. For the new system, using common priority application calls Spring Cloud Spring Coud application or application calls Dubbo Dubbo application.

But the structure adjustment for the transformation of the existing system, that is, if the system is A Spring Cloud system, want to add or modify some services to Dubbo and vice versa, mixed service calls 2,4 scene will appear, this kind of scene mainly through over-compatible to ensure a smooth upgrade.



Inferences based on usage scenarios, the original system may be Spring Cloud or Dubbo, so the service registry need to support Eureka and Zookeeper, calling the agreement need to support Http (Restful) or RPC protocol.

Operating logic can be resolved in the following paragraphs:
 

  1. The service provider can configure the item, the specific services provided to outside Spring Cloud (Restful) and Dubbo (RPC) protocol services

  2. Service provider according to a service type provided by the protocol, into a corresponding service contract, and register the Eureka Zookeeper

  3. Service consumer access to services and registration information from Eureka Zookeeper, the analysis according to the service contract

  4. Consumer service provider service according to configuration items, acquisition of service contracts, call service


 

  • 采用统一声明式调用方式使得开发人员比较容易开发应用,调用实现通过服务类型区分,分别采用Feign,Dubbo采用自带实现,这样可以有效支持已有系统调用,降低学习成本。

  • 独立注解可以统一规范开发,控制平台调用规则处理需要提供和消费的接口。

  • 服务类型控制应用是服务提供方还是服务消费方,可以在同一应用中支持服务双体系和消费双体系。

  • 灵活配置的服务体系规则,便于根据需要调整服务体系,如应用总体为Spring Cloud,新增提供和消费服务都是Dubbo,可以在原有的配置中,增加这些新服务为Dubbo体系规则即可。


定义期决定运行的过程


服务类型是针对具体的服务提供类型为Spring Cloud(Restful)服务还是Dubbo(RPC)服务,提供对应的服务契约(完整的服务描述Swagger)。

注册中心类型就是基于启动依赖和配置项,决定连接的注册中心具体为Eureka还是Zookeeper,提供对应的服务发布格式(注册中心存储的服务格式)。


服务类型决定应用、包、接口类型定义的优先级依次递增,即如果都有配置时,以接口配置为准。服务类型的切换,可以通过配置文件的修改调整,无需调整代码。

服务提供和服务调用的关键逻辑:

1. 根据配置,扫描EOSService接口。
2. 判断服务提供类型,包含多层级优先级判断,确定服务提供类型。
a ) Dubbo类型:仿照Dubbo本身服务发布的形式,注册Dubbo bean实例
b ) Spring Cloud类型:根据约定发布对应Restful服务(因为为方便开发采用声明式调用,所以需要平台约定如url、type等规则)
3. 判断服务调用类型,包含多层级优先级判断,确定服务调用方式。
a ) Dubbo类型:仿照Dubbo本身服务发布的形式,注册Dubbo bean实例
b ) Spring Cloud类型:根据约定注册Feign bean。调用时,通过Feign调用服务。

 

注册中心根据如上依赖项决定,启动bean加载不同。不同的注册中心保留的服务发布时机和格式有不同。


同体系的注册中心因为需要对接已有系统,所以服务发布格式都延用同体系内容,如Spring Cloud服务发布到Eureka,和Dubbo服务发布到Zookeeper中的服务格式同原有系统其他服务,不做特殊处理。

服务发布和服务获取的关键逻辑:

1. 根据依赖项,启动不同注册中心初始化过程。
2. 判断注册中心类型,替换服务注册实例。
a ) Zookeeper类型:启动Zookeeper注册和监听实例,根据服务提供类型,组织服务发布格式到Zookeeper节点(具体格式后面有示例)。
b ) Eureka类型:Spring Cloud同原有,Dubbo服务通过异步扫描,放置到对应的扩展属性。
3. 判断注册中心类型,替换服务实例获取方式。
a ) Zookeeper类型:启动Zookeeper注册和监听实例,根据服务提供类型,从 Zookeeper节点获取并解析服务格式(具体格式后面有示例)。
b ) Eureka类型:Spring Cloud同原有,Dubbo服务通过监听Eureka 扩展属性。



Spring Cloud服务的发布格式在Zookeeper中存储如上图,在Zookeeper中新增/spring-cloud-service目录,记录Spring Cloud服务访问所需要的要素。

焦作国医堂胃肠医院地址在哪里:http://jz.lieju.com/zhuankeyiyuan/37175869.htm


["dubbo://172.20.10.7:20882/com.primeton.eos.demo.sdk.server.core.api.DubboService?anyhost=true&application=provider&bean.name=ServiceBean:dubboServiceController:com.primeton.eos.demo.sdk.server.core.api.DubboService&default.deprecated=false&default.dynamic=false&default.register=true&default.timeout=1000&deprecated=false&dubbo=2.0.2&dynamic=false&generic=false&interface=com.primeton.eos.demo.sdk.server.core.api.DubboService&methods=addUserPost,addUser&pid=46073®ister=true&release=2.7.1&side=provider×tamp=1573006719825"]

9002
61441


Dubbo服务的发布格式在Eureka中存储如上图,将完整的Dubbo服务所需要的要素全部存储到metadata中。

开发使用示例


关键时序处理链路示例


实际运行过程,根据服务的具体配置项和注册中心有相应的差异。



【小结】统一调用框架就是怎么支持各种混合服务调用的场景,又能统一一种开发体验,根据需要灵活调整实际服务类型。框架解决的问题是开发期统一简单,运行期灵活多变,保证服务稳定。实现时需要约束服务类型规则和注册中心依赖形式,同时定义配套提供和调用规则。如定义Spring Cloud的服务地址规则。http://dalian.qd8.com.cn/yiyao/xinxi21_3709996.html
【后记】在方案实现中遇到以下几类问题:



因具体问题与Spring Cloud、Dubbo和第三方具体jar版本有关,只能具体问题具体解决。
 

  • Jar版本冲突一般采用调整或锁定jar版本。

  • Bean冲突一般修改Bean的配置或者名称。

  • 配置项冲突需要自定义配置项处理过程,通过参数或启动脚本设置。


关于作者:零零九,现任普元金融资深工程师,主要负责微服务平台和流程平台设计与开发,先后参与公司EOS、BPS的产品开发和客户定制。持续关注应用安全和NLP。


Guess you like

Origin blog.51cto.com/14510269/2450476