Springboot 2.x 整合Dubbo 2.6.x和Dubbo 2.7.x

Springboot 2.x 整合Dubbo 2.6.x和Dubbo 2.7.x,第1张

Dubbo有很长一段时间的发展史,2018年的时候不知道为什么阿里暂更了一年,之后又重新开始更新。之前一直是阿里在维护,后面阿里把它捐给了Apache基金会,由Apache来维护,26x之前,maven中的包名都是alibaba,270之后包名改成了apache,其中整合入系统中有一些差异;发展史:

Dubbo的原理什么的以及它的组成这里就不扯了,直接说说dubbo的项目结构吧。

基本的Dubbo项目组成分为三个部分:

接口层这里自定义了接口,实现部分由服务提供层来实现。建议将model也放在接口层中,接口层中对dubbo没有相关依赖,在这里pom就不提供了。

Java是商城系统开发的一种语言,java商城系统可分为前端和管理后台两部分,当中,前端主要是为顾客带来购物展示服务,后台是协助企业完成对整个商城的经营管理。通常java商城系统具备的基础作用包含产品管理、订单管理系统、门店管理、消息管理、会员管理、系统管理等,而作用有没有完善、实用、简便是对商城系统较大的考验。

易族智汇javashop商城系统开发有极严格的代码评审制度力争为客户提供精良的、方便二次开发的代码。

dubbo实现了分布式远程调用框架,多运行节点既能提高可靠性,又能提升负载能力。dubbo配置主要有注册中心(推荐zookeeper或redis)、提供者provider、消费者consumer,注册中心是第三方实现,所以主要配置好服务提供者和消费者就可以了。实际上服务接口和实现都是需要我们自己设计和实现的,dubbo做的事情就是将服务实现发布到注册中心,然后消费者从注册中心订阅服务接口,之后对接口的调用就由dubbo调度提供者去执行并返回结果。以下配置都有源码,见右侧“免费资源”。

提供者provider的配置:提供者是独立运行的节点,可以多实例运行,将服务注册到注册中心

必须要有application name,注册中心配置zookeeper,协议dubbo,超时6秒失败不重试,提供者加载repository和service层bean,然后发布接口service。

<dubbo:application name="ite-provider" />

<dubbo:registry address="zookeeper://127001:2181"/>

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

<dubbo:provider timeout="6000" retries="0"/>

<import resource="classpath:cachexml"/>

<import resource="classpath:ite-repositoryxml"/>

<import resource="classpath:ite-servicexml"/>

<import resource="classpath:ite-providerxml"/>

ite-providerxml,ref引用的bean是ite-servicexml已经定义好的接口实现,dubbo:service就是把接口实现发布到注册中心

<dubbo:service ref="codeListService" interface="comitecheastitedomainserviceCodeListService" />

<dubbo:service ref="idService" interface="comitecheastitedomainserviceIdService" />

<dubbo:service ref="passwordService" interface="comitecheastitedomainservicePasswordService" />

<dubbo:service ref="rolePermissionService" interface="comitecheastitedomainserviceRolePermissionService" />

provider是可以独立运行的,dubbojar里面有assembly目录,运行mvn assembly:directory就可以生成能直接运行的provider目录

assemblyxml内容,可以切换dir或targz两种格式

<assembly>

<id>assembly</id>

<formats>

<!-- <format>targz</format> -->

<format>dir</format>

</formats>

<includeBaseDirectory>true</includeBaseDirectory>

<fileSets>

<fileSet>

<directory>src/main/assembly/bin</directory>

<outputDirectory>bin</outputDirectory>

<fileMode>0755</fileMode>

</fileSet>

<fileSet>

<directory>src/main/assembly/conf</directory>

<outputDirectory>conf</outputDirectory>

<fileMode>0644</fileMode>

</fileSet>

<fileSet>

<directory>src/test/resources</directory>

<outputDirectory>conf</outputDirectory>

<fileMode>0644</fileMode>

</fileSet>

</fileSets>

<dependencySets>

<dependencySet>

<outputDirectory>lib</outputDirectory>

</dependencySet>

</dependencySets>

</assembly>

dubboproperties,运行startbat或startsh时,将从属性文件读取dubbo配置信息,provider节点可以多处复制并运行。

dubbocontainer=log4j,spring

dubboapplicationname=ite-provider

dubboregistryaddress=zookeeper://127001:2181

dubbomonitorprotocol=registry

dubboprotocolname=dubbo

dubboprotocolport=20880

dubbospringconfig=providerxml

dubbolog4jfile=logs/ite-providerlog

dubbolog4jlevel=WARN

消费者consumer的配置,使用dubbo:reference订阅注册中心里的服务即可,然后就可以@Autowired注入服务接口了。

<dubbo:application name="ite-consumer" />

<dubbo:registry address="zookeeper://127001:2181"/>

<dubbo:reference id="codeListService" interface="comitecheastitedomainserviceCodeListService" />

<dubbo:reference id="idService" interface="comitecheastitedomainserviceIdService" />

<dubbo:reference id="passwordService" interface="comitecheastitedomainservicePasswordService" />

<dubbo:reference id="rolePermissionService" interface="comitecheastitedomainserviceRolePermissionService" />

如果前端项目是一个消费者,就可以在webxml里直接加载consumerxml订阅服务了。

<listener>

<listener-class>orgspringframeworkwebcontextContextLoaderListener</listener-class>

</listener>

<context-param>

<param-name>contextConfigLocation</param-name>

<param-value>classpath:consumerxml,classpath:cachexml,classpath:shiroxml,classpath:frontxml</param-value>

</context-param>

实际上本地调试开发时,可以不必启用分布式配置,只需要更改webxml即可,所有的服务都已经是配置好了的。

<listener>

<listener-class>orgspringframeworkwebcontextContextLoaderListener</listener-class>

</listener>

<context-param>

<param-name>contextConfigLocation</param-name>

<param-value>classpath:ite-repositoryxml,classpath:ite-servicexml,classpath:cachexml,classpath:shiroxml,classpath:frontxml</param-value>

</context-param>

zookeeper的配置很简单,

wget >

以上就是关于Springboot 2.x 整合Dubbo 2.6.x和Dubbo 2.7.x全部的内容,包括:Springboot 2.x 整合Dubbo 2.6.x和Dubbo 2.7.x、java商城系统那个比较好、调用dubbo服务时事务配置在哪等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!

欢迎分享,转载请注明来源:聚客百科

原文地址: http://juke.outofmemory.cn/life/3657447.html

()
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-04-24
下一篇 2023-04-24

发表评论

登录后才能评论

评论列表(0条)

保存