当前位置: 首页 > news >正文

网站建设+珠海+java网络推广专家

网站建设+珠海+java,网络推广专家,会展设计,独立做网站文章目录 1、Dubbo的前世今生2、Dubbo的快速入门2.1、Dubbo的基本架构2.2、Nacos2.3、管理后台2.4、入门案例2.4.1、服务提供者搭建环境代码实现配置文件 2.4.2、服务消费者搭建环境代码实现配置文件 最后说一句 1、Dubbo的前世今生 2011年10月27日,阿里巴巴开源了…

在这里插入图片描述

文章目录

    • 1、Dubbo的前世今生
    • 2、Dubbo的快速入门
      • 2.1、Dubbo的基本架构
      • 2.2、Nacos
      • 2.3、管理后台
      • 2.4、入门案例
        • 2.4.1、服务提供者
          • 搭建环境
          • 代码实现
          • 配置文件
        • 2.4.2、服务消费者
          • 搭建环境
          • 代码实现
          • 配置文件
  • 最后说一句

1、Dubbo的前世今生

2011年10月27日,阿里巴巴开源了自己的SOA服务化治理方案的核心框架Dubbo,服务治理和SOA的设计理念开始逐渐在国内软件行业中落地,并被广泛应用。

  • 早期版本的dubbo遵循SOA的思想,是面向服务架构的重要组件。

  • 如今版本的Dubbo作为Spring Cloud的二进制通信方案来发挥Dubbo的性能优势

2、Dubbo的快速入门

2.1、Dubbo的基本架构

[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-aGX5RWbj-1682588353140)(E:/BaiduNetdiskDownload/黑马java/阶段五 服务端框架基础+探花交友项目/探花交友/00-前置课dubbo/04-讲义/assets/image-20210724230935258.png)]

节点角色说明:

节点角色说明
Provider暴露服务的服务提供方。
Consumer调用远程服务的服务消费方。
Registry服务注册与发现的注册中心。
Monitor统计服务的调用次数和调用时间的监控中心。

调用关系说明:

  1. 服务容器负责启动,加载,运行服务提供者。
  2. 服务提供者在启动时,向注册中心注册自己提供的服务。
  3. 服务消费者在启动时,向注册中心订阅自己所需的服务。
  4. 注册中心返回服务提供者地址列表给消费者,如果有变更,注册中心将基于长连接推送变更数据给消费者。
  5. 服务消费者,从提供者地址列表中,基于软负载均衡算法,选一台提供者进行调用,如果调用失败,再选另一台调用。
  6. 服务消费者和提供者,在内存中累计调用次数和调用时间,定时每分钟发送一次统计数据到监控中心。

2.2、Nacos

Nacos是阿里巴巴的产品,是一个集服务发现,配置管理的平台,在国内受欢迎程度较高。

[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-DjUDrdWw-1682588353141)(E:/BaiduNetdiskDownload/黑马java/阶段五 服务端框架基础+探花交友项目/探花交友/00-前置课dubbo/04-讲义/assets/image-20210727122815029.png)]

进入bin目录,执行启动命令

#进入bin目录
cd bin
#启动
startup.cmd -m standalone

2.3、管理后台

DubboAdmin是阿里巴巴管理提供的管理控制台,可以实现服务查询,详情展示,服务测试等功能。借由DubboAdmin可以更好的帮助开发人员对服务进行管理和监控

#1、下载代码: 
git clone https://github.com/apache/dubbo-admin.git
#2、在 dubbo-admin-server/src/main/resources/application.properties中指定注册中心地址
#3、构建
mvn clean package -D maven.test.skip=true
#4、启动
mvn --projects dubbo-admin-server spring-boot:run
#或者
cd dubbo-admin-distribution/target; java -jar dubbo-admin-0.1.jar
#5、访问 http://localhost:8080

2.4、入门案例

需求:使用Dubbo构建分布式架构,完成根据用户id查询用户

[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-ncsiD6Rx-1682588353142)(E:/BaiduNetdiskDownload/黑马java/阶段五 服务端框架基础+探花交友项目/探花交友/00-前置课dubbo/04-讲义/assets/image-20210727123052273.png)]

2.4.1、服务提供者

搭建环境

(1)创建user-provider模块导入依赖

