Sentinel Getting Started And Integration of Spring Cloud Alibaba Tutorials

本文主要是介绍Sentinel Getting Started And Integration of Spring Cloud Alibaba Tutorials,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

原文链接:Sentinel Getting Started And Integration of Spring Cloud Alibaba Tutorials

Sentinel Getting Started And Integration of Spring Cloud Alibaba Tutorials

TIPS

This article based on:a

- Spring Boot 2.1.5

- Spring Cloud Greenwich.SR1

- Spring Cloud Alibaba 0.9.0

- Nacos 1.0.0

1. What is Sentinel ?

With the popularity of microservices, the stability between services and services is becoming more and more important. Sentinel uses traffic as an entry point to protect the stability of services from multiple dimensions such as flow control, blowdown, and system load-balance protection.

In a nutshell, Sentinel is a lightweight flow control, blowdown and degraded Java library.

Sentinel has the following characteristics:

  • Rich application scenarios:Sentinel undertakes the core scene of Alibaba's "Double Eleven" promotion traffic for nearly 10 years. For example, spikes (that is, burst flow control can be tolerated in the system capacity), message peaking and valley filling, cluster flow control, real-time fuse downstream applications that are not available.
  • Complete real-time monitoring:Sentinel also provides real-time monitoring. You can see the single machine second-level data of the access application in the console, or even the aggregate operation of clusters of less than 500 sizes.
  • Extensive open source ecology:Sentinel Provides out-of-the-box integration modules with other open source frameworks/libraries. For example, integration with Spring Cloud, Dubbo, gRPC. You only need to introduce the appropriate dependencies and perform a simple configuration to quickly access Sentinel.
  • Complete SPI extension point:Sentinel provides an easy-to-use, comprehensive SPI expansion interface。You can quickly customize the logic by implementing an extension interface. Such as custom rule management, adapting dynamic data sources, etc.

