您的位置:首页 > 教育 > 培训 > 网红营销对消费者行为的影响_网址提交收录_百度权重怎么提高_外链怎么发

网红营销对消费者行为的影响_网址提交收录_百度权重怎么提高_外链怎么发

2024/10/6 9:19:50 来源:https://blog.csdn.net/qq_58159506/article/details/142283927  浏览:    关键词:网红营销对消费者行为的影响_网址提交收录_百度权重怎么提高_外链怎么发
网红营销对消费者行为的影响_网址提交收录_百度权重怎么提高_外链怎么发

Spring Cloud Alibaba-(1)搭建项目环境

Spring Cloud Alibaba-(2)Nacos【服务注册与发现、配置管理】

Spring Cloud Alibaba-(3)OpenFeign【服务调用】

Spring Cloud Alibaba-(4)Sentinel【流控和降级】

Spring Cloud Alibaba-(5)Seata【分布式事务】

Spring Cloud Alibaba-(6)Spring Cloud Gateway【网关】

Spring Cloud Alibaba-(7)RocketMQ【分布式消息队列】

1.Sentinel官网-https://sentinelguard.io/zh-cn/index.html

2.流控,即流量控制

流控的主要目的是防止系统过载。当系统请求量过大时,可以通过限制请求的速率来保证系统的稳定性和响应时间。流控规则(6.4.1节)可以帮助开发者合理分配系统的流量,避免因流量过大而导致系统崩溃。

3.降级,即熔断降级

降级的主要目的是当系统出现异常或负载过高时,主动降低服务的可用性,以保证核心业务不受影响熔断降级策略(6.5节)通常用于处理服务超时、异常率高等问题。

4.下载 Sentinel 控制台

5.进入目录,cmd 运行(java -Dserver.port=8858 -jar sentinel-dashboard-1.8.6.jar)

6.订单微服务整合Sentinel

6.1 引入Maven依赖

<!-- sentinel 限流降级 -->
<dependency><groupId>com.alibaba.cloud</groupId><artifactId>spring-cloud-starter-alibaba-sentinel</artifactId>
</dependency>

6.2 bootstrap.yml 配置 Sentinel 控制台地址

server:port: 8000spring:profiles:active: publicapplication:name: order-servicedatasource:driver-class-name: com.mysql.cj.jdbc.Driverurl: jdbc:mysql://localhost:3306/springcloud2024username: rootpassword: 123456cloud:nacos:discovery:server-addr: http://localhost:8848config:server-addr: http://localhost:8848file-extension: yaml
#        namespace: 94d2d0de-e485-47b1-a375-b423ccc01301openfeign:httpclient:# 连接超时connection-timeout: 5000sentinel:transport:dashboard: http://localhost:8858# Openfeign 整合 sentinel
feign:sentinel:enabled: true

6.3 直接访问 Sentinel 控制台是空的,要调用接口才会注册到Sentinel

6.4 流控规则

6.4.1 流控规则

阈值类型QPS:即每秒的访问量,超过阈值会流控
并发线程数:超过阈值会流控
流控模式直接:直接流控该资源
关联:流控关联资源
链路:流控入口资源
流控效果快速失败:超过阈值,直接拒绝
Warm Up(适用于激增流量):在一段时间内让流量逐渐增加到阈值
排队等待(适用于脉冲流量):请求排队,保证稳定的流量速率

6.4.2 设置下单接口 QPS 流控规则(每秒访问量超过2次,直接流控该资源,超过2次的请求直接拒绝)

6.4.3 快速请求下单接口,测试流控

6.5 熔断降级策略

慢调用比例(适用于对延迟敏感)

慢调用比例是指在一定时间内,请求超时或超过阈值所占的比例。如果超过阈值,则触发熔断降级。

异常比例(适用于对异常敏感)

异常比例是指在一定时间内,抛出异常请求所占的比例。如果超过阈值,则触发熔断降级。

异常数(适用于对异常数敏感)

异常数是指在一定时间内,抛出异常请求次数。如果超过阈值,则触发熔断降级。

7.OpenFeign 整合 Sentinel 实现服务出现异常,对服务进行降级

7.1 OpenFeign 创建降级回调类

package com.dragon.openfeign;import cn.dev33.satoken.util.SaResult;
import com.dragon.entity.Product;
import org.springframework.stereotype.Component;@Component
public class ProductServiceFallback implements ProductServiceFeign {@Overridepublic SaResult getById(String id) {return SaResult.ok().setMsg("调用产品服务的 getById() 出现异常,服务降级了");}@Overridepublic SaResult saveOrUpdate(Product productDto) {return SaResult.ok().setMsg("调用产品服务的 saveOrUpdate() 出现异常,服务降级了");}@Overridepublic SaResult test() {return SaResult.ok().setMsg("调用产品服务的 test() 出现异常,服务降级了");}
}

7.2 OpenFeign 开启降级回调  fallback = ProductServiceFallback.class

package com.dragon.openfeign;import cn.dev33.satoken.util.SaResult;
import com.dragon.entity.Product;
import io.swagger.v3.oas.annotations.Operation;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;/*** value:服务提供方的服务名* path:服务提供方的RequestMapping* fallback:接口出现异常的降级回调类*/
@FeignClient(value = "product-service",path = "/product",fallback = ProductServiceFallback.class)
public interface ProductServiceFeign {@Operation(summary = "根据ID获取产品")@PostMapping("/getById/{id}")SaResult getById(@PathVariable("id") String id);@Operation(summary = "新增或更新")@PostMapping("/saveOrUpdate")SaResult saveOrUpdate(@RequestBody Product productDto);@Operation(summary = "测试产品服务的 test() 接口")@GetMapping("/test")SaResult test();
}

7.3 bootstrap.yml 开启Openfeign 整合 sentinel

# Openfeign 整合 sentinel
feign:sentinel:enabled: true

7.4 产品服务的 test() 中模拟出现异常

7.5 订单服务调用产品服务,进行测试

8.Sentinel 持久化

8.1 为什么 Sentinel 要实现持久化?

Sentinel 的规则默认保存在内存中,重启服务规则丢失。

8.2 Sentinel + Nacos 实现持久化

8.2.1 引入Maven依赖

<!-- sentinel 规则保存到 nacos 配置中心 -->
<dependency><groupId>com.alibaba.csp</groupId><artifactId>sentinel-datasource-nacos</artifactId>
</dependency>

8.2.2 Nacos 配置管理,创建流控规则配置

8.3.3 bootstrap.yml 配置

8.4.4 调用  /order/add/{productId} 接口,Sentinel会自动读取Nacos的流控配置,实现流控

版权声明:

本网仅为发布的内容提供存储空间,不对发表、转载的内容提供任何形式的保证。凡本网注明“来源:XXX网络”的作品,均转载自其它媒体,著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。

我们尊重并感谢每一位作者,均已注明文章来源和作者。如因作品内容、版权或其它问题,请及时与我们联系,联系邮箱:809451989@qq.com,投稿邮箱:809451989@qq.com