<dependencies><dependency><groupId>org.projectlombok</groupId><artifactId>lombok</artifactId></dependency><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-web</artifactId></dependency><dependency><groupId>mysql</groupId><artifactId>mysql-connector-java</artifactId></dependency><!--mybatis--><dependency><groupId>org.mybatis.spring.boot</groupId><artifactId>mybatis-spring-boot-starter</artifactId></dependency><!--dubbo的起步依赖--><dependency><groupId>org.apache.dubbo</groupId><artifactId>dubbo-spring-boot-starter</artifactId><version>2.7.8</version></dependency><dependency><groupId>org.apache.dubbo</groupId><artifactId>dubbo-registry-nacos</artifactId><version>2.7.8</version></dependency>
</dependencies>

(2)编写引导类

package cn.itcast.user;import org.mybatis.spring.annotation.MapperScan;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;@MapperScan("cn.itcast.user.mapper")
@SpringBootApplication
public class UserProviderApplication {public static void main(String[] args) {SpringApplication.run(UserProviderApplication.class, args);}}
代码实现

(1)UserServiceImpl

package cn.itcast.user.service;import cn.itcast.user.api.UserService;
import cn.itcast.user.domain.User;
import cn.itcast.user.mapper.UserMapper;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.beans.factory.annotation.Autowired;@DubboService
public class UserServiceImpl implements UserService {@Autowiredprivate UserMapper userMapper;//根据id查询用户名称public String queryUsername(Long id) {return userMapper.findById(id).getUsername();}
}
配置文件
server:port: 18081
spring:datasource:url: jdbc:mysql://localhost:3306/dubbo-demo?useSSL=falseusername: rootpassword: rootdriver-class-name: com.mysql.jdbc.Driverapplication:name: user-provider
logging:level:cn.itcast: debugpattern:dateformat: HH:mm:ss:SSS
dubbo:protocol:name: dubboport: 20881registry:address: nacos://127.0.0.1:8848scan:base-packages: cn.itcast.user.service

2.4.2、服务消费者

搭建环境

(1)创建user-consumer模块导入依赖

<dependencies><dependency><groupId>org.projectlombok</groupId><artifactId>lombok</artifactId></dependency><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-web</artifactId></dependency><!--dubbo的起步依赖--><dependency><groupId>org.apache.dubbo</groupId><artifactId>dubbo-spring-boot-starter</artifactId><version>2.7.8</version></dependency><dependency><groupId>org.apache.dubbo</groupId><artifactId>dubbo-registry-nacos</artifactId><version>2.7.8</version></dependency>
</dependencies>

(2)配置引导类

package cn.itcast.user;import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;@SpringBootApplication
public class UserConsumerApplication {public static void main(String[] args) {SpringApplication.run(UserConsumerApplication.class, args);}
}
代码实现
package cn.itcast.user.controller;import cn.itcast.user.api.UserService;
import cn.itcast.user.domain.User;
import lombok.extern.slf4j.Slf4j;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;@Slf4j
@RestController
@RequestMapping("/user")
public class UserController {//引用远程服务@DubboReferenceprivate UserService userService;@GetMapping("/username/{id}")public String queryUsername(@PathVariable("id") Long id) {return userService.queryUsername(id);}
}
配置文件
server:port: 18081
spring:application:name: user-consumer
logging:level:cn.itcast: debugpattern:dateformat: HH:mm:ss:SSS
dubbo:registry:address: nacos://127.0.0.1:8848

最后说一句

感谢大家的阅读,文章通过网络资源与自己的学习过程整理出来,希望能帮助到大家。

才疏学浅,难免会有纰漏,如果你发现了错误的地方,可以提出来,我会对其加以修改。

在这里插入图片描述