2. Guides

  • Add dependencies:
  <dependency><groupId>org.springframework.cloud</groupId><artifactId>spring-cloud-starter-alibaba-sentinel</artifactId><version>0.2.1.RELEASE</version></dependency>

  • Add configurations:
  server:port: 8010spring:application:# Specify the name of the service registered to the nacos servername: microservice-consumer-moviecloud:nacos:discovery:server-addr: 127.0.0.1:8848management:endpoints:web:exposure:include: '*'

  • Add Controller:
  @RequestMapping("/movies")@RestControllerpublic class MovieController {@Autowiredprivate RestTemplate restTemplate;@GetMapping("/users/{id}")public User findById(@PathVariable Long id) {// Use the placeholder of the RestTemplateUser user = this.restTemplate.getForObject("http://microservice-provider-user/users/{id}",User.class,id);// ...Movie microservices business...return user;}}

It can be seen from the code that this one can't be normal controller! Because Sentinel starter will provide a current limit for all HTTP services by default, the Controller can be protected by Sentinel (but there are no rules for configuring protection yet, so it has not been protected yet)!

3. Test

  • Access http://localhost:8010/actuator/sentinel ,the following results can be obtained:
  {"DegradeRules": [],"datasources": {},"ParamFlowRule": [],"SystemRules": [],"FlowRules": [],"properties": {"eager": false,"enabled": true,"datasource": {},"transport": {"port": "8719","dashboard": "localhost:8080","heartbeatIntervalMs": null},"metric": {"fileSingleSize": null,"fileTotalCount": null,"charset": "UTF-8"},"servlet": {"blockPage": null},"filter": {"order": -2147483648,"urlPatterns": ["/*"]},"flow": {"coldFactor": "3"},"log": {"dir": null,"switchPid": false}}}

At the moment, we don't know what the meaning of the result exposed by /actuator/sentinel is. It doesn't matter, please read on.

4. Summary

Just add the spring-cloud-starter-alibaba-sentinel dependency to your app, and all HTTP interfaces get Sentinel protection! Of course, we currently have no rules for configuring protection for Sentinel.

5. Sample Code

GitHub

Gitee

原文链接:Sentinel Getting Started And Integration of Spring Cloud Alibaba Tutorials

本文由博客一文多发平台 OpenWrite 发布!

这篇关于Sentinel Getting Started And Integration of Spring Cloud Alibaba Tutorials的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/984238

相关文章

Maven中引入 springboot 相关依赖的方式(最新推荐)

《Maven中引入springboot相关依赖的方式(最新推荐)》:本文主要介绍Maven中引入springboot相关依赖的方式(最新推荐),本文给大家介绍的非常详细,对大家的学习或工作具有... 目录Maven中引入 springboot 相关依赖的方式1. 不使用版本管理(不推荐)2、使用版本管理(推

Java 中的 @SneakyThrows 注解使用方法(简化异常处理的利与弊)

《Java中的@SneakyThrows注解使用方法(简化异常处理的利与弊)》为了简化异常处理,Lombok提供了一个强大的注解@SneakyThrows,本文将详细介绍@SneakyThro... 目录1. @SneakyThrows 简介 1.1 什么是 Lombok?2. @SneakyThrows

在 Spring Boot 中实现异常处理最佳实践

《在SpringBoot中实现异常处理最佳实践》本文介绍如何在SpringBoot中实现异常处理,涵盖核心概念、实现方法、与先前查询的集成、性能分析、常见问题和最佳实践,感兴趣的朋友一起看看吧... 目录一、Spring Boot 异常处理的背景与核心概念1.1 为什么需要异常处理?1.2 Spring B

如何在 Spring Boot 中实现 FreeMarker 模板

《如何在SpringBoot中实现FreeMarker模板》FreeMarker是一种功能强大、轻量级的模板引擎,用于在Java应用中生成动态文本输出(如HTML、XML、邮件内容等),本文... 目录什么是 FreeMarker 模板?在 Spring Boot 中实现 FreeMarker 模板1. 环

SpringMVC 通过ajax 前后端数据交互的实现方法

《SpringMVC通过ajax前后端数据交互的实现方法》:本文主要介绍SpringMVC通过ajax前后端数据交互的实现方法,本文给大家介绍的非常详细,对大家的学习或工作具有一定的参考借鉴价... 在前端的开发过程中,经常在html页面通过AJAX进行前后端数据的交互,SpringMVC的controll

Java中的工具类命名方法

《Java中的工具类命名方法》:本文主要介绍Java中的工具类究竟如何命名,本文给大家介绍的非常详细,对大家的学习或工作具有一定的参考借鉴价值,需要的朋友参考下吧... 目录Java中的工具类究竟如何命名?先来几个例子几种命名方式的比较到底如何命名 ?总结Java中的工具类究竟如何命名?先来几个例子JD

Java Stream流使用案例深入详解

《JavaStream流使用案例深入详解》:本文主要介绍JavaStream流使用案例详解,本文通过实例代码给大家介绍的非常详细,对大家的学习或工作具有一定的参考借鉴价值,需要的朋友参考下吧... 目录前言1. Lambda1.1 语法1.2 没参数只有一条语句或者多条语句1.3 一个参数只有一条语句或者多

Spring Security自定义身份认证的实现方法

《SpringSecurity自定义身份认证的实现方法》:本文主要介绍SpringSecurity自定义身份认证的实现方法,下面对SpringSecurity的这三种自定义身份认证进行详细讲解,... 目录1.内存身份认证(1)创建配置类(2)验证内存身份认证2.JDBC身份认证(1)数据准备 (2)配置依

SpringBoot整合OpenFeign的完整指南

《SpringBoot整合OpenFeign的完整指南》OpenFeign是由Netflix开发的一个声明式Web服务客户端,它使得编写HTTP客户端变得更加简单,本文为大家介绍了SpringBoot... 目录什么是OpenFeign环境准备创建 Spring Boot 项目添加依赖启用 OpenFeig

Java Spring 中 @PostConstruct 注解使用原理及常见场景

《JavaSpring中@PostConstruct注解使用原理及常见场景》在JavaSpring中,@PostConstruct注解是一个非常实用的功能,它允许开发者在Spring容器完全初... 目录一、@PostConstruct 注解概述二、@PostConstruct 注解的基本使用2.1 基本代