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

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

Java Demo Usage Guide

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

This topic uses Java as an example to describe how to connect an MQTTS client to the platform and receive subscribed messages from the platform.

Prerequisites

You have installed IntelliJ IDEA by following the instructions provided in For details about the installation, see Installing IntelliJ IDEA.

Installing IntelliJ IDEA

  1. Go to the IntelliJ IDEA website to download and install a desired version. The following uses 64-bit IntelliJ IDEA 2019.2.3 Ultimate as an example.

  2. After the download is complete, run the installation file and install Node.js as prompted.

Importing Sample Code

  1. Download the Java demo.
  2. Open the IDEA developer tool and click Import Project.

  3. Select the Java demo downloaded in 1 and click Next.

  4. Import the sample code.

Establishing a Connection

  1. Set the access address and authentication parameters in com.iot.mqtt.example.demo.MqttConstants.

    // Address for connecting the MQTT client to the platform. Replace it with the MQTT access domain name in "Connection Configuration Parameters".
    String HOST = "${HOST}";
    // Access credential. Replace it with the access credential obtained in "Obtaining the MQTT Access Credential".
    String ACCESS_KEY = "${accessKey}";
    String ACCESS_CODE = "${accessCode}";
    // Instance ID. This parameter is mandatory when multiple standard instances are purchased in the same region.
    String INSTANCE_ID = "${instanceId}";
    // Topic for receiving data. Replace it with the topic used for rule action creation.
    String SUBSCRIBE_TOPIC = "${subscribeTopic}";
    NOTE:

    For details about the parameters in the demo, see Connection Configuration Parameters.

  2. Run the sample code (com.iot.mqtt.example.demo.MqttDemo) and check whether the subscription is successful based on the log information. This example does not involve the server certificate verification. For details about how to verify the server certificate, see com.iot.mqtt.example.demo.MqttTlsDemo.

    • Successful subscription
      Figure 1 Successful subscription
    • Failed subscription
      1. The username or password is incorrect.
        Figure 2 Incorrect username or password
      2. The topic does not exist.
        Figure 3 The topic does not exist

Receiving Data

After topic subscription, when a device reports data and a rule is triggered, the MQTT client can receive the forwarded data. The following figure shows the logs generated when the forwarded data is received.

Figure 4 Receiving the forwarded data

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