兼职做页面的网站,m版网站开发,wordpress插件常用,部队网站建设建议目录 1.说明
2.示例
3.总结 1.说明
dubbo官网#xff1a;https://cn.dubbo.apache.org/zh-cn/
Apache Dubbo 是一款 RPC 服务开发框架#xff0c;用于解决微服务架构下的服务治理与通信问题#xff0c;支持多种语言#xff0c;官方提供了 Java、Golang 等多语言 SDK 实…目录 1.说明
2.示例
3.总结 1.说明
dubbo官网https://cn.dubbo.apache.org/zh-cn/
Apache Dubbo 是一款 RPC 服务开发框架用于解决微服务架构下的服务治理与通信问题支持多种语言官方提供了 Java、Golang 等多语言 SDK 实现。使用 Dubbo 开发的微服务原生具备相互之间的远程地址发现与通信能力 利用 Dubbo 提供的丰富服务治理特性可以实现诸如服务发现、负载均衡、流量调度等服务治理诉求。Dubbo 被设计为高度可扩展用户可以方便的实现流量拦截、选址的各种定制逻辑。
2.示例
实现说明 创建一个空项目在空项目中创建3个模块分别定义接口工程生产者工程及消费者工程。并在生产者工程及消费者工程中引入接口工程。 接口工程存放表的实体类及服务接口。 生产者工程提供服务接口的实现。 消费者工程调用服务接口。
实现步骤
①引入dubbo依赖 !-- Dubbo Spring Boot Starter --dependencygroupIdorg.apache.dubbo/groupIdartifactIddubbo-spring-boot-starter/artifactIdversion2.7.8/version/dependencydependency!--zookerper版本一定要匹配 --groupIdorg.apache.dubbo/groupIdartifactIddubbo-registry-zookeeper/artifactIdversion2.7.8/version/dependency ②在接口工程中创建接口
package com.example.service;public interface PrivoderService {String getInfo();
}③在生产者工程中实现接口并进行dubbo的配置
接口实现使用dbboservice注解将服务的实现暴露给dubbo
package com.example.provider.service.impl;import com.example.service.PrivoderService;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.stereotype.Service;/*** Author linaibo* Date 2023/11/18 15:28* Version 1.0*/
Service
DubboService
public class PrividerServiceImpl implements PrivoderService {Overridepublic String getInfo() {return 执行成功;}
}配置文件
server:port: 8881
dubbo:application:name: provider-service //dubbo的应用名registry:protocol: zookeeper //使用zookeeper作为服务的注册中心address: 127.0.0.1:2181 //zookeeper地址protocol:name: dubbo //使用dubbo协议port: 20885consumer:timeout: 60000 //调用接口的超时时间check: false //启动时不校验消费者是否已启动
spring:datasource:url: jdbc:mysql://localhost:3306/ry-vue?useUnicodetruecharacterEncodingutf8zeroDateTimeBehaviorconvertToNulluseSSLtrueserverTimezoneGMT%2B8username: rootpassword: 123456
mybatis:mapper-locations: classpath*:mapper/*Mapper.xmltype-aliases-package: com.**.domain
启动类配置添加EnableDubbo用于将dubbo相关的配置bean加载到spring容器
package com.example.provider;import org.apache.dubbo.config.spring.context.annotation.EnableDubbo;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;/*** Author linaibo* Date 2023/11/18 15:32* Version 1.0*/
SpringBootApplication
EnableDubbo
public class ProviderApplication {public static void main(String[] args) {SpringApplication.run(ProviderApplication.class, args);}
}④生产者工程中调用接口
调用使用DubboReference指定调用的服务
package com.example.consumer.service.impl;import com.example.consumer.service.ConsumerService;
import com.example.domain.AjaxResult;
import com.example.service.ISysConfigService;
import com.example.service.PrivoderService;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.stereotype.Service;import static com.example.domain.AjaxResult.success;/*** Author linaibo* Date 2023/11/18 15:56* Version 1.0*/
Service
public class ConsumerServiceImpl implements ConsumerService {DubboReferenceprivate PrivoderService privoderService;DubboReferenceprivate ISysConfigService sysConfigService;Overridepublic String getInfo() {String info privoderService.getInfo();return info;}Overridepublic AjaxResult getConfig(Long configId) {return success(sysConfigService.selectConfigById(configId));}
}配置文件及启动类配置和生产者工程一致
启动zookeeper服务及生产者工程及消费者工程就可以进行服务的调用。
3.总结
可以通过dubbo-admin进行服务的管理及查看。
dubbo.consumer.timeout调用超时时间毫秒默认为 1000。debug模式下会导致调用失败所以需要调大。
dubbo.consumer.check为true时开启服务启动时检查依赖的服务是否可用默认为 true。
也就是说生产者没有启动时消费者无法启动需要设置为false
参照SpringBoot整合dubbozooker搭建分布式服务超详细_springbootdubbo分布式项目-CSDN博客
SpringBoot项目集成Dubbo_springboot集成dubbo-CSDN博客