Rapid Construction of SpringCloud Microservice Project (SpringCloud Alibaba)

I. Overview

        Spring Cloud Alibaba is a one-stop solution for Spring Cloud and Alibaba's microservice architecture. It provides various components in the Spring Cloud ecosystem with the connection with Alibaba middleware, more convenient and easier to use, and rapid development of microservices. Capability and support

2. Commonly used components

  1. Nacos: service registration and discovery, configuration center, providing service registration and discovery, distributed configuration and other capabilities.
  2. Sentinel: Traffic control, service degradation, real-time application monitoring and online admission control capabilities.
  3. RocketMQ: message service, providing reliable message service and message track capabilities.
  4. Seata: Distributed transactions, providing high-performance and high-reliability distributed transaction support.
  5. Dubbo: An RPC framework that provides high-performance, low-latency remote service invocation capabilities.
  6. Alibaba Cloud SDK: Alibaba Cloud support library, which provides cloud computing infrastructure capabilities.

3. Advantages of SpringCloud Alibaba

        1. Based on Spring Cloud: Spring Cloud is a mature microservice framework, and Spring Cloud Alibaba is extended and enhanced on Spring Cloud, which can provide better microservice architecture support.
        2. Rich Alibaba Cloud middleware support: Spring Cloud Alibaba can integrate a variety of Alibaba Cloud middleware, including service registration and discovery, configuration center, message queue, distributed transactions, etc., providing better support for enterprise-level microservice applications. support.
        3. Strong performance and reliability: Based on Alibaba's technology and experience, Spring Cloud Alibaba has a good guarantee in terms of performance and reliability, and is suitable for high-concurrency and high-load enterprise-level application scenarios.
        4. Ease of use and high efficiency: Each component of Spring Cloud Alibaba provides a wealth of documentation and examples, and developers can quickly get started with programming to improve development efficiency.
        5. Active community: Spring Cloud Alibaba's community is very active, with many excellent developers contributing and maintaining it, who can solve problems and provide support in a timely manner.

4. Project construction

1. Create a parent project import dependency

 <!--SpringCloud-->
  <dependencyManagement>
    <dependencies>
      <dependency>
        <groupId>com.alibaba.cloud</groupId>
        <artifactId>spring-cloud-alibaba-dependencies</artifactId>
        <version>2.2.1.RELEASE</version>
        <type>pom</type>
        <scope>import</scope>
      </dependency>
      <dependency>
        <groupId>org.springframework.cloud</groupId>
        <artifactId>spring-cloud-dependencies</artifactId>
        <version>Hoxton.SR3</version>
        <type>pom</type>
        <scope>import</scope>
      </dependency>
    </dependencies>
  </dependencyManagement>

2. Install and start Nacos

3. Add Nacos dependency

   <dependency>
            <groupId>com.alibaba.cloud </groupId>
            <artifactId>spring-cloud-starter-alibaba-nacos-discovery</artifactId>
        </dependency>

        <dependency>
            <groupId>com.alibaba.cloud</groupId>
            <artifactId>spring-cloud-starter-alibaba-nacos-config</artifactId>
        </dependency>

4. Start class annotation service registration @EnableDiscoveryClient

5. yml configures Nacos configuration center information

spring:
  main:
    allow-bean-definition-overriding: true
  profiles:
    active: dev
  application:
    name: service-user
  cloud:
    nacos:
      discovery:
        server-addr: localhost:8848 #注册中心
      config:
        server-addr: localhost:8848 #配置中心
        file-extension: yaml #配置文件格式
        prefix: application-user #配置前缀 ,默认使用sring.application.name
        group: DEFAULT_GROUP
        namespace: 

6. Configure the Feign call interface. When using Feign to call the interface, you need to add relevant dependencies and use the @EnableFeignClients annotation on the startup class to enable the Feign function

7. Install and start Sentinel

8. Configure Sentinel current limit fuse, add Sentinel related dependencies in pom.xml

   <!--sentinel依赖-->
        <dependency>
            <groupId>com.alibaba.cloud</groupId>
            <artifactId>spring-cloud-starter-alibaba-sentinel</artifactId>
        </dependency>

9, yml configuration to open Sentinel

feign:
  sentinel:
    enabled: true

Guess you like

Origin blog.csdn.net/lzc19991201/article/details/131355083