هذه الصفحة غير متوفرة حاليًا بلغتك المحلية. نحن نعمل جاهدين على إضافة المزيد من اللغات. شاكرين تفهمك ودعمك المستمر لنا.

Compute
Elastic Cloud Server
Huawei Cloud Flexus
Bare Metal Server
Auto Scaling
Image Management Service
Dedicated Host
FunctionGraph
Cloud Phone Host
Huawei Cloud EulerOS
Networking
Virtual Private Cloud
Elastic IP
Elastic Load Balance
NAT Gateway
Direct Connect
Virtual Private Network
VPC Endpoint
Cloud Connect
Enterprise Router
Enterprise Switch
Global Accelerator
Management & Governance
Cloud Eye
Identity and Access Management
Cloud Trace Service
Resource Formation Service
Tag Management Service
Log Tank Service
Config
OneAccess
Resource Access Manager
Simple Message Notification
Application Performance Management
Application Operations Management
Organizations
Optimization Advisor
IAM Identity Center
Cloud Operations Center
Resource Governance Center
Migration
Server Migration Service
Object Storage Migration Service
Cloud Data Migration
Migration Center
Cloud Ecosystem
KooGallery
Partner Center
User Support
My Account
Billing Center
Cost Center
Resource Center
Enterprise Management
Service Tickets
HUAWEI CLOUD (International) FAQs
ICP Filing
Support Plans
My Credentials
Customer Operation Capabilities
Partner Support Plans
Professional Services
Analytics
MapReduce Service
Data Lake Insight
CloudTable Service
Cloud Search Service
Data Lake Visualization
Data Ingestion Service
GaussDB(DWS)
DataArts Studio
Data Lake Factory
DataArts Lake Formation
IoT
IoT Device Access
Others
Product Pricing Details
System Permissions
Console Quick Start
Common FAQs
Instructions for Associating with a HUAWEI CLOUD Partner
Message Center
Security & Compliance
Security Technologies and Applications
Web Application Firewall
Host Security Service
Cloud Firewall
SecMaster
Anti-DDoS Service
Data Encryption Workshop
Database Security Service
Cloud Bastion Host
Data Security Center
Cloud Certificate Manager
Edge Security
Blockchain
Blockchain Service
Web3 Node Engine Service
Media Services
Media Processing Center
Video On Demand
Live
SparkRTC
MetaStudio
Storage
Object Storage Service
Elastic Volume Service
Cloud Backup and Recovery
Storage Disaster Recovery Service
Scalable File Service Turbo
Scalable File Service
Volume Backup Service
Cloud Server Backup Service
Data Express Service
Dedicated Distributed Storage Service
Containers
Cloud Container Engine
SoftWare Repository for Container
Application Service Mesh
Ubiquitous Cloud Native Service
Cloud Container Instance
Databases
Relational Database Service
Document Database Service
Data Admin Service
Data Replication Service
GeminiDB
GaussDB
Distributed Database Middleware
Database and Application Migration UGO
TaurusDB
Middleware
Distributed Cache Service
API Gateway
Distributed Message Service for Kafka
Distributed Message Service for RabbitMQ
Distributed Message Service for RocketMQ
Cloud Service Engine
Multi-Site High Availability Service
EventGrid
Dedicated Cloud
Dedicated Computing Cluster
Business Applications
Workspace
ROMA Connect
Message & SMS
Domain Name Service
Edge Data Center Management
Meeting
AI
Face Recognition Service
Graph Engine Service
Content Moderation
Image Recognition
Optical Character Recognition
ModelArts
ImageSearch
Conversational Bot Service
Speech Interaction Service
Huawei HiLens
Video Intelligent Analysis Service
Developer Tools
SDK Developer Guide
API Request Signing Guide
Terraform
Koo Command Line Interface
Content Delivery & Edge Computing
Content Delivery Network
Intelligent EdgeFabric
CloudPond
Intelligent EdgeCloud
Solutions
SAP Cloud
High Performance Computing
Developer Services
ServiceStage
CodeArts
CodeArts PerfTest
CodeArts Req
CodeArts Pipeline
CodeArts Build
CodeArts Deploy
CodeArts Artifact
CodeArts TestPlan
CodeArts Check
CodeArts Repo
Cloud Application Engine
MacroVerse aPaaS
KooMessage
KooPhone
KooDrive
Help Center/ Cloud Service Engine/ Getting Started/ Connecting Spring Cloud Applications to Nacos Engines Using Spring Cloud SDK

Connecting Spring Cloud Applications to Nacos Engines Using Spring Cloud SDK

Updated on 2024-09-30 GMT+08:00

This section uses a demo to demonstrate how to connect microservice applications to Nacos engines.

  1. Preparations

    You need to register with Huawei Cloud and complete real-name authentication, top up your account, grant permissions, create a VPC and subnet, obtain the demo package, and prepare the local host for compilation, building, and packaging.

  2. Creating a Registry/Configuration Center

    You can select engine specifications, AZs, and networks when creating an engine.

  3. Connecting Spring Cloud Applications to Nacos Engines

    This section describes how to connect a provider service and a consumer service to a Nacos engine.

Preparations

  1. Sign up for a HUAWEI ID and complete real-name authentication.
    Skip this step if you already have a HUAWEI ID, or perform the following steps to create one.
    1. Log in to the Huawei Cloud official website and click Sign Up.
    2. Sign up for a HUAWEI ID. For details, see Signing up for a HUAWEI ID and Enabling Huawei Cloud Services.

      After your ID is created, the system redirects you to your personal information page.

    3. Complete real-name authentication. For details, see Individual Real-Name Authentication.
      NOTE:

      Real-name authentication is required only when you buy or use resources in the Chinese mainland.

  2. Top up your account.

    Ensure that your account has sufficient balance.

  3. Grant permissions.

    You must have the required permissions to create dependent resources and Nacos engines. For details, see Creating a User and Granting Permissions.

    NOTE:

    To create a registry/configuration center, you must have the CSE FullAccess and DNS FullAccess permissions.

  4. Create a VPC and subnet.

    Nacos engines run in a VPC and need to be bound to a subnet. You must have a VPC and subnet to create Nacos engines. For details, see Creating a VPC. Skip this step if you already have a VPC and subnet.

  5. The Java JDK and Maven have been installed on the local host for compilation, building, and packaging, and the Maven central library can be accessed.
  6. Download the demo source code from GitHub to the local host and decompress it.

Creating a Registry/Configuration Center

  1. Go to the Buy Registry/Configuration Center Instance page.
  2. In the left navigation pane, choose Registry/Configuration Center.
  3. Click Buy Registry/Configuration Center Instance.
  4. Set parameters according to the following table. Parameters marked with an asterisk (*) are mandatory. For details, see Creating a Registry/Configuration Center.

    Table 1 Creating a registry/configuration center

    Parameter

    Description

    *Billing Mode

    Billing mode. Currently, Pay-per-use is supported. Pay-per-use is postpaid. You use registry/configuration centers and then pay as billed for your usage duration.

    *Enterprise Project

    Select the enterprise project where the Nacos engine is located. Enterprise projects let you manage cloud resources and users by project. default is selected by default.

    *Name

    Enter a Nacos engine name. The name contains 3 to 64 characters, including letters, digits, and hyphens (-), and starts with a letter but cannot end with a hyphen (-). For example, nacos-test.

    *Registry/Configuration Center Instance

    The registry/configuration center supports Nacos engines.

    NOTE:

    Cluster nodes in the registry/configuration center are evenly distributed to different AZs. A failure of a single node does not affect external services. The registry/configuration center does not support AZ-level DR but provides host-level DR.

    *Instances

    Select the required capacity specifications. In this example, the number of instances is 500, and the number of capacity units is 10.

    Version

    Only the latest version can be created.

    *Network

    Select the created VPC and subnet. You can search for and select a VPC and subnet from the drop-down list.

    A VPC enables you to provision logically isolated, configurable, and manageable virtual networks for your engine.

  5. Click Buy Now. The registry/configuration center starts to be created. When the status is Available, the registry/configuration center is created.

Connecting Spring Cloud Applications to Nacos Engines

  1. Log in to CSE.
  2. Obtain the registry and discovery address of a Nacos engine.

    1. In the left navigation pane, choose Registry/Configuration Center and click the Nacos engine instance.
    2. In the Connection Information area on the Basic Information page, obtain the service center address.

  3. Change the configuration center address, service center address, and microservice name in the demo.

    1. Configure the Nacos configuration center in bootstrap.properties.
      Find the nacos-examples-master\nacos-spring-cloud-example\nacos-spring-cloud-discovery-example\nacos-spring-cloud-consumer-example\src\main\resources file in the demo source code directory downloaded to the local host, add the bootstrap.properties file, and configure the Nacos configuration center.
      spring.cloud.nacos.config.server-addr= XXX.nacos.cse.com:8848 //Address of the Nacos configuration center
      spring.cloud.nacos.config.prefix= example //Prefix of the configuration file name
      spring.cloud.nacos.config.file-extension= properties //Extension of the configuration file name
      spring.cloud.nacos.config.group= XXX //Group to which the configuration file belongs. If this parameter is left blank, the default value DEFAULT_GROUP  is used.
      spring.cloud.nacos.config.namespace= XXX  //ID of the namespace to which the configuration file belongs. If this parameter is left blank, the default value public is used.
    2. Configure the Nacos service center address and microservice name in the application.properties file.
      • Find the nacos-examples-master\nacos-spring-cloud-example\nacos-spring-cloud-discovery-example\nacos-spring-cloud-consumer-example\src\main\resources\application.properties file in the demo source code directory downloaded to the local host and configure the consumer service.
        server.port=8080
        spring.application.name= service-consumer //Microservice name
        spring.cloud.nacos.discovery.server-addr= XXX.nacos.cse.com:8848 //Nacos service center address
        spring.cloud.nacos.discovery.group= XXX  //Group to which the microservice belongs. If this parameter is left blank, the default value DEFAULT_GROUP is used.
        spring.cloud.nacos.discovery.namespace= XXX  //ID of the namespace to which the microservice belongs. If this parameter is left blank, the default value public is used.
        spring.cloud.nacos.discovery.cluster-name= XXX  //Name of the cluster to which the microservice belongs. If this parameter is left blank, the default value DEFAULT is used.
      • Find the nacos-examples-master\nacos-spring-cloud-example\nacos-spring-cloud-discovery-example\nacos-spring-cloud-provider-example\src\main\resources\application.properties file in the demo source code directory downloaded to the local host and configure the provider service.
        server.port=8070
        spring.application.name= service-provider //Microservice name
        spring.cloud.nacos.discovery.server-addr= XXX.nacos.cse.com:8848 //Nacos service center address
        spring.cloud.nacos.discovery.group= XXX  //Group to which the microservice belongs. If this parameter is left blank, the default value DEFAULT_GROUP is used.
        spring.cloud.nacos.discovery.namespace= XXX  //ID of the namespace to which the microservice belongs. If this parameter is left blank, the default value public is used.
        spring.cloud.nacos.discovery.cluster-name= XXX  //Name of the cluster to which the microservice belongs. If this parameter is left blank, the default value DEFAULT is used.

  4. Pack the demo source code into a JAR package.

    1. In the root directory of the demo source code, open the Command Prompt and run the mvn clean package command to package and compile the project.
    2. After the compilation is successful, two JAR packages are generated, as shown in Table 2.
      Table 2 Software packages

      Directory Where the Software Package Is Located

      Package Name

      Description

      \nacos-spring-cloud-consumer-example\target

      nacos-spring-cloud-consumer-example-0.2.0-SNAPSHOT.jar

      Service consumer

      \nacos-spring-cloud-provider-example\target

      nacos-spring-cloud-provider-example-0.2.0-SNAPSHOT.jar

      Service provider

  5. Deploy Spring Cloud applications.

    Deploy provider and consumer on the ECS node in the VPC where the Nacos engine is located.
    1. Create an ECS node in the VPC where the engine instance is located and log in to the ECS node. For details, see Purchasing and Logging In to a Linux ECS.
    2. Install JRE to provide a running environment for services.
    3. Upload the JAR package generated in 4 to the ECS node.
    4. Run the java -jar {JAR package} command to run the generated JAR package.

  6. Confirm the deployment results.

    1. Optional: On the CSE console, choose Registry/Configuration Center and click the Nacos engine created in Creating a Registry/Configuration Center.
    2. Choose Service Management and check the number of instances of microservices service-consumer and service-provider.
      • If Instances is not 0, the demo has been connected to the Nacos engine.
      • If Instances is 0 or the service-consumer and service-provider services cannot be found, the demo fails to be connected to the Nacos engine.

We use cookies to improve our site and your experience. By continuing to browse our site you accept our cookie policy. Find out more

Feedback

Feedback

Feedback

0/500

Selected Content

Submit selected content with the feedback