Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Describe what this PR does / why we need it
about the thoughts on issue #3750
Describe how you did it
不同RPC协议的本质区别在于序列化和数据格式,在原有的springcloud的REST/HTTP协议上添加dubbo(triple)和grpc协议,sca体系中,微服务之间的调用多为feign调用,为了不改变sca体系中client跟sever原有的rest风格(使用springboot)开发习惯,feign进行http请求关键的部分在Feign.Client中,我们实现Feign.Client,在execute方法中,建立与server的netty连接,通过这个netty我们将http请求涉及的(url,body,method,headers,封装为HttpMetadata对象)通过rpc协议(triple,grpc)进行传输,在server侧根据获取到的httpMetadata对象构建http请求,交由server侧的spring调用链(dispatcherServlet)进行处理
The fundamental differences between different RPC (Remote Procedure Call) protocols lie in their serialization and data formats. The existing Spring Cloud framework, which primarily uses the REST/HTTP protocols, can be extended by adding support for protocols like Dubbo (Triple) and gRPC, In the SCA system, the invocation between microservices is mostly done through Feign calls. In order to not change the original REST style (using SpringBoot) development habits of the client and server in the SCA system, the key part of Feign's HTTP request is in the Feign.Client. We implement the Feign.Client, and in the execute method, we establish a Netty connection with the server. Through this Netty, we encapsulate the HTTP request-related information (URL, body, method, headers) into an HttpMetadata object, and then transmit it through the RPC protocol (Triple, gRPC). On the server side, we construct the HTTP request based on the obtained HttpMetadata object and pass it to the Spring call chain for processing(dispatcherServlet)
SpringCloudAlibaba介绍
Spring Cloud Alibaba(下文简称为SCA) 致力于提供微服务开发的一站式解决方案。此项目包含开发分布式应用服务的必需组件,方便开发者通过 Spring Cloud 编程模型轻松使用这些组件来开发分布式应用服务。 依托 SCA,您只需要添加一些注解和少量配置,就可以将 Spring Cloud 应用接入阿里分布式应用解决方案,通过阿里中间件来迅速搭建分布式应用系统。
SpringCloudAlibaba-rpc-starter介绍:
为 SCA 提供业内主流的rpc(dubbo/grpc)接入能力
方案选型:
在SCA体系中,服务的producer跟consumer使用http协议进行通信(一般是openfeign),与
在java体系中,业内主流的rpc框架底层大多数使用基于netty的tcp协议进行传输,而不同rpc协议之间的本质区别在于它们的数据格式跟序列化方式的不同
基于这样的认知,我们在producer侧调用netty.bind,同时在producer进行服务注册的时候将对应的rpc.netty.port添加到注册中心的metadata上
producer跟consumer之间的通信为了适应sca体系,使用的仍是openfeign调用
在consumer侧对Feign.Client进行实现,对execute方法进行重写
其参数Request中包含了一个http请求的基本参数(method,url,body,headers),将这些封装到HttpMetadata中
同时consumer根据Feign注解中的value值从loadbalance中获取到producer的服务信息,从中解析出rpc.netty.port,进行consumer的netty.connet,完成了netty的连接
这时只需要让netty的encoderHandler跟decoderHandler对应上rpc协议即可,所以方案中选用了Dubbo的Exchanger,默认传输的协议是Dubbo,使用的是Hessian2序列化。
将上述封装好的HttpMetadata通过netty传输到producer侧,根据httpMetadata的参数重新构建出HttpServletRequest,通过DispacherServlet进行Spring服务链的调用,完成服务通信
通过这种方式,在producer跟consumer都属于sca体系下实现了rpc协议的接入