dubbo服务集群配置

xiaoxiao2021-02-28  146

一、基本概念

dubbo-provider

dubbo-consumber

二、工程框架

edu-service-user

在其src/main/resources/sping中,有一个dubbo-provider.xml文件,其中的配置如下

                      <!--使用zookeeper注册中心暴露服务地址-->

                     <dubbo:registry  protocol="zookeeper"  address="192.168.3.71:2181" />

                     <!--使用dubbo协议在20880端口暴露服务-->

                     <dubbo:protocol name="dubbo"  port="20880" />

                    <!--用户服务接口-->

                     <dubbo:service interface="wusc.edu.facade.user.service.PmsUserFacade"  ref="PmsUserFacade" />

edu-web-user

在其src/main/resources/sping中,有一个dubbo-consumber.xml文件,其中的配置如下

                   <!--使用zookeeper注册中心暴露服务地址-->

                     <dubbo:registry  protocol="zookeeper"  address="192.168.3.71:2181" />

                     <!--使用dubbo协议在20880端口暴露服务-->

                     <dubbo:protocol name="dubbo"  port="20880" />

                    <!--用户服务接口-->

                     <dubbo:reference interface="wusc.edu.facade.user.service.PmsUserFacade"  id="PmsUserFacade" check="false" />

edu-facade-user

注意:这里dubbo是服务的提供者,通过在注册中心上注册来将服务的IP和端口暴露出去(具体是通过“用户服务接口”这个接口暴露,可通过dubbo-admin上的服务列表查看);消费者也是通过这个接口来找到并消费服务方所提供的服务;

PS具体过程:服务提供者注册服务到zookeeper,消费者到zookeeper上订阅服务,初次调用时是通过zookeeper,后期则是直接进行关联;

三、集群负载均衡

在dubbo-admin中可以配置某服务的负载策略,有随机、轮询等多种策略,可以提供暴露在同一端口的dubbo服务在被调用时的负载均衡;默认为随机,一般不修改;

四、dubbo服务注册到zookeepek

服务起来后,向zookeeper注册服务;

五、实际项目中代码的配置文件

在一个拆分项目中,对于service端,其的dubbo-provider文件如下:

<?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:dubbo="http://code.alibabatech.com/schema/dubbo" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://code.alibabatech.com/schema/dubbo http://code.alibabatech.com/schema/dubbo/dubbo.xsd"> <dubbo:application name="jht-service-payment" /> <!-- 使用zookeeper注册中心暴露服务地址 --> <dubbo:registry protocol="zookeeper" address="${dubbo.registry.address}" /> <!-- 多协议配置 --> <dubbo:protocol name="dubbo" port="20886" /> <!-- <dubbo:protocol name="hessian" port="8089" /> --> <!-- 监控中心配置,protocol="registry",表示从注册中心发现监控中心地址 --> <dubbo:monitor protocol="registry" /> <!-- 当ProtocolConfig和ServiceConfig某属性没有配置时,采用此缺省值 --> <dubbo:provider timeout="30000" threadpool="fixed" threads="100" accepts="1000" /> <import resource="dubbo-service-payment.xml" /> <import resource="dubbo-service-member.xml" /> </beans> PS:可知,对于dubbo-provider文件,其中的注册中心地址啥的,都用变量替代了。对于redis-哨兵集群的配置文件也一样(在配置文件中写明哨兵的地址,主哨兵的名称,在其他地方来通过变量引用此主哨兵的地址)。即公共的地址都写在common文件中,其他的地方则使用变量来引用。

对于web端(名称为payment),其的dubbo-reference-payment文件如下

<?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:dubbo="http://code.alibabatech.com/schema/dubbo" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://code.alibabatech.com/schema/dubbo http://code.alibabatech.com/schema/dubbo/dubbo.xsd"> <dubbo:reference interface="com.jinhuitong.facade.payment.service.ICertifiedPaymentService" id="certifiedPaymentServiceImpl" check="false"/> <dubbo:reference interface="com.jinhuitong.facade.payment.service.IGatePaymentService" id="gatePaymentServiceImpl" check="false"/> <dubbo:reference interface="com.jinhuitong.facade.payment.member.serivce.IMemberWithdrawService" id="memberWithdrawServiceImpl" /> </beans>

转载请注明原文地址: https://www.6miu.com/read-44407.html

最新回复(0)