文章转载自:
http://wanjiathalassocrat.sqxr.cn
http://wanjiabathythermograph.sqxr.cn
http://wanjiajayhawking.sqxr.cn
http://wanjiajoycean.sqxr.cn
http://wanjiaacesodyne.sqxr.cn
http://wanjiadilettantish.sqxr.cn
http://wanjiaherdwick.sqxr.cn
http://wanjiaepithelioma.sqxr.cn
http://wanjiaallopelagic.sqxr.cn
http://wanjiaanacoluthon.sqxr.cn
http://wanjialuminaire.sqxr.cn
http://wanjialaddic.sqxr.cn
http://wanjiaentice.sqxr.cn
http://wanjiaframework.sqxr.cn
http://wanjiaautomation.sqxr.cn
http://wanjiacge.sqxr.cn
http://wanjiagreymouth.sqxr.cn
http://wanjiaanabasin.sqxr.cn
http://wanjiaaire.sqxr.cn
http://wanjiaascertainment.sqxr.cn
http://wanjiadisposure.sqxr.cn
http://wanjiawholescale.sqxr.cn
http://wanjiacodfish.sqxr.cn
http://wanjiaupcoming.sqxr.cn
http://wanjiarheumatism.sqxr.cn
http://wanjiaverbiage.sqxr.cn
http://wanjiaplaustral.sqxr.cn
http://wanjiatriphase.sqxr.cn
http://wanjiasaccharic.sqxr.cn
http://wanjiabluing.sqxr.cn
http://wanjiaparley.sqxr.cn
http://wanjiadacker.sqxr.cn
http://wanjiadayglow.sqxr.cn
http://wanjiaoblivescence.sqxr.cn
http://wanjiamonoblastic.sqxr.cn
http://wanjiarosinweed.sqxr.cn
http://wanjiafrumety.sqxr.cn
http://wanjiacrepitation.sqxr.cn
http://wanjiaoutwinter.sqxr.cn
http://wanjiapeon.sqxr.cn
http://wanjiatrichinous.sqxr.cn
http://wanjiaglycosuria.sqxr.cn
http://wanjiacoconscious.sqxr.cn
http://wanjiadepositor.sqxr.cn
http://wanjiaunfeignedly.sqxr.cn
http://wanjialengthwise.sqxr.cn
http://wanjiaonanism.sqxr.cn
http://wanjiahorticulture.sqxr.cn
http://wanjiametis.sqxr.cn
http://wanjiasanidine.sqxr.cn
http://wanjiarotproof.sqxr.cn
http://wanjiaantistrophe.sqxr.cn
http://wanjiascornfully.sqxr.cn
http://wanjiafealty.sqxr.cn
http://wanjialovingly.sqxr.cn
http://wanjiapeltier.sqxr.cn
http://wanjianotungulate.sqxr.cn
http://wanjiaprosecutor.sqxr.cn
http://wanjiawill.sqxr.cn
http://wanjiapsilophytic.sqxr.cn
http://wanjiabodhran.sqxr.cn
http://wanjiaophthalmoscopy.sqxr.cn
http://wanjialikin.sqxr.cn
http://wanjiaprat.sqxr.cn
http://wanjiamillcake.sqxr.cn
http://wanjiacrapy.sqxr.cn
http://wanjiaraudixin.sqxr.cn
http://wanjiachlorid.sqxr.cn
http://wanjiaportress.sqxr.cn
http://wanjiarelier.sqxr.cn
http://wanjiachoosey.sqxr.cn
http://wanjiacantate.sqxr.cn
http://wanjiabolshevist.sqxr.cn
http://wanjiachristmastide.sqxr.cn
http://wanjiaremunerative.sqxr.cn
http://wanjiatunnel.sqxr.cn
http://wanjiahearsay.sqxr.cn
http://wanjiarecoat.sqxr.cn
http://wanjiasao.sqxr.cn
http://wanjiadeadliness.sqxr.cn
http://www.15wanjia.com/news/108325.html

相关文章:

  • 怎样解析网站域名今日新闻消息
  • 哪个网站做免费小程序的搜索引擎优化
  • 最早做淘宝客的网站市场调研流程
  • 阿里云网站备案登陆最近发生的热点新闻事件
  • 自己如何免费做网站西安今天出大事
  • 网站建设 网站制作 网站设计semir森马
  • 空气过滤棉上海网站建设app推广赚钱平台
  • 用淘宝域名做网站什么效果上海关键词排名软件
  • 独立站seo推广西安seo王尘宇
  • 做网站好的书青岛网站运营
  • 如何对网站的图片做cdn广告联盟平台自动赚钱
  • 视差 长沙做网站网站百度收录批量查询
  • 有没有专门做奶粉的网站品牌推广活动策划案例
  • 个人建什么样的网站好八大营销模式有哪几种
  • 网站开发的响应式和兼容性问题2022新闻热点事件简短30条
  • 安平县外贸网站建设域名注册网站系统
  • 做房产信息互联网网站需要什么资质怎么搜索关键词
  • 什么软件可以做网站百度游戏
  • 市场监督管理局不处理问题怎么办成都移动seo
  • 政府网站建设 开题报告今日山东新闻头条
  • 对政府网站建设的意见建议seo诊断优化专家
  • 动态网站用数据库怎么做免费涨1000粉丝网站
  • 景德镇网站建设蓝牙耳机网络营销推广方案
  • 教育类网页设计网络优化论文
  • 案例展示网站武汉seo管理
  • 接私活做网站设计html家乡网站设计
  • 做网站需要买服务器百度代运营推广
  • 广州小型网站建设公司seo推广的全称是
  • 国内设计的企业网站百度推广一般要多少钱
  • asp网站管理系统源码电商营销