Closed GohnGM closed 5 years ago
首先基于我的理解是,蚂蚁团队为了解决Spring模块隔离问题而设计了JVM服务,RPC则是一个远程调用框架,所以做了一个测试,对结果感到很疑惑! 我将sample项目中的sofaboot-sample-with-rpc复制了一个副本,这里简称两个项目应用为A和B; 首先A定义为消费端,我屏蔽了本地implement的实现,同时移除了xml配置如下:
<sofa:service ref="personServiceImpl" interface="com.alipay.sofa.boot.examples.demo.rpc.bean.PersonService"> <sofa:binding.jvm/> </sofa:service> <sofa:reference id="personReferenceBolt" interface="com.alipay.sofa.boot.examples.demo.rpc.bean.PersonService"> <!--<sofa:binding.bolt/>--> <sofa:binding.jvm/> </sofa:reference> <sofa:reference id="personReferenceRest" interface="com.alipay.sofa.boot.examples.demo.rpc.bean.PersonService"> <sofa:binding.rest/> </sofa:reference> <bean id="personFilter" class="com.alipay.sofa.boot.examples.demo.rpc.bean.PersonServiceFilter"/> <sofa:rpc-global-filter ref="personFilter"/>
然后我打开副本项目,对xml做了如下更改:
<sofa:service ref="personServiceImpl" interface="com.alipay.sofa.boot.examples.demo.rpc.bean.PersonService"> <sofa:binding.bolt/> <sofa:binding.rest/> </sofa:service> <bean id="personFilter" class="com.alipay.sofa.boot.examples.demo.rpc.bean.PersonServiceFilter"/> <sofa:rpc-global-filter ref="personFilter"/>
最后我启动A、B,按照我的理解:如果采用如下方式调用: @Service class SofaRefClazz {
@SofaReference(interfaceType = PersonService.class, binding = @SofaReferenceBinding(bindingType = "jvm")) public PersonService personBolt; @SofaReference(interfaceType = PersonService.class, binding = @SofaReferenceBinding(bindingType = "rest")) public PersonService personRest;
............. } 按照我的预期控制台应该打印出: [JVM]hi bolt! [RPC]hi rest! 可是却出现了: [JVM]hi bolt! [JVM]hi rest!
服务引用有个优先 JVM 的策略,默认为 true. 可以通过设置注解 @SofaReference jvmFirst 属性
谢谢,测试的确是这样。
首先基于我的理解是,蚂蚁团队为了解决Spring模块隔离问题而设计了JVM服务,RPC则是一个远程调用框架,所以做了一个测试,对结果感到很疑惑! 我将sample项目中的sofaboot-sample-with-rpc复制了一个副本,这里简称两个项目应用为A和B; 首先A定义为消费端,我屏蔽了本地implement的实现,同时移除了xml配置如下:
然后我打开副本项目,对xml做了如下更改:
最后我启动A、B,按照我的理解:如果采用如下方式调用: @Service class SofaRefClazz {
.............
} 按照我的预期控制台应该打印出: [JVM]hi bolt! [RPC]hi rest! 可是却出现了: [JVM]hi bolt! [JVM]hi rest!