I. Introduction of Ali Micro Service
1. Basic description

Alibaba-cloud is committed to providing a one-stop solution for microservice development. This project contains the necessary components for developing distributed application microservices that developers can easily use to develop distributed application services through the SpringCloud programming model. With only a few annotations and a few configurations, SpringCloud applications can be connected to ali micro services solution and distributed application systems can be quickly built through ali middleware.

2. Core functions

  • The service traffic limit is degraded
By default, support WebServlet, WebFlux OpenFeign, RestTemplate, SpringCloudGateway Zuul, Dubbo and degradation of the current limiting RocketMQ access, can be changed through the console at runtime real-time current limiting downgrade rules, You can also view Metrics for traffic limiting degradation.

  • Service registration and discovery
It ADAPTS to the Spring Cloud Service Registration and Discovery standard and integrates Ribbon support by default.

  • Distributed Configuration Management
Support external configuration in distributed systems, automatically refresh when configuration changes.

  • Message driven capability
Build message-driven capabilities for microservice applications based on Spring Cloud Stream.

  • Distributed transaction
Use the @GlobalTransactional annotation to solve distributed transaction problems efficiently and without intrusion to the business.

  • Distributed task scheduling
Provides second-level, precise, highly reliable, and highly available scheduled (Cron expression based) task scheduling services. It also provides a distributed task execution model, such as grid tasks. Grid tasks allow quantum tasks to be evenly distributed to all workers (schedulerx-client) for execution.

3. Functional components

  • Nacos

A dynamic service discovery, configuration management and service management platform that makes it easier to build cloud native applications.

  • Sentinel

Taking the flow as the entry point, the stability of service is protected from multiple dimensions such as flow control, fusing downgrading and system load protection.

  • RocketMQ

An open source distributed messaging system, based on highly available distributed clustering technology, provides low latency, highly reliable message publishing and subscription services.

  • Dubbo

Apache Dubbo is a high-performance Java RPC framework.

  • Seata

Alibaba open source product, an easy to use high-performance microservices distributed transaction solution.

  • OSS

Ali cloud Object StorageService (OSS) is a massive, secure, low-cost and highly reliable cloud StorageService provided by ali cloud. You can store and access any type of data in any application, anytime, anywhere.

  • SchedulerX

A distributed task scheduling product developed by Ali middleware team provides second-level, accurate, highly reliable and highly available timing (based on Cron expression) task scheduling service.

4. Environment and dependency

  • Nacos service
Nacos is dedicated to discovering, configuring, and managing microservices. Help developers quickly implement dynamic service discovery, service configuration, service metadata and traffic management. Agile building, delivery, and management of microservices platforms. Start by downloading Nacos and starting Nacos Server.

Reference article:

Nacos components, environment construction and introduction of the case

  • Version of the relationship
Version 2.1.X. lease corresponds to SpringBoot2.1.x. Version 2.0.X. lease corresponds to Version 2.0.x of Spring Bootstrap. PS usually learn new things, the most likely to make people confused is the version of the corresponding relationship, the problem is not easy to troubleshoot, generally can refer to the official website to the sample.

Ii. Service Center management
1. Case structure

  • Server: node08-nacos-server
  • Client: node08-nacos-clien

2. Configuration files

The configuration is as follows:

my
name
info
spring
datasource
type
druid
driverClassName
url
jdbc
mysql
//localhost:3306/data_one
username
password
Core content: DataID, file format, file content configuration. There is also a MySQL data source configured.

3. Service registration discovery

(1) Server configuration

  • The core depends on
<dependency>
<groupId>
</groupId>
<artifactId>
</artifactId>
<version>
</version>
</dependency>
  • The configuration file
spring
application
name
cloud
nacos
discovery
server-addr
If the name configuration is the same as the DataID configuration above, the above configuration can be read.

  • Provide service interface
@RestController
public
private
static
@RequestMapping
“/web/getMsg”
“8001 service called…”
return
“Hello:”
  • Start class annotations
@SpringBootApplication
// SpringCloud native annotation @enableDiscoveryClient Enables service registration discovery
@EnableDiscoveryClient
public
(2) Client configuration

  • The core depends on
<dependency>
<groupId>
</groupId>
<artifactId>
</artifactId>
<version>
</version>
</dependency>
<! — Feign component –>
<dependency>
<groupId>
</groupId>
<artifactId>
</artifactId>
<version>
</version>
</dependency>
It is also possible to access the interface services provided by the above server based on Feign mode.

  • Access based on Rest interfaces
Interface Configuration

@Configuration
@LoadBalanced
@Bean
return
new
RestTemplate
This usage is the same as the SpringCloud native framework ecology.

Request method

@RestController
public
@Resource
private
@RequestMapping
“/web/getMsgV1/{name}”
“http://node08-nacos-server:8001/web/getMsg/”
return
  • Access based on Feign interface
Feign Interface configuration

@FeignClient
“node08-nacos-server”
public
@GetMapping
“/web/getMsg”
The usage here remains the same as the native framework ecology of SpringCloud.

Request method

@RestController
public
@Resource
private
@RequestMapping
“/web/getMsgV2/{name}”
return
  • Startup Class Configuration
@SpringBootApplication
@EnableDiscoveryClient
@EnableFeignClients
“cloud.nacos.client.feign”
public

3. Configuration center management

Through the configuration management of Nacos, the configuration within the integrated architecture system can be centrally and uniformly stored and managed in Nacos. Separate multi-environment configuration and flexible rights management.

1. Core dependencies

<dependency>
<groupId>
</groupId>
<artifactId>
</artifactId>
<version>
</version>
</dependency>

2. Configure the server

spring
application
name
cloud
nacos
discovery
server-addr
config
server-addr
file-extension
The core configuration here is the Config configuration.

3. Configure the read mode

This is the native reading of the Spring framework.

@RestController
@RefreshScope
public
@Value
“${my.name:}”
private
@Value
“${my.info:}”
private
@RequestMapping
“/getNameInfo”
return
“:”

4. Database connection

Configuring JDBC Connections

Here you configure the JdbcTemplate database access API based on the Druid connection pool.

@Configuration
public
@Value
“${spring.datasource.druid.url}”
private
@Value
“${spring.datasource.druid.username}”
private
@Value
“${spring.datasource.druid.password}”
private
@Value
“${spring.datasource.druid.driverClassName}”
private
/** * Druid connection pool configuration */
@Bean
new
return
/** * JDBC operation configuration */
@Bean
“jdbcTemplate”
return
new
The test method

@RestController
public
@Resource
private
@RequestMapping
“/getJdbc”
“select phone from d_phone”
return

Iv. Case Summary

After all, AlibabaCloud framework is based on the SpringCloud framework. Adapted to a lot of ali open source components, in the selection of micro-service framework components, according to business needs and the team familiar with the selection of procedures.