Spring Cloud Alibaba【创建支付服务生产者、创建服务消费者 、Dubbo和OpenFeign区别 、微服务接入OpenFeign】(二)

news2024/10/7 16:16:06

 

目录

分布式服务治理_创建支付服务生产者

分布式服务治理_创建服务消费者 

服务调用_Dubbo和OpenFeign区别 

服务调用_微服务接入OpenFeign


分布式服务治理_创建支付服务生产者

创建服务提供者工程cloud-provider-payment8001 

POM文件引入依赖 

<dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-actuator</artifactId>
        </dependency>
        <dependency>
            <groupId>com.alibaba.cloud</groupId>
            <artifactId>spring-cloud-starter-alibaba-nacos-discovery</artifactId>
        </dependency>
        <dependency>
            <groupId>org.projectlombok</groupId>
            <artifactId>lombok</artifactId>
        </dependency>
    </dependencies>

编写主启动类

@Slf4j
//注解开启服务注册与发现功能
@EnableDiscoveryClient
@SpringBootApplication
public class PaymentMain8001 {
    public static void main(String[] args) {
       SpringApplication.run(PaymentMain8001.class,args);
        log.info("************PaymentMain8001 启动成功 ********");
   }
}

注意: @EnableDiscoveryClient:开启注册发现服务

编写YML配置文件 

server:
 port: 8001
spring:
 application:
    # 微服务名字
   name: provider-payment
 cloud:
   nacos:
     discovery:
        # Nacos服务地址
       server-addr: 192.168.66.101:8848

查看Nacos控制台服务

分布式服务治理_创建服务消费者 

创建服务提供者工程cloud-consumer-order80 

POM文件引入依赖 

  <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-actuator</artifactId>
        </dependency>
        <dependency>
            <groupId>com.alibaba.cloud</groupId>
            <artifactId>spring-cloud-starter-alibaba-nacos-discovery</artifactId>
        </dependency>
        <dependency>
            <groupId>org.projectlombok</groupId>
            <artifactId>lombok</artifactId>
        </dependency>
    </dependencies>

编写主启动类

@SpringBootApplication
@Slf4j
@EnableDiscoveryClient
public class OrderMain80 {
    public static void main(String[] args) {
        SpringApplication.run(OrderMain80.class,args);
        log.info("************ OrderMain80 启动成功 ********");
   }
}

编写YML配置文件

server:
 port: 80
spring:
 application:
    # 微服务名字
   name: consumer-order
 cloud:
   nacos:
     discovery:
        # Nacos服务地址
       server-addr: 192.168.66.101:8848

查看Nacos控制台服务

服务调用_Dubbo和OpenFeign区别 

回顾Dubbo 

Apache Dubbo 是一款微服务开发框架,它提供了 RPC通信与微服务治理两大关键能力。这意味着,使用 Dubbo 开发的微服务,将具备相互之间的远程发现与通信能力, 同时利用 Dubbo 提供的丰富服务治理能力,可以实现诸如服务发现、负载均衡、流量调度等服务治理诉求。

通信性能方面 

从通信的性能上来分析,SpringCloud的通信采用Openfeign (feign)组件。Feign基于Http传输协议,底层实现是Rest。从OSI 7层模型上来看Rest属于应用层。

注意:在高并发场景下性能不够理想,成为性能瓶颈。

Dubbo框架的通信协议采用RPC协议,属于传输层协议,性能上自然比rest高。提升了交互的性 能,保持了长连接,高性能。 

注意: Dubbo性能更好,比如支持异步调用、Netty性能更好。 

 

 

实时效果反馈

1.OpenFeign底层是Feign采用___协议。

A RPC

B HTTP 

C TCP

D 以上都错误

2. Dubbo框架的通信协议采用RPC协议,属于___协议。

A 应用层

B 传输层

C 会话层

D 以上都是错误

服务调用_微服务接入OpenFeign

创建工程cloud-consumer-openfeign-order80 

添加OpenFeign依赖 

   <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-actuator</artifactId>
        </dependency>
        <dependency>
            <groupId>com.alibaba.cloud</groupId>
            <artifactId>spring-cloud-starter-alibaba-nacos-discovery</artifactId>
        </dependency>
        <dependency>
            <groupId>org.projectlombok</groupId>
            <artifactId>lombok</artifactId>
        </dependency>
        <!-- openfeign -->
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-openfeign</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-loadbalancer</artifactId>
        </dependency>
    </dependencies>

主启动类添加feign注解

@EnableFeignClients
@SpringBootApplication
@Slf4j
@EnableDiscoveryClient
public class OrderOpenFeign80 {
    public static void main(String[] args) {
       SpringApplication.run(OrderOpenFeign80.class,args);
        log.info("*************OrderOpenFeign80 启动成功 ********");
   }
}

创建YML配置文件

server:
 port: 80
spring:
 application:
    # 微服务名字
   name: consumer-order
 cloud:
   nacos:
     discovery:
        # Nacos服务地址
       server-addr: 192.168.66.101:8848
feign:
 client:
   config:
     default:
        # ⽹络连接阶段1秒超时 7
       connectTimeout: 1000
        # 服务请求响应阶段2秒超时
       readTimeout: 2000

创建要调用的的微服务接口

@Service
@FeignClient(value = "provider-payment",fallback = TemplateServiceFallback.class)
public interface PaymentService {
    @GetMapping("/payment/index")
    String index();
}

创建控制层

/**
* 订单控制层
*/
@RestController
@RequestMapping("order")
public class OrderController {
   @Autowired
    private PaymentService paymentService;
    /**
     * 测试OpenFeign
     * @return
     */
    @GetMapping("index")
    public String index(){
        return paymentService.index();
   }
}

测试

请求http://192.168.66.101:80/order/index

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

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

相关文章

MP4怎么转换为gif的格式?快试试这两个方法!

想要将MP4视频文件转换为GIF格式&#xff1f;不用担心&#xff0c;本文将为您介绍两种简单易行的方法&#xff1a;记灵在线工具和使用FFmpeg命令行工具。这些方法适用于不同的用户&#xff0c;无论您是喜欢在线工具还是偏向命令行操作&#xff0c;都能找到适合自己的方式。让我…

开源代码分享(8)—大规模电动汽车时空耦合双层优化调度(附matlab代码)

参考文献&#xff1a; [1]He L , Yang J , Yan J , et al. A bi-layer optimization based temporal and spatial scheduling for large-scale electric vehicles[J]. Applied Energy, 2016, 168(apr.15):179-192. DOI:10.1016/j.apenergy.2016.01.089 1.基本原理 1.1摘要 电…

Python模块基础

一、模块 模块可以看成是一堆函数的集合体。 一个py文件内部就可以放一堆函数&#xff0c;因此一个py文件就可以看成一个模块。 如果这个py文件的文件名为module.py&#xff0c;模块名则是module。 1、模块的四种形式 在Python中&#xff0c;总共有以下四种形式的模块&…

MySQL约束和查询

约束和查询 1. 约束1.1 约束类型1.2 常用的约束 2. 查询2.1 聚合查询2.1.1 聚合函数2.1.2 GROUP BY2.1.3 HAVING 2.2 联合查询2.2.1 内连接2.2.2 外连接 2.3 合并查询 1. 约束 1.1 约束类型 NOT NULL - 指示某列不能存储 NULL 值。UNIQUE - 保证某列的每行必须有唯一的值。DE…

TCP四次挥手过程

TCP 断开连接是通过四次挥手方式。 双方都可以主动断开连接&#xff0c;断开连接后主机中的「资源」将被释放&#xff0c; 刚开始双方都处于 establised 状态&#xff0c;假如是客户端先发起关闭请求&#xff0c;过程如下图&#xff1a; 第一次挥手&#xff1a;客户端打算关闭…

C++模拟实现位图和布隆过滤器(哈希)

目录 前言引入&#xff1a; 一、位图 1.1 位图概念 1.2 位图的实现 1.3 位图的应用 二、布隆过滤器 2.1 哈希的弊端 2.2 布隆过滤器概念 2.3 布隆过滤器的插入 2.4 布隆过滤器的查找 2.5 布隆过滤器的删除 2.6 布隆过滤器的模拟实现 2.7 布隆过滤器优缺点 三、…

CSS ::file-selector-button伪元素修改input上传文件按钮的样式

默认样式 修改后的样式 <!DOCTYPE html> <html lang"en"> <head><meta charset"UTF-8"><meta http-equiv"X-UA-Compatible" content"IEedge"><meta name"viewport" content"widthdev…

HTTP 请求走私漏洞(HTTP Request Smuggling)

一、什么是Http 请求走私漏洞&#xff1f; HTTP请求走私漏洞&#xff08;HTTP Request Smuggling&#xff09;是一种安全漏洞&#xff0c;利用了HTTP协议中请求和响应的解析和处理方式的不一致性。攻击者通过构造特定的恶意请求&#xff0c;以欺骗服务器和代理服务器&#xff0…

微信小程序-地图上的图标计算旋转值朝向经纬度计算

废话不多说&#xff0c;开整 // 参数为寄件人经纬度和收件人经纬度 // 根据寄收件人经纬度弧度π进行rotate旋转计算 const getRotate (po1, po2) > {if (!(po1 && po2)) return 0const lng_a po1.longitudeconst lat_a po1.latitudeconst lng_b po2.longitud…

pg谓词下推分析(一)

谓词下推分析&#xff08;一&#xff09; 本文基于pg13.8。 谓词下推阶段即是把约束条件下推对条件涉及的表上&#xff08;RelOptlnfo&#xff09;&#xff0c;其中同时会涉及到等价类的推导&#xff0c;及建立逻辑连接关系&#xff08;外连接的SpecialJoinInfo结构的创建与设…

apple pencil二代平替笔哪个好用?苹果平板平替笔排行

光是一款Apple Pencil&#xff0c;就卖到了接近一千多块&#xff0c;信息对于很多人来说都觉得太贵了。事实上&#xff0c;由于平替电容笔的性价比也非常高&#xff0c;因此它还是值得一试的。不管是学习&#xff0c;写作&#xff0c;还是绘画&#xff0c;这支平替电容笔&#…

力扣 135. 分发糖果

题目来源&#xff1a;https://leetcode.cn/problems/candy/description/ C题解&#xff08;来源代码随想录&#xff09;&#xff1a; 先从左往右比较&#xff0c;右边孩子评分比左边高就多发1颗糖&#xff0c;否则就只发1颗&#xff1b;再从右往左比较&#xff0c;左边孩子评分…

Element ui table展开行中,某些行需要展开,某些行不需要展开

1.templatetemplate里面对应的代码&#xff1a; <el-table :data"menuList" style"width: 100%" :row-class-name"isShowIcon"><el-table-column type"expand"><template slot-scope"props" v-if"prop…

阿里云GPU服务器使用教程_创建_连接_GPU驱动_实践教程

阿里云GPU服务器怎么使用&#xff1f;先创建GPU实例、GPU云服务器远程连接&#xff0c;为GPU云服务器安装GPU驱动、安装GRID驱动等&#xff0c;使用GPU服务器部署NGC环境、GPU AI模型训练教程、在GPU实例上使用RAPIDS加速机器学习任务、RAPIDS加速机器学习等使用教程&#xff0…

AI代码生成能力进一步提高,网友:程序员饭碗保不住了?

文章内容来源于公众号——布博士&#xff08;擎创科技资深产品专家&#xff09; 自chatGPT出现以来&#xff0c;人工智能&#xff08;AI&#xff09;迅速发展成为科技行业的重要领域。人工智能已应用于医疗、金融、交通、农业等各个领域。人工智能代码生成的进步提高了软件开发…

Ingress:集群进出流量的总管

Service 很有用&#xff0c;但也只能说是“基础设施”&#xff0c;它对网络流量的管理方案还是太简单&#xff0c;离复杂的现代应用架构需求还有很大的差距&#xff0c;所以 Kubernetes 就在 Service 之上又提出了一个新的概念&#xff1a;Ingress。 Service 还有一个缺点&…

el-dialog 添加loading;avue-form 表单插槽

效果: 第一步&#xff1a;custom-class"publishDialog" 新起一个类名 <el-dialog title"发布配置" custom-class"publishDialog" :visible.sync"publishDialogVisible" width"800px" :append-to-body"true":b…

【电路效应】信号处理和通信系统模型中的模拟电路效应研究(SimulinkMatlab代码实现)

目录 &#x1f4a5;1 概述 &#x1f4da;2 运行结果 &#x1f389;3 参考文献 &#x1f308;4 Matlab代码、Simulink仿真实现 &#x1f4a5;1 概述 在信号处理和通信系统模型中&#xff0c;模拟电路效应研究是指考虑到实际电路的特性对信号进行建模和分析的过程。模拟电路效应…

C++中main()函数和命令行参数介绍

C中main()函数和命令行参数介绍 在C中&#xff0c;main()函数是程序的入口点&#xff0c;它是一个特殊的函数&#xff0c;在程序开始执行时被首先调用&#xff0c;也是程序结束时的最后一个被执行的函数。main() 函数的类型始终为 int&#xff0c;根据C标准&#xff0c;main() …

Petalinux 无法识别PHY ADDR 显示地址为FF 或者-1

BD文件使能了GEM 但是系统启动以后ifconfig发现没有ETH0 解决办法有两种 1&#xff0c;在DTS settings下设置对应的板卡 2.直接修改设备树&#xff0c;第二种方法对没有linux基础的朋友不是那么友好