dubbo+nacos+xml(nacos替换zookeeper)

已经搭建好的dubbo框架为前提
(注解引入dubbo的xml文件 @ImportResource(locations = "classpath:consumer.xml"))
开始替换为nacos
导入依赖:
<!-- Dubbo Nacos registry dependency -->
<dependency>
 <groupId>com.alibaba</groupId>
 <artifactId>dubbo-registry-nacos</artifactId>
 <version>0.0.1</version>
</dependency>

修改dubbo的xml文件  

<!-- 用于配置连接注册中心相关信息 -->

<dubbo:registry address="nacos://自己的ip:8848" check="false" />

下面是我的dubbo文件,只改上面这一行就可以

<?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="dubbo-xml-spring-boot-provider" />

   <!-- 用于配置连接注册中心相关信息 -->
   <dubbo:registry address="nacos://自己的ip:8848" check="false"  />
   <!-- 用于配置提供服务的协议信息,协议由提供方指定,消费方被动接受 -->
   <dubbo:protocol name="dubbo" port="20882" accesslog="true" />
   <!--<dubbo:consumer check="false" />
   <dubbo:registry check="false" />-->

   <!--用于暴露一个服务,定义服务的元信息,一个服务可以用多个协议暴露,一个服务也可以注册到多个注册中心 -->
   <!--每个接口都应定义版本号,为后续不兼容升级提供可能 -->
   <!--ref:服务的真正实现类 -->
   <dubbo:service interface="com.gjy.service.DefaultApiService" ref="defaultService" version="1.0.0"  stub="com.gjy.service.DefaultApiServiceSub"/>

   <!--<dubbo:service interface="com.gjy.service.DefaultApiService" ref="defaultService2" version="2.0.0"  />-->
   <!--监控中心配置 监控中心协议,如果为protocol="registry",表示从注册中心发现监控中心地址,否则直连监控中心。 -->
   <!--<dubbo:monitor protocol="registry"></dubbo:monitor>-->
   <!-- 直连监控中心服务器地址 -->
   <!-- <dubbo:monitor address="localhost:6379"></dubbo:monitor> -->

</beans>

我的 application.properties 文件如下:

server.port=9090
#nacos.config.namespace=b0c23b23-0652-4aa3-af22-9c977dec1a28
#nacos.config.server-addr=192.168.0.102:8848
#nacos.config.enabled=true
# Nacos registry address
#spring.application.name=provider

## Nacos registry address
#dubbo.registry.address=192.168.0.103:8848
# 注册中心
#dubbo.registry.id = dubboRegistry
#dubbo.registry.timeout=5000

#dubbo.registry.protocol=nacos
#dubbo.registry.address = 127.0.0.1:2181
#dubbo.registry.client = curator
#dubbo.registry.protocol=zookeeper

启动成功

调用方:  导入刚才的依赖,修改注册中心地址就可以了

<dubbo:registry address="nacos://自己的ip:8848" check="false"/>

启动:

 

好的,这里提供一个基于 Spring Cloud+Spring Boot+Nacos+Dubbo+mybatis plus+RocketMQ+Sentinel+Seata+mysql 的项目手脚架搭建步骤: 1. 首先需要搭建一个 Spring Cloud 项目,可以使用 Spring Initializr 快速创建。选择 Spring Boot 版本和其他依赖项,如 Eureka、Zuul、Config 等。 2. 集成 Nacos 作为注册中心和配置中心。在 pom.xml 中添加相关依赖项,并在 application.yml 中配置 Nacos 服务地址和相关配置。 3. 集成 Dubbo 作为 RPC 框架。在 pom.xml 中添加 DubboZookeeper 相关依赖项,并在 application.yml 中配置 Dubbo 的相关信息。 4. 集成 mybatis plus 作为 ORM 框架。在 pom.xml 中添加 mybatis plus 相关依赖项,并在 application.yml 中配置 mybatis plus 的相关信息。 5. 集成 RocketMQ 作为消息队列。在 pom.xml 中添加 RocketMQ 相关依赖项,并在 application.yml 中配置 RocketMQ 的相关信息。 6. 集成 Sentinel 作为流量控制和熔断降级框架。在 pom.xml 中添加 Sentinel 相关依赖项,并在 application.yml 中配置 Sentinel 的相关信息。 7. 集成 Seata 作为分布式事务框架。在 pom.xml 中添加 Seata 相关依赖项,并在 application.yml 中配置 Seata 的相关信息。 8. 集成 mysql 作为数据库。在 pom.xml 中添加 mysql 相关依赖项,并在 application.yml 中配置 mysql 的相关信息。 9. 编写业务代码,并在 Dubbo 接口上添加 @DubboService 注解,实现业务逻辑。在需要分布式事务的方法上添加 @GlobalTransactional 注解,实现分布式事务。 10. 在需要流量控制的方法上添加 @SentinelResource 注解,实现流量控制和熔断降级。 11. 在需要使用 RocketMQ 的地方,调用 RocketMQTemplate 发送消息,并编写监听器接收消息。 12. 在需要使用 Seata 的地方,调用 Seata 提供的 API 实现分布式事务。 以上是一个简单的搭建步骤,具体的细节还需要根据项目实际情况进行调整和优化。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值