Developer Guide - Support.huaweicloud

Transcription

ServiceStageDeveloper GuideIssue01Date2022-06-06HUAWEI TECHNOLOGIES CO., LTD.

Copyright Huawei Technologies Co., Ltd. 2022. All rights reserved.No part of this document may be reproduced or transmitted in any form or by any means without priorwritten consent of Huawei Technologies Co., Ltd.Trademarks and Permissionsand other Huawei trademarks are trademarks of Huawei Technologies Co., Ltd.All other trademarks and trade names mentioned in this document are the property of their respectiveholders.NoticeThe purchased products, services and features are stipulated by the contract made between Huawei andthe customer. All or part of the products, services and features described in this document may not bewithin the purchase scope or the usage scope. Unless otherwise specified in the contract, all statements,information, and recommendations in this document are provided "AS IS" without warranties, guaranteesor representations of any kind, either express or implied.The information in this document is subject to change without notice. Every effort has been made in thepreparation of this document to ensure accuracy of the contents, but all statements, information, andrecommendations in this document do not constitute a warranty of any kind, express or implied.Huawei Technologies Co., Ltd.Address:Huawei Industrial BaseBantian, LonggangShenzhen 518129People's Republic of uawei.comIssue 01 (2022-06-06)Copyright Huawei Technologies Co., Ltd.i

ServiceStageDeveloper GuideContentsContents1 Microservice Development Guide. 11.1 Overview. 11.1.1 Development Introduction. 11.1.2 Related Concepts. 31.1.3 Development Process. 41.1.4 Development Specifications. 71.2 Developing Microservice Applications.81.3 Preparing the Environment. 91.4 Connecting Microservice Applications to CSE. 121.4.1 Connecting Spring Cloud Applications to CSE.121.4.2 Connecting Java Chassis Applications to CSE. 181.5 Deploying Microservice Applications. 221.6 Using CSE Functions. 231.6.1 Using Service Registry. 231.6.2 Using the Configuration Center. 271.6.2.1 Configuration Center Overview . 271.6.2.2 Java Chassis Configuration Center. 281.6.2.3 Spring Cloud Configuration Center.301.6.3 Using Service Governance. 311.6.3.1 Overview. 311.6.3.2 Request Marker-based Governance with Dynamic Configuration.321.6.3.3 Development of Request Marker-based Governance with Dynamic Configuration.371.6.4 Using Dark Launch.391.6.5 Using Dashboard. 411.6.6 Using Security Authentication. 421.6.6.1 Security Authentication Overview.421.6.6.2 Creating a Security Authentication Account and Password. 421.6.6.3 Configuring the Security Authentication Account and Password for a Microservice. 421.7 Appendix. 441.7.1 Java chassis Version Upgrade Reference. 441.7.2 Changing and Switching AK/SK Authentication Mode.451.7.3 Configuring the AK/SK for Microservice Applications.461.7.3.1 Java Chassis. 46Issue 01 (2022-06-06)Copyright Huawei Technologies Co., Ltd.ii

ServiceStageDeveloper GuideContents1.7.3.2 Go Chassis.471.7.3.3 Spring Cloud. 471.7.3.4 Mesher. 481.7.4 Obtaining the AK/SK and Project Name. 491.7.5 Local Development Tool. 501.7.6 Connecting Go Chassis Applications to CSE. 501.7.7 Connecting Dubbo Applications to CSE. 521.7.7.1 Connecting Dubbo Applications to CSE. 521.7.7.2 Using Service Registry. 551.7.7.3 Using the Configuration Center. 561.7.7.4 Using Service Governance. 571.7.8 Connecting Mesher Applications to CSE. 581.7.8.1 Mesher Overview. 581.7.8.2 Description. 601.7.8.3 Connecting .Net Core to Service Mesh. 61Issue 01 (2022-06-06)Copyright Huawei Technologies Co., Ltd.iii

ServiceStageDeveloper Guide1 Microservice Development Guide1Microservice Development GuideOverviewDeveloping Microservice ApplicationsPreparing the EnvironmentConnecting Microservice Applications to CSEDeploying Microservice ApplicationsUsing CSE FunctionsAppendix1.1 Overview1.1.1 Development IntroductionOverviewA stable and reliable microservice running environment is crucial as themicroservice architecture has become the first option for developers to buildapplications.Cloud Service Engine (CSE) is a one-stop management platform provided byServiceStage for microservice solutions. It enables developers to focus on servicedevelopment and improve product delivery efficiency and quality. The microservicearchitecture consists of the following: Issue 01 (2022-06-06)Remote Procedure Call (RPC) communication between microservices. Themicroservice architecture requires that microservices communicate with eachother through RPC instead of other traditional communication modes, such asshared memory and pipes. Common communication protocols include REST(HTTP JSON), gRPC (HTTP2 protobuffer) and Web Service (HTTP SOAP).Using RPC for communication reduces coupling between microservices andmakes the system more open with less technological restriction. You areadvised to use standard protocols in the industry, such as REST. Proprietaryprotocols can also be used in scenarios requiring high performance.Copyright Huawei Technologies Co., Ltd.1

ServiceStageDeveloper Guide1 Microservice Development Guide Distributed microservice instances and service discovery. The microservicearchitecture is highly elastic and needs to support multi-instance deploymentof microservices to handle the dynamic service traffic. The microservice designis generally stateless. Increasing stateless microservice instances lets youimprove processing performance. When there are a large number of instances,a middleware that supports service registry and discovery is required formicroservice calling and addressing. Dynamic and centralized configuration management. The configuration ofmicroservice management is increasingly complex as the number ofmicroservices and instances increases. The configuration managementmiddleware provides a unified view for all microservices, simplifying theconfiguration management of microservices. Such middleware works with thegovernance console to adjust microservice at microservice runtime to handlechanging service scenarios without application upgrade. Microservice governance capabilities, such as circuit breaker, isolation, ratelimiting, and load balancing. These governance capabilities can mitigate theimpact of some common faults of the microservice architecture on theservices. Tracing and centralized log collection and retrieval. Viewing logs remains themost commonly used method for analyzing system faults. Tracing informationhelps locate faults and analyze performance bottlenecks.The microservice architecture has been implemented on many open-sourceframeworks, such as Spring Cloud, Apache ServiceComb Java chassis (Javachassis for short), Apache Dubbo (Dubbo for short), and Go chassis. CSE supportsthe access of these open-source microservice frameworks and uses functions suchas registry, discovery, centralized configuration, and service governance. Thefollowing figure shows the relationship.You can use Spring Cloud and Java chassis microservice development frameworksto access the microservice engine to obtain the best development experience andtechnical support. Using other development frameworks, such as Go chassis andDubbo, or using Mesher to access the microservice engine depends on thetechnical support of the open-source community.This document focuses on the development guide of Spring Cloud and Javachassis. Microservice applications developed based on other frameworks use themicroservice engine: Go chassis. For details, see Connecting Go Chassis Applications to CSE. Dubbo. For details, see Connecting Dubbo Applications to CSE.Issue 01 (2022-06-06)Copyright Huawei Technologies Co., Ltd.2

ServiceStageDeveloper Guide1 Microservice Development Guide Mesher. For details, see Connecting Mesher Applications to CSE.Development Capability RequirementsThis document describes how the open-source microservice developmentframeworks are connected to CSE and use its functions. Assume that you have thefollowing development capabilities: You have developed an application based on a microservice developmentframework supported by ServiceStage and want to host the application onCSE. This document provides technical support for connecting microserviceapplications to CSE. This document does not describe how to use the opensource microservice development frameworks. You can obtain the basicmaterials and development guides of these frameworks in relevant opensource communities. Understanding the functions of the registry center and configuration center inmicroservice applications, and building and using the registry center inprojects. Different microservice development frameworks support differentopen-source registry centers by default. Therefore, understanding thefunctions of a registry center helps you change registry centers at ease. Getting familiar with the procedure of deploying applications in a VM orcontainer environment. For details, see Deploying Application Components.1.1.2 Related ConceptsCore Concepts of CSE Application: a software system that implements a complete service. Anapplication consists of multiple microservices, which can discover and calleach other. Microservice: a software system that implements a specific service function.Microservices are independently developed and deployed. Microservice instance: An instance is generated when a microservice isdeployed in the runtime environment using the deployment system. Aninstance can be considered a process, and multiple instances can be deployedfor a microservice. Microservice environment: a logical concept established by the service center,which can be development or production. Microservice instances in differentenvironments are logically isolated and cannot be discovered or called byeach other.Core Concepts of ServiceStageSome important concepts of ServiceStage are described as follows: Issue 01 (2022-06-06)Application: The meaning of ServiceStage applications is similar to that of CSEapplications. The application name of ServiceStage is specified duringdeployment, and the application name of CSE is specified during microservicedevelopment. The two names can be different. The microservice developmentframework provides the environment variable mapping function, which allowsdevelopers to set the ServiceStage application name as the microserviceapplication name.Copyright Huawei Technologies Co., Ltd.3

ServiceStageDeveloper Guide1 Microservice Development Guide Component: A component of ServiceStage corresponds to a microservice ofCSE. The component name of ServiceStage is specified during deployment,and the component name of CSE is specified during microservicedevelopment. CSE can use the component names of ServiceStage throughenvironment variable mapping. Instance: An instance of ServiceStage corresponds to an instance of CSE.Instances are available on ServiceStage once the deployment is successful.Instances are available on CSE only after they are registered with the servicecenter. When the service is normally registered, the number of instances ofServiceStage and CSE is the same. When the registry fails, instances areavailable only on ServiceStage. Environment: The concept of environment in ServiceStage is different fromthat in CSE. The ServiceStage environment is a running environmentconsisting of resources, including CSE and cloud container engine (CCE).1.1.3 Development ProcessOverviewFigure 1-1 shows the process of developing an application and using CSE.Issue 01 (2022-06-06)Copyright Huawei Technologies Co., Ltd.4

ServiceStageDeveloper Guide1 Microservice Development GuideFigure 1-1 Development processDescription1.Develop microservice applicationsIf you have developed a microservice application, skip this step and preparethe environment.Before developing a microservice application, you need to select a technology.To select an appropriate technology, technical decision makers need toIssue 01 (2022-06-06)Copyright Huawei Technologies Co., Ltd.5

ServiceStageDeveloper Guide1 Microservice Development Guideconsider whether team members can master the technology, and whether thetechnology can deliver the desired functions, performance, and reliability ofthe project. Many other factors, such as commercial services, should also betaken into account. This document does not discuss technology selection.Assume that the technical team has selected a proper developmentframework. Most technical teams build their services using open-sourceframeworks.For details about how to develop microservice applications, see DevelopingMicroservice Applications.2.–For Java chassis, the following technology is used for local microservicedevelopment:–For Spring Cloud, the following technology is used for local microservicedevelopment:Prepare the environmentCreate a cloud environment to support the CSE connection test, cloud-basedapplication deployment, and CSE functions. Generally, a test environment anda production environment are created. ServiceStage facilitates cloudenvironment management. For details, see Preparing the Environment.3.Connect to microservice applicationsMicroservice applications are connected to CSE. To perform this step, youneed to modify the configuration files and build scripts of developedapplications. After the modification, recompile and package the applicationand deploy the application package on CSE using ServiceStage. For details,see Connecting Microservice Applications to CSE.Issue 01 (2022-06-06)Copyright Huawei Technologies Co., Ltd.6

ServiceStageDeveloper Guide1 Microservice Development Guide4.Deploy microservice applicationsDeploy the developed microservice applications to CSE using ServiceStage. Fordetails, see Deploying Microservice Applications.5.Use CSE functionsAn evolving application requires continuous improvement and iteration. Ineach iteration, microservice applications may need to be upgraded, requiringmore CSE functions. The preceding application development, compilation,packaging, and deployment will repeat during function iteration. For details,see Using CSE Functions.1.1.4 Development SpecificationsDevelopment LanguageUsing Java or Go to develop microservices.Microservice Development Framework VersionsThe following table lists the recommended versions of the microservicedevelopment framework. If you have used the microservice development framework of an earlierversion to build applications, you are advised to upgrade it to therecommended version to obtain the stable and rich function experience. If an application has been developed using the Spring Cloud microservicedevelopment framework, you are advised to use Spring Cloud Huawei toaccess the application. If new microservice applications are developed based on open source andindustry ecosystem components, you are advised to use the Spring Cloudframework. If you want to use the out-of-the-box governance capability and highperformance RPC framework provided by CSE, you are advised to use the Javachassis va chassis2.6.0 or laterUses the software package provided bythe open-source project for connectionwithout introducing third-party softwarepackages.Version description of the Java chassismicroservice development a-chassis/releases.Issue 01 (2022-06-06)Copyright Huawei Technologies Co., Ltd.7

ServiceStageDeveloper Guide1 Microservice Development GuideFrameworkRecommendedVersionDescriptionSpring Cloud1.8.0-2020.0.x orlaterUses Spring Cloud Huawei forconnection. The recommended version:Spring Cloud Huawei; correspondingSpring Cloud version: 2020.0.x.Version description of the Spring Cloudmicroservice development ud-huawei/releasesSpring Cloud1.8.0-Hoxton orlaterUses Spring Cloud Huawei forconnection. The recommended version:Spring Cloud Huawei; correspondingSpring Cloud version: Hoxton.Version description of the Spring Cloudmicroservice development ud-huawei/releases1.2 Developing Microservice ApplicationsIf you have developed a microservice application, skip this section.The open-source community provides development documents and help channelsto help you use the microservice development framework. For details aboutmicroservice application development in a specific microservice framework, seethe reference documents provided in this section.The recommended CSE samples offer you quick connection to CSE. Download thesamples, modify the CSE address and AK/SK information in the configuration file,and run the examples locally. These samples can be registered with CSE. Spring CloudSource code repository: https://github.com/spring-cloudIssues: For details, see the issues in each code repository of the source coderepository.Developer guide: https://spring.io/projects/spring-cloudSpring Cloud Huawei project: ecommended CSE samples: samples/tree/master/basic Java chassisSource code repository: ssues: /issuesDeveloper guide: ssis/en US/Issue 01 (2022-06-06)Copyright Huawei Technologies Co., Ltd.8

ServiceStageDeveloper Guide1 Microservice Development GuideRecommended CSE samples: master/basic1.3 Preparing the EnvironmentYou need to prepare the local development and commissioning environment andcloud environment.Preparing a Local Development and Commissioning EnvironmentThe local development and commissioning environment is used to set up a simpletest environment. The options are as follows: Download the local CSE. Use the professional or exclusive microservice engine and open the IP addressfor public network access to ensure that the local environment can beaccessed.Preparing the Cloud EnvironmentBefore deploying microservice applications on the cloud, you need to prepare thecloud environment. Perform the following procedure to prepare the environment: Obtain the AK/SK and project name. For details, see Obtaining the AK/SKand Project Name.NOTE If the professional microservice engine is used, you need to configure the AK/SK. If the exclusive microservice engine is used, you do not need to configure theAK/SK. Create a microservice engine. For details, see Creating an ExclusiveMicroservice Engine. Create an environment. For details, see Environment Management. Thecreated environment must contain resources such as CCE clusters, Elastic LoadBalancers (ELBs), and CSEs. Create an application. For details, see Creating an Application.Common Environment VariablesUsing ServiceStage to manage environments and deploy applications simplifiesuser configuration. ServiceStage sets some environment variables for applications.The following table lists some common environment variables:Issue 01 (2022-06-06)Copyright Huawei Technologies Co., Ltd.9

ServiceStageDeveloper Guide1 Microservice Development GuideTable 1-1 Common environment variablesNameDescriptionPAAS CSE ENDPOINTAddress of services such as the CSE registry center andconfiguration center. This environment variable is usedwhen the professional microservice engine is accessedthrough API Gateway. A unified domain name applies tothe external access addresses of the preceding services.NOTEYou are not advised to use this environment variable. Instead, usethe environment variable of a specific service, so that you do notneed to modify the application when connecting to the exclusivemicroservice engine.PAAS CSE SC ENDPOINTAddress for CSE registry and discovery.PAAS CSE CC ENDPOINTAddress of the CSE configuration center.PAAS PROJECT NAMEName of a project.CAS APPLICATION NAMEName of a ServiceStage application.CAS COMPONENT NAMEName of a ServiceStage component.CAS INSTANCE VERSIONVersion of the deployed ServiceStage.You can use these variables based on the mechanisms of different microservicedevelopment frameworks, such as the Place Holder mechanism of Spring Cloudand the mapping.yaml mechanism of Java chassis, to reduce manual input duringdeployment.When creating an application on ServiceStage, you can bind middleware, such asDistributed Cache Service (DCS) and Relational Database Service (RDS), to theapplication. You can obtain the configuration information about the middlewarebound to applications by using the following environment variables. Distributed sessionDistributed sessions are stable and reliable session storage based on DCS,supporting automatic injection for mainstream web containers, such astomcat context, node.js express-session, and PHP session handler.The following table describes the environment variables of distributedsessions.Issue 01 (2022-06-06)Copyright Huawei Technologies Co., Ltd.10

ServiceStageDeveloper Guide1 Microservice Development GuideTable 1-2 Environment variables of DCS sessions Environment VariableDescriptionDISTRIBUTED SESSION CLUSTERWhether the instance is in clustermode. Value: true or false.DISTRIBUTED SESSION TYPEStorage type of a distributed sessioninstance. Currently, only Redis issupported.DISTRIBUTED SESSION VERSIONVersion of a distributed sessioninstance.DISTRIBUTED SESSION NAMEName of a distributed sessioninstance.DISTRIBUTED SESSION HOSTIP address for connecting to adistributed session instance.DISTRIBUTED SESSION PORTPort for connecting to a distributedsession instance.DISTRIBUTED SESSION PASSWORDPassword for connecting to adistributed session instance.Distributed cacheDistributed Cache Service (DCS) is an online, distributed, in-memory cacheservice compatible with Redis and Memcached. It combines high reliabilityand scalability with instant availability and easy management, delivering highread/write performance and fast data access.The following table describes the environment variables of DCS.Table 1-3 Environment variables of DCSIssue 01 (2022-06-06)Environment VariableDescriptionDISTRIBUTED CACHE CLUSTERWhether the instance is in clustermode. Value: true or false.DISTRIBUTED CACHE TYPEStorage type of a distributed cacheinstance. Currently, only Redis issupported.DISTRIBUTED CACHE VERSIONVersion of a DCS instance.DISTRIBUTED CACHE NAMEName of a DCS instance.DISTRIBUTED CACHE HOSTIP address for connecting to a DCSinstance.DISTRIBUTED CACHE PORTPort for connecting to a DCSinstance.DISTRIBUTED CACHE PASSWORDPassword for connecting to a DCSinstance.Copyright Huawei Technologies Co., Ltd.11

ServiceStageDeveloper Guide1 Microservice Development Guide Relational databaseRelational Database Service (RDS) is a cloud-based web service that isreliable, scalable, easy-to-manage, and out-of-the-box.The following table describes the environment variables of RDS.Table 1-4 Environment variables of RDSEnvironment VariableDescriptionRELATIONAL DATABASE NAMEName of an RDS instance.RELATIONAL DATABASE CONNECTION TYPEConnection type of an RDS instance.Value: JNDI/SPRING CLOUD CONNECTOR.RELATIONAL DATABASE JNDI NAMEJNDI name of an RDS instance. Thisvariable is used if the connectiontype is JNDI.RELATIONAL DATABASE DB NAMEDatabase name of an RDS instance.RELATIONAL DATABASE DB USERDatabase user of an RDS instance.RELATIONAL DATABASE DB TYPEDatabase type of an RDS instance.Currently, only MySQL is supported.RELATIONAL DATABASE VERSIONDatabase version of an RDSinstance.RELATIONAL DATABASE HOSTDatabase IP address of an RDSinstance.RELATIONAL DATABASE PORTDatabase port of an RDS instance.RELATIONAL DATABASE PASSWORDDatabase password of an RDSinstance.1.4 Connecting Microservice Applications to CSE1.4.1 Connecting Spring Cloud Applications to CSEThis section describes how to connect Spring Cloud app

of microservices to handle the dynamic service traffic. The microservice design is generally stateless. Increasing stateless microservice instances lets you . and building and using the registry center in projects. Different microservice development frameworks support different open-source registry centers by default. Therefore, understanding the