หน้านี้ยังไม่พร้อมใช้งานในภาษาท้องถิ่นของคุณ เรากำลังพยายามอย่างหนักเพื่อเพิ่มเวอร์ชันภาษาอื่น ๆ เพิ่มเติม ขอบคุณสำหรับการสนับสนุนเสมอมา

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
On this page

Connecting Java Chassis Applications to CSE Engines

Updated on 2024-05-06 GMT+08:00

This section describes how to connect Java chassis applications to CSE engines and use the most common functions of CSE engines. For details about the development guide, see Using Microservice Engine Functions.

In the Apache ServiceComb Samples project, you can find the code corresponding to the development methods in this section.

Prerequisites

  • Microservice applications have been developed based on Java chassis.

    For details about microservice application development in the Java chassis framework, see https://servicecomb.apache.org/references/java-chassis/en_US/.

  • Version requirements. See Requirements for Microservice Development Framework of a.
  • This document assumes that you use Maven for dependency management and packaging in your project. You are familiar with the Maven dependency management mechanism and are able to modify the dependency management and dependency in the pom.xml file.
  • Java chassis can be used together with different technologies. The name of the configuration file is related to the technology you use. For example, if you use Java chassis in Spring mode, the configuration file name is microservice.yaml. If you use Java chassis in Spring Boot mode, the configuration file name is application.yaml. This document uses microservice.yaml to indicate the configuration file. You need to use a configuration file name corresponding to your project.

Procedure

  1. Add dependencies to the pom.xml file of the project.

    <dependency>
        <groupId>org.apache.servicecomb</groupId>
        <artifactId>solution-basic</artifactId>
    </dependency>
    <dependency>
        <groupId>org.apache.servicecomb</groupId>
        <artifactId>servicestage-environment</artifactId>
    </dependency>
    NOTE:
    • The solution-basic module contains common Java chassis functions, such as the configuration center module and service governance module, which allow you to enable these functions in one-click.
      <!-- Configuration center module -->
      <dependency>
      <groupId>org.apache.servicecomb</groupId>
      <artifactId>config-cc</artifactId>
      </dependency>
      <!-- Service governance module -->
      <dependency>
      <groupId>org.apache.servicecomb</groupId>
      <artifactId>handler-governance</artifactId>
      </dependency>
    • The servicestage-environment module consists of the following dependent module:
      <!-- Registry and discovery module -->
      <dependency>
        <groupId>org.apache.servicecomb</groupId>
        <artifactId>registry-service-center</artifactId>
      </dependency>

    You are advised to use Maven Dependency Management to manage the third-party software dependencies of a project. Add the following information to the pom.xml file of the project:

    <dependencyManagement>
        <dependencies>
          <dependency>
            <groupId>org.apache.servicecomb</groupId>
            <artifactId>java-chassis-dependencies</artifactId>
            <version>${java-chassis.version}</version>
            <type>pom</type>
            <scope>import</scope>
          </dependency>
        </dependencies>  
    </dependencyManagement>

    Skip the operation if your project already contains the preceding dependencies.

    The servicestage-environment software package is optional. This software package provides the environment variable mapping function. When you use ServiceStage to deploy applications, you do not need to manually modify information such as the registry center address, configuration center address, and project name. The default configurations in the microservice.yaml file are overwritten by environment variables. The mapping.yaml file is contained in the software package. You can also add the mapping.yaml file to your own project.

    NOTE:

    The mapping.yaml file may change in later versions to support the latest functions of CSE engines. If you do not want the new version to evolve with CSE engines, you can add the mapping.yaml file to your project instead of adding the servicestage-environment dependency.

    Generally, the microservice.yaml and mapping.yaml files are stored in the /src/main/resources/ directory in the root directory of the current project.

    PAAS_CSE_ENDPOINT:
      - servicecomb.service.registry.address
      - servicecomb.config.client.serverUri
    PAAS_CSE_SC_ENDPOINT:
      - servicecomb.service.registry.address
    PAAS_CSE_CC_ENDPOINT:
      - servicecomb.config.client.serverUri
    PAAS_PROJECT_NAME:
      - servicecomb.credentials.project
    
    # CAS_APPLICATION_NAME:
    #  - servicecomb.service.application
    # CAS_COMPONENT_NAME:
    #  - servicecomb.service.name
    # CAS_INSTANCE_VERSION:
    #  - servicecomb.service.version

    Common software packages are added to solution-basic, and the default microservice.yaml file is provided. This configuration file configures common Handlers and parameters as follows:

    # order of this configure file
    servicecomb-config-order: -100
    
    servicecomb:
    
    # handlers
      handler:
        chain:
          Provider:
            default: qps-flowcontrol-provider
          Consumer:
            default: qps-flowcontrol-consumer,loadbalance,fault-injection-consumer
    
    # loadbalance strategies
      references:
        version-rule: 0+
      loadbalance:
        retryEnabled: true
        retryOnNext: 1
        retryOnSame: 0
    
    # metrics and access log
      accesslog:
        enabled: true
      metrics:
        window_time: 60000
        invocation:
          latencyDistribution: 0,1,10,100,1000
        Consumer.invocation.slow:
          enabled: true
          msTime: 1000
        Provider.invocation.slow:
          enabled: true
          msTime: 1000
        publisher.defaultLog:
          enabled: true
          endpoints.client.detail.enabled: true

    servicecomb-config-order is set to -100 in the microservice.yaml configuration file, indicating that the priority of the configuration file is low. (A larger order indicates a higher priority. The default value is 0.) If the same configuration item is added to the service, the configuration will be overwritten.

    NOTE:

    The microservice.yaml file may change in later versions to support the latest functions of CSE engines. If you do not want the new version to evolve with CSE engines, you can write the configuration items to your own microservice.yaml file.

  2. (Optional) Configure the AK/SK.

    Perform this step only when you use the professional microservice engine.

    The AK/SK is configured in the microservice.yaml file. ServiceComb provides plaintext configuration by default and allows you to customize the encryption storage scheme. For details about how to obtain the AK/SK and project name, see Obtaining the AK/SK and Project Name.

    • Add the following configuration in plaintext to the microservice.yaml file:
        servicecomb:  
          credentials:
            accessKey: AK #Enter the AK.
            secretKey: SK #Enter the SK.
            project: Project name #Enter the project name.
            akskCustomCipher: default
    • Implement the org.apache.servicecomb.foundation.auth.Cipher API using either of the following methods:
      • String name()

        Name definition of servicecomb.credentials.akskCustomCipher, which needs to be added to the configuration file.

      • char[] decode(char[] encrypted)

        Decrypt the API, which is used after secretKey is decrypted.

      The implementation class must be declared as SPI. For example:

      package com.example
      public class MyCipher implements Cipher

      Create an SPI configuration file. The file name and path are META-INF/serivce/org.apache.servicecomb.foundation.auth.Cipher, and the file content is as follows:

      com.example.MyCipher

      Add the following configuration to the microservice.yaml file:

      servicecomb:
        credentials:
          accessKey: AK #Enter the AK.
          secretKey: SK #Enter the encrypted SK.
          project: Project name #Enter the project name.
          akskCustomCipher: youciphername #Enter the returned name of the name() method in the implementation class.
    NOTE:

    If you do not want to write the AK/SK into the configuration file, use either of the following environment variable methods. For details, see Method 2.

    • Use environment variables. The OS environment variable name cannot contain periods (.). The Java chassis can automatically process the environment variable servicecomb_credentials_accessKey and map it to servicecomb.credentials.accessKey.
    • Add the mapping.yaml file and customize the environment variable name. For details about this method, see the servicestage-environment module in 1.

  3. (Optional) Configure security authentication parameters.

    Perform this step only when you use the exclusive microservice engine and enable security authentication. In other scenarios, skip this step.

    After security authentication is enabled for a microservice engine, all called APIs can be called only after a token is obtained. For details about the authentication process, see RBAC.

    To use security authentication, obtain the username and password from the microservice engine and then add the following configuration to the configuration file.

    servicecomb:
      credentials:
        rbac.enabled: true
        account:
          name: your account name # Username obtained from the microservice engine
          password: your password # Password obtained from the microservice engine
        cipher: default # Returned name of the name() method in the implementation class of API org.apache.servicecomb.foundation.auth.Cipher

    cipher specifies the name of the algorithm used to encrypt the password. By default, the password is stored in plaintext. The encryption is implemented through customization. The details are as follows:

    • Implement the org.apache.servicecomb.foundation.auth.Cipher API using either of the following methods:
      • String name()

        Name definition of servicecomb.credentials.cipher, which needs to be added to the configuration file.

      • char[] decode(char[] encrypted)

        Decrypt the API, which is used after secretKey is decrypted.

      The implementation class must be declared as SPI. For example:

      package com.example
      public class MyCipher implements Cipher

      Create an SPI configuration file. The file name and path are META-INF/serivce/org.apache.servicecomb.foundation.auth.Cipher, and the file content is as follows:

      com.example.MyCipher

      Add the following configuration to the microservice.yaml file:

      servicecomb:
        credentials:
          rbac.enabled: true
          account:
            name: your account name 
            password: your password # Encrypted password
          cipher: youciphername # Returned name of the name() method in the implementation class
    NOTE:
    • Plaintext storage cannot ensure security. You are advised to encrypt the password.
    • You can also use environment variables to configure the username and password, which is the same as configuring the AK/SK. For details, see Java Chassis.
    • If you use the professional microservice engine, the watch function is not available. You need to disable the watch function in the configuration file. Otherwise, error logs will be periodically printed. In the service center, set watch to false. In the configuration center, set refreshMode to 1.
      servicecomb:
        service:
          application: porter-application
          name: user-service
          version: 0.0.1
          registry:
            address: http://localhost:30100
            instance:
              watch: false
        config:
          client:
            serverUri: http://localhost:30103
            refreshMode: 1

เราใช้คุกกี้เพื่อปรับปรุงไซต์และประสบการณ์การใช้ของคุณ การเรียกดูเว็บไซต์ของเราต่อแสดงว่าคุณยอมรับนโยบายคุกกี้ของเรา เรียนรู้เพิ่มเติม

Feedback

Feedback

Feedback

0/500

Selected Content

Submit selected content with the feedback