(一)原有的协议保留,在Triple协议的端口上陆续集成不同的协议。在未来某一个版本之后,去掉不同端口的实现:
因为Dubbo3 的主推协议是Triple,所以我们将会在Triple上做端口复用,即只要配置了Triple协议,就可以采用端口复用的能力。
第一种:举个例子,拿xml接入方式为例,以往我们配置多协议的方式是
<dubbo:protocol name="dubbo" port="20880"/> <dubbo:protocol name="tri" port="50051"/> <bean id="tripleService" class="org.apache.dubbo.demo.provider.TripleServiceImpl"/> <dubbo:service delay="5000" version="1.0.0" timeout="5000" interface="org.apache.dubbo.demo.TripleService" ref="tripleService" protocol="dubbo,tri"/>
而在20880端口上还是正常暴露TripleService服务,即在50051和20880上都支持dubbo协议。
第二种:在多协议配置中port还有”-1“值可选
<dubbo:protocol name="dubbo" port="-1"/> <dubbo:protocol name="tri" port="50051"/> <bean id="tripleService" class="org.apache.dubbo.demo.provider.TripleServiceImpl"/> <dubbo:service delay="5000" version="1.0.0" timeout="5000" interface="org.apache.dubbo.demo.TripleService" ref="tripleService" protocol="dubbo,tri"/>
为port=”-1“附加新的语义,它不再开设一个专门为dubbo协议提供的可用端口,而是向Triple协议上迁移。即在50051上支持dubbo和Triple协议。
(二)完全开辟新的端口复用的配置
比如:
<dubbo:application name="demo-provider" unification-port="60000"/> <dubbo:protocol name="dubbo" port="20880"/> <dubbo:protocol name="tri" port="50051"/> <bean id="tripleService" class="org.apache.dubbo.demo.provider.TripleServiceImpl"/> <dubbo:service delay="5000" version="1.0.0" timeout="5000" interface="org.apache.dubbo.demo.TripleService" ref="tripleService" protocol="dubbo,tri"/>
增加类似unification-port的配置,用于开启端口复用,并在该端口上加载所配置的协议dubbo、triple。
(三)在现有的协议上配置需要新增的协议
比如:
<dubbo:application name="demo-provider"/> <dubbo:protocol name="tri" port="50051" port-unification-protocols="dubbo"/> <bean id="tripleService" class="org.apache.dubbo.demo.provider.TripleServiceImpl"/> <dubbo:service delay="5000" version="1.0.0" timeout="5000" interface="org.apache.dubbo.demo.TripleService" ref="tripleService" protocol="tri"/>
TripleService服务仅仅暴露了triple协议,现在我们需要为50051端口继续支持dubbo协议,则在triple protocol 上增加port-unification-protocols配置,其中配置dubbo,即50051端口也将支持dubbo协议