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
Situation Awareness
Managed Threat Detection
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

SDK Usage Instructions

Updated on 2025-02-14 GMT+08:00

The data subscription function caches data changes of key services in the database and provides a unified SDK API for downstream services to subscribe to, obtain, and consume.

Before using the SDK, create a data subscription task on the DRS console. For details, see Creating a Data Subscription Task.

After a subscription task is created, you can use an SDK to subscribe to incremental data in the subscription task in real time. The following lists the constraints:

  1. DRS only provides SDK JAVA version. For details, see SDK Download Address.
  2. One subscription channel can be consumed by only one SDK. If multiple SDKs are connected to one data subscription channel, only one SDK process can obtain the data change information. If multiple downstream SDKs must subscribe to the same RDS instance, you need to create a data subscription task for each SDK.
  3. A downstream SDK cannot subscribe to and consume multiple subscription tasks.
  4. After data subscription is successful, new data can be retained for a maximum of three days if the data is not consumed in time.
NOTICE:

The SDK JAVA version provided by DRS supports the development environment of JDK 1.6 or later. JDK 1.8 is recommended.

Network Type

Currently, only VPCs are supported.

SDK Working Principles

Data consumption and message confirmation are two asynchronous threads started based on the transaction sequence. The two threads are independent of each other and comply with the causal sequence. The received messages invoke the notify function registered by users in sequence. The SDK ensures that each message is pushed only once.

Importing SDK JAR Package

The SDK JAR package can be directly imported only through the library. Currently, the Maven central repository is not supported.

<dependency>
<groupId>com.huawei.hwclouds</groupId>
<artifactId>drs-subscribe-sdk</artifactId>
<version>1.0</version>
</dependency>

Configuring Parameters

During data subscription, some parameters affect the speed and interval for obtaining data.

Before starting the SDK, you can set the following parameters in the subscribe.properties configuration file as required:

#Initial delay for obtaining the subscription data
MESSAGE_DELAY_TIME = 1500000
#Interval for obtaining the subscription data
MESSAGE_PERIOD_TIME = 2000000
#Notify the user that the subscription data initial delay
NOTIFY_DELAY_TIME = 2000
#Notify the user of the subscription data interval
NOTIFY_PERIOD_TIME = 1000
#Initial delay of the ACK messages from the server
ACK_DELAY_TIME = 3000
#Interval between the ACK messages from the server
ACK_PERIOD_TIME = 5000
NOTE:
  • The preceding parameter values are set by default. You can also customize parameter values based on the site requirements.
  • The unit of the time mentioned above is microsecond.

Confirmation Mechanism

The SDK uses the automatic batch confirmation mechanism. The client program does not need to invoke the confirmation function and can be confirmed repeatedly.

For example: the client receives five batches of messages, and the server only confirms the first, the second, and the fifth batch, respectively. Messages are confirmed in sequence. Therefore, it indicates that the client has consumed all messages in the first to fifth batch. If the client program is suspended, the consumption checkpoint starts from the fifth batch.

SDK Template

import com.huawei.hwclouds.drs.context.SubscribeContext;
import com.huawei.hwclouds.drs.message.ClusterMessage;
import com.huawei.hwclouds.drs.subscribe.ClusterListener;
import com.huawei.hwclouds.drs.subscribe.DefaultSubscribeClient;
import com.huawei.hwclouds.drs.subscribe.SubscribeClient;
import java.util.List;
public class MainClass {
public static void main(String[] args) throws Exception {
SubscribeContext context = new SubscribeContext();
//There will be security risks if the username and password used for authentication are directly written into code. Store the username and password in ciphertext in the configuration file or environment variables.
//In this example, the username and password are stored in the environment variables. Before running this example, set environment variables EXAMPLE_USERNAME_ENV and EXAMPLE_PASSWORD_ENV based on site requirements.
//Set a Username of the current cloud account.
String username = System.getenv("EXAMPLE_USERNAME_ENV");
context.setDomainName(username);
//Set the Password of the current cloud account.
String userpassword = System.getenv("EXAMPLE_PASSWORD_ENV");
context.setPassword(userpassword);
//Set the IP address of the subscription instance on the Data Subscription Management page.
context.setIp("SubscribeChannelIp");
context.setUserId("userId");
SubscribeClient client =
DefaultSubscribeClient.getSubscribeClient(context);
ClusterListener clusterListener = new ClusterListener() {
@Override
//Client consumption behavior defined in notify
public void notify(List<ClusterMessage> var1) throws Exception {
for (ClusterMessage message : var1) {
System.out.println("Message is " + message.toString());
}
}
public void onException(Exception e) {
    e.printStackTrace();
}
};
client.addClusterListener(clusterListener);
client.start();
}
}

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