sofastack / sofa-rpc-boot-projects

SOFABoot projects for SOFARPC, include starter and samples.
https://github.com/sofastack/sofa-rpc
Apache License 2.0
292 stars 117 forks source link

Some ideas about using RPC with SOFABoot #199

Open antergone opened 5 years ago

antergone commented 5 years ago

现在注解是在ReferenceAnnotationBeanPostProcessor阶段处理,扫描注解创建RPC代理对象,并通过反射的方式放到了注入点。

想法:

  1. 能否直接提供一个静态类工厂类(SofaRpcFactory)和一个通用配置文件(SofaProperties)。在这个工厂内提供create方法,内部做各种RPC初始化操作,并返回RPC动态代理接口对象。 TestFacade SofaRpcFactory.create(TestFacade.class, props)。 这样做可以直接将Client初始化完全黑盒在RPC组件内,将Facade的生命周期绑定到spring容器中去,初始化阶段不再依赖注解,显式的用@Bean将RPC和Spring连接起来。

这个想法来源于Retrofit2的客户端构造过程: retrofit2.Retrofit#create

  1. 提供EnableSofaRPC注解,通过import的方式激活Registrar,用Registrar配合Scanner进行扫描注册Bean。这里可以定一个规范,本地要有一个Facade接口继承其他服务的Facade包并带上@SofaRpcClient注解,或者开发者需要给出一个调用Facade 的Class列表供框架扫描。

这个想法来源于 Spring Cloud FeignClient的做法

sofastack-bot[bot] commented 5 years ago

Hi @antergone, we detect non-English characters in the issue. This comment is an auto translation by @sofastack-robot to help other users to understand this issue.

We encourage you to describe your issue in English which is more friendly to other users.

The annotation is now processed in the ReferenceAnnotationBeanPostProcessor stage, which scans the annotation to create the RPC proxy object and puts it into the injection point by reflection. Ideas: 1. Can you provide a static class factory class (SofaRpcFactory) and a generic configuration file (SofaProperties) directly. The create method is provided in this factory, and various RPC initialization operations are performed internally, and the RPC dynamic proxy interface object is returned. TestFacade SofaRpcFactory.create(TestFacade.class, props). This can directly initialize the client to the black box in the RPC component, bind the lifecycle of the facade to the spring container, and the initialization phase no longer relies on annotations. Explicitly connect RPC and Spring with @Bean. This idea comes from the client-side construction process of Retrofit2: retrofit2.Retrofit#create 2. Provides EnableSofaRPC annotations, activates Registrar by importing, and uses Registrar with Scanner to scan and register beans. Here you can define a specification. Locally, there must be a Facade interface inheriting the Facade package of other services with the annotation of @SofaRpcClient, or the developer needs to give a list of classes calling Facade for the framework to scan. This idea comes from the practice of Spring Cloud FeignClient