Dubbo3.0 Demo

news2024/10/7 14:26:15

将SpringBoot工程集成Dubbo

1.创建父工程

在这里插入图片描述

2.创建子工程consumer,provider

在这里插入图片描述
在这里插入图片描述

3.初始化工程

在这里插入图片描述

4.引入依赖

在provider和consumer中引入dubbo依赖

        <dependency>
            <groupId>org.apache.dubbo</groupId>
            <artifactId>dubbo-spring-boot-starter</artifactId>
            <version>3.0.7</version>
        </dependency>
        <dependency>
            <groupId>org.apache.dubbo</groupId>
            <artifactId>dubbo-rpc-dubbo</artifactId>
            <version>3.0.7</version>
        </dependency>
        <dependency>
            <groupId>org.apache.dubbo</groupId>
            <artifactId>dubbo-registry-zookeeper</artifactId>
            <version>3.0.7</version>
        </dependency>

5.新建common模块

在这里插入图片描述
在common模块创建User类
User

@Data
@AllArgsConstructor
public class User implements Serializable {
    private String uid;
    private String username;
}

在common模块创建接口UserService

public interface UserService {
    public User getUser(String uid);
}

Provider

1.pom中添加依赖

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter</artifactId>
        </dependency>

        <dependency>
            <groupId>org.projectlombok</groupId>
            <artifactId>lombok</artifactId>
            <optional>true</optional>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>

        <dependency>
            <groupId>org.apache.dubbo</groupId>
            <artifactId>dubbo-spring-boot-starter</artifactId>
            <version>3.0.7</version>
        </dependency>
        <dependency>
            <groupId>org.apache.dubbo</groupId>
            <artifactId>dubbo-rpc-dubbo</artifactId>
            <version>3.0.7</version>
        </dependency>
        <dependency>
            <groupId>org.apache.dubbo</groupId>
            <artifactId>dubbo-registry-zookeeper</artifactId>
            <version>3.0.7</version>
        </dependency>
        <dependency>
            <groupId>com.hejiawang</groupId>
            <artifactId>common</artifactId>
            <version>0.0.1-SNAPSHOT</version>
            <scope>compile</scope>
        </dependency>

2.添加UserServiceImpl

使用@DubboService并且指定版本

@DubboService(version = "1.0")
public class UserServiceImpl implements UserService {
    public User getUser(String uid){
        User hejiawang = new User(uid,"hejiawang");
        return hejiawang;
    }
}

3.添加UserServiceImpl2

使用@DubboService并且指定版本

@DubboService(version = "2.0")
public class UserServiceImpl2 implements UserService {
    public User getUser(String uid){
        User hejiawang = new User(uid,"hejiawang");
        return hejiawang;
    }
}

4.在启动类中添加@EnableDubbo

@SpringBootApplication
@EnableDubbo
public class ConsumerApplication {

	public static void main(String[] args) {
		SpringApplication.run(ConsumerApplication.class, args);
	}

}

Consumer

1.pom中添加依赖

		<dependency>
			<groupId>org.apache.dubbo</groupId>
			<artifactId>dubbo-spring-boot-starter</artifactId>
			<version>3.0.7</version>
		</dependency>
		<dependency>
			<groupId>org.apache.dubbo</groupId>
			<artifactId>dubbo-rpc-dubbo</artifactId>
			<version>3.0.7</version>
		</dependency>
		<dependency>
			<groupId>org.apache.dubbo</groupId>
			<artifactId>dubbo-registry-zookeeper</artifactId>
			<version>3.0.7</version>
		</dependency>
		<dependency>
			<groupId>com.hejiawang</groupId>
			<artifactId>common</artifactId>
			<version>0.0.1-SNAPSHOT</version>
			<scope>compile</scope>
		</dependency>

2.添加OrderService

OrderService

@Service
public class OrderService {
    @DubboReference(version = "1.0")
    private UserService userService;

    public User getOrderService(String uid){
        return userService.getUser(uid);
    }
}

3.添加OrderController

OrderController

@RestController
public class OrderController {
    @Autowired
    OrderService orderService;

    @GetMapping("/user/{uid}")
    public User getUser(@PathVariable("uid") String uid) {
        return orderService.getOrderService(uid);

    }
}

4.启动类添加@EnableDubbo

@SpringBootApplication
@EnableDubbo
public class ConsumerApplication {

	public static void main(String[] args) {
		SpringApplication.run(ConsumerApplication.class, args);
	}

}

测试

1.启动本地zk

在这里插入图片描述

2.启动provider,consumer

在这里插入图片描述

3.调用consumer服务的controller

localhost:8081/user/123

通过dubbo返回结果
在这里插入图片描述

4.通过zkweb查看provider UserService有2个版本并且1.0版本有消费者

在这里插入图片描述

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.coloradmin.cn/o/856837.html

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈,一经查实,立即删除!

相关文章

文心一言 VS 讯飞星火 VS chatgpt (73)-- 算法导论7.1 4题

四、如何修改 QUICKSORT&#xff0c;使得它能够以非递增序进行排序? 文心一言&#xff1a; 快速排序&#xff08;Quicksort&#xff09;是一种常用的排序算法&#xff0c;基于分治策略进行设计。默认情况下&#xff0c;快速排序会以递增序进行排序。若想修改快速排序以实现非…

基于星火和Gradio的聊天机器人

星火大模型官网&#xff1a;https://xinghuo.xfyun.cn/ 1 创建虚拟环境&#xff08;windows&#xff09; conda create -n Gradio python3.8 pip install gradio 中间遇到os报错&#xff0c;解决方案&#xff1a; pip install aiofiles23.2.1 2 代码 SparkDesk.py&#xff1a…

Android Studio跳过Haxm打开模拟器

由于公司权限限制无法安装Haxm&#xff0c;这个时候我们可以试试Arm相关的镜像去跳过Haxm运行模拟器。解决方案&#xff1a;安装API27以下的Arm Image. #ifdef __x86_64__if (sarch "arm64" && apiLevel >28) {APANIC("Avds CPU Architecture %s i…

linux_常用命令

一、日常使用命令/常用快捷键命令 开关机命令 1、shutdown –h now&#xff1a;立刻进行关机 2、shutdown –r now&#xff1a;现在重新启动计算机 3、reboot&#xff1a;现在重新启动计算机 4、su -&#xff1a;切换用户&#xff1b;passwd&#xff1a;修改用户密码 5、logou…

使用IIS服务器部署Flask python Web项目

参考文章 ""D:\Program Files (x86)\Python310\python310.exe"|"D:\Program Files (x86)\Python310\lib\site-packages\wfastcgi.py"" can now be used as a FastCGI script processor参考文章 请求路径填写*&#xff0c;模块选择FastCgiModule&…

web-xss-dvwa

目录 xss&#xff08;reflected&#xff09; low medium high xss(store) low medium high xss(dom) low medium high xss&#xff08;reflected&#xff09; low 没有什么过滤&#xff0c;直接用最普通的标签就可以了 http://127.0.0.1/DVWA-master/vulnerabili…

【神经网络手写数字识别-最全源码(pytorch)】

Torch安装的方法 学习方法 1.边用边学&#xff0c;torch只是一个工具&#xff0c;真正用&#xff0c;查的过程才是学习的过程2.直接就上案例就行&#xff0c;先来跑&#xff0c;遇到什么来解决什么 Mnist分类任务&#xff1a; 网络基本构建与训练方法&#xff0c;常用函数解析…

【C语言】数据在内存中的存储详解

文章目录 一、什么是数据类型二、类型的基本归类三、 整型在内存中的存储1.原码、反码、补码2.大小端(1)什么是大小端(2)为什么会有大小端 四、浮点型在内存中的存储1. 浮点数存储规则 五、练习1.2.3.4.5.6.7. 一、什么是数据类型 我们可以把数据类型想象为一个矩形盒子&#x…

DCMM数据管理成熟度之数据战略-数据战略规划

需要咨询加 &#xff1a;shuirunjj 标准原文 1概述 数据战略规划是在所有利益相关者之间达成共识的结果。从宏观及微观两个层面确定开展数据管理及应用的动因,并综合反映数据提供方和消费方的需求。 2 过程描述 过程描述如下: a) 识别利益相关者,明确利益相关者的需求; …

人机融合智能可化简为遥控+预先规划+重新规划过程

人机融合智能可以被简单描述为人类的遥控、机器的预先规划以及人-机器共同的动态重新规划的过程。 首先&#xff0c;人类的遥控是指人类通过指令、控制和操作来操纵机器的行为和功能。人类可以利用各种界面和输入设备&#xff0c;如键盘、鼠标、触摸屏等&#xff0c;将自己的意…

Python做一个绘图系统3:从文本文件导入数据并绘图

文章目录 导入数据文件对话框修改绘图逻辑源代码 Python绘图系统系列&#xff1a;将matplotlib嵌入到tkinter 简单的绘图系统 导入数据 单纯从作图的角度来说&#xff0c;更多情况是已经有了一组数据&#xff0c;然后需要将其绘制。这组数据可能是txt格式的&#xff0c;也可能…

HashMap的put方法流程

首先根据key的值计算hash值&#xff0c;找到该元素在数组中存储的下标如果数组是空的&#xff0c;则调用resize进行初始化&#xff1b;如果没有哈希冲突直接放在对应的数组下标里如果冲突了&#xff0c;且key已经存在&#xff0c;就覆盖掉value如果冲突后是链表结构&#xff0c…

Android Studio实现刮刮卡效果

代码和刮刮乐图片参考网络 实现效果 MainActivity import android.app.Activity; import android.os.Bundle;public class MainActivity extends Activity {Overrideprotected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentVi…

汽车控制器底层软件BOOTLOADER开发经历

现在所谓智能汽车必备的OTA技术&#xff0c;在ECU控制器层面就是BOOT的开发&#xff0c;对应autosar体系里面的BSW基础软件。 同学刚开始接触汽车软件开发会有一种思想&#xff0c;要学就学听起来high level的autosar&#xff0c;但是到底autosar是个什么东西也搞不懂&#xf…

基于数据全生命周期的数据资产价值评估方法及应用

基于数据全生命周期的数据资产价值评估方法及应用 李冬青, 刘吟啸, 邓镭, 李铭洋 阿里巴巴集团&#xff0c;上海 200120 摘要&#xff1a;数据资产价值评估是现代数据资产管理和运营以及数据流通的基础。基于数据全生命周期理论&#xff0c;从第一性原则出发&#xff0c;通过评…

2023好用苹果电脑杀毒软件Cleanmymac X

苹果电脑怎么杀毒&#xff1f;这个问题自从苹果电脑变得越来越普及&#xff0c;苹果电脑的安全性问题也逐渐成为我们关注的焦点。虽然苹果电脑的安全性相对较高&#xff0c;但仍然存在着一些潜在的威胁&#xff0c;比如流氓软件窥探隐私和恶意软件等。那么&#xff0c;苹果电脑…

Day 25 C++ stack容器(栈)

文章目录 stack 基本概念定义基本概念栈顶&#xff08;Top&#xff09;——指向栈中最上面的元素的位置。入栈&#xff08;Push&#xff09;——将元素添加到栈顶。出栈&#xff08;Pop&#xff09;——从栈顶移除元素。栈空&#xff08;Empty&#xff09;——当栈中没有任何元…

企业权限管理(三)-产品添加

产品添加 从product-list.jsp跳转到product-add.jsp <button type"button" class"btn btn-default" title"新建" onclick"location.href${pageContext.request.contextPath}/pages/product-add.jsp"><iclass"fa fa-file…

后端开发9.商品类型模块

概述 简介 商品类型我设计的复杂了点,设计了多级类型 效果图 数据库设计

ORACLE和MYSQL区别

1&#xff0c;Oracle没有offet,limit&#xff0c;在mysql中我们用它们来控制显示的行数&#xff0c;最多的是分页了。oracle要分页的话&#xff0c;要换成rownum。 2&#xff0c;oracle建表时&#xff0c;没有auto_increment&#xff0c;所有要想让表的一个字段自增&#xff0c…