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

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
Help Center/ ROMA Connect/ Developer Guide/ Developer Guide for Data Integration/ (Example) Developing a Custom Data Source for a Real-Time Task

(Example) Developing a Custom Data Source for a Real-Time Task

Updated on 2024-10-10 GMT+08:00

Scenarios

Custom connectors can access real-time data sources through message forwarding. This section uses an MQS data source and Java as an example. Refer to RealtimeConnector.rar for demo code.

Prerequisites

  • A Linux server that runs JDK 1.8 or later is available.
  • IntelliJ IDEA: 2018.3.5 or later; Eclipse: 3.6.0 or later
  • Obtain MysqlConnctor.rar from the demo (sha256:34c9bc8d99eba4ed193603019ce2b69afa3ed760a452231ece3c89fd7dd74da1) package.
  • The TPS for user programs to write messages to MQS cannot exceed 6000.

Procedure

  1. Create a Spring Boot template project, start real-time data source consumption in the Main method, and use the MQS SDK to produce the consumed data to MQS.

    Sample code:

    @SpringBootApplication
    public class RealtimeConnectorApplication {
        private static final Logger LOGGER = LoggerFactory.getLogger(RealtimeConnectorApplication.class);
    
        public static void main(String[] args) throws MQClientException {
            DefaultMQPushConsumer rocketMQConsumer = createRocketMQConsumer();
            MqsProducer mqsProducer = new MqsProducer();
            MessageListenerConcurrently rocketmqMessageListener = new MessageListenerConcurrently() {
                @Override
                public ConsumeConcurrentlyStatus consumeMessage(List<MessageExt> messageList,
                    ConsumeConcurrentlyContext context) {
                    for (MessageExt message : messageList) {
                        String jsonString = convertMessageToJsonString(message);
                        //Write JSON data to MQS. mqs-topic indicates the created topic, which will be consumed by FDI tasks.
                        mqsProducer.produce("mqs-topic", jsonString);
                    }
                    LOGGER.info("Success to process {} data", messageList.size());
                    //Mark the message as consumed.
                    return ConsumeConcurrentlyStatus.CONSUME_SUCCESS;
                }
            };
            //Register the callback implementation class to process the messages obtained from RocketMQ.
            rocketMQConsumer.registerMessageListener(rocketmqMessageListener);
            //Start RocketMQ consumption.
            rocketMQConsumer.start();
        }
     
        private static DefaultMQPushConsumer createRocketMQConsumer() throws MQClientException {
            //Instantiate the RocketMQ consumer. Enter the actual consumer group name.
            DefaultMQPushConsumer consumer = new DefaultMQPushConsumer("myCompanyGroup");
            //Set the NameServer IP address.
            consumer.setNamesrvAddr("localhost:9876");
            //Subscribe to one or more topics and use tags to filter messages to consume.
            consumer.subscribe("RocketMQTopic", "*");
            return consumer;
        }
     
        /**
         * Convert the messages read by RocketMQ into JSON strings. The actual conversion is implemented based on the RocketMQ message content.
         *
         * @param messageExt
         * @return
         */
        private static String convertMessageToJsonString(MessageExt messageExt) {
            JSONObject jsonObject = new JSONObject();
            jsonObject.put("id", 1);
            jsonObject.put("name", "zhangsan");
            return jsonObject.toJSONString();
        }
    }
  2. Run the following command in the root directory to generate an executable JAR package, for example, RealtimeConnector-1.0-SNAPSHOT.jar, in RealtimeConnector\target.

    # mvn package

  3. Use Linux or Windows to upload the RealtimeConnector-1.0-SNAPSHOT.jar package to the user server that runs JDK, and run the following command:

    # java -jar RealtimeConnector-1.0-SNAPSHOT.jar &

  4. The following uses an MQS data source as the source and MySQL as the destination to describe how to create a real-time task.

    Connect the MQS data source at the source and the MySQL data source at the destination and create a real-time task. For details, see Creating a Common Data Integration Task. After the configuration is complete, run the task to migrate data from the MQS data source to MySQL tables.

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

Feedback

Feedback

Feedback

0/500

Selected Content

Submit selected content with the feedback