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
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

Accessing RabbitMQ on a Client (SSL Disabled)

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

This section takes the example of a demo of DMS for RabbitMQ to describe how to access a RabbitMQ instance with SSL disabled on a RabbitMQ client for message production and consumption.

Prerequisites

  • A RabbitMQ instance with SSL disabled has been created following the instructions in Buying a RabbitMQ Instance. The username and password entered in the instance creation have been obtained.
  • Instance Address (Private Network) or Instance Address (Public Network) has been recorded.
  • The network between the client server and the RabbitMQ instance has been established. For details about network requirements, see RabbitMQ Network Connection Requirements.
  • JDK v1.8.111 or later has been installed on the client server, and the JAVA_HOME and PATH environment variables have been configured as follows:

    Add the following lines to the .bash_profile file in the home directory as an authorized user. In this command, /opt/java/jdk1.8.0_151 is the JDK installation path. Change it to the path where you install JDK.

    export JAVA_HOME=/opt/java/jdk1.8.0_151 
    export PATH=$JAVA_HOME/bin:$PATH

    Run the source .bash_profile command for the modification to take effect.

  • In the RabbitMQ instance: A virtual host, exchange, and queue have been created and an exchange-queue binding has been configured.

Accessing the Instance in CLI Mode

  1. Log in to the client server.
  2. Run the following command to download RabbitMQ-Tutorial.zip (code package of the sample project):

    wget https://dms-demo.obs.cn-north-1.myhuaweicloud.com/RabbitMQ-Tutorial.zip

  3. Run the following command to decompress RabbitMQ-Tutorial.zip:

    unzip RabbitMQ-Tutorial.zip

  4. Run the following command to navigate to the RabbitMQ-Tutorial directory, which contains the precompiled JAR file:

    cd RabbitMQ-Tutorial

  5. Create messages using the sample project.

    java -cp .:rabbitmq-tutorial.jar Send {host} {port} {user} {password}

    Parameter description:

    • {host}: connection address obtained in Prerequisites
    • {port}: port of the RabbitMQ instance. Enter 5672.
    • {user}: username obtained in Prerequisites
    • {password}: password obtained in Prerequisites

    Sample message production:

    [root@ecs-test RabbitMQ-Tutorial]# java -cp .:rabbitmq-tutorial.jar Send 192.168.xx.40 5672 test Zxxxxxxs
     [x] Sent 'Hello World!'
    [root@ecs-test RabbitMQ-Tutorial]# java -cp .:rabbitmq-tutorial.jar Send 192.168.xx.40 5672 test Zxxxxxxs
     [x] Sent 'Hello World!'

  6. Retrieve messages using the sample project.

    java -cp .:rabbitmq-tutorial.jar Recv {host} {port} {user} {password}

    Parameter description:

    • {host}: connection address obtained in Prerequisites
    • {port}: port of the RabbitMQ instance. Enter 5672.
    • {user}: username obtained in Prerequisites
    • {password}: password obtained in Prerequisites

    Sample message consumption:

    [root@ecs-test RabbitMQ-Tutorial]# java -cp .:rabbitmq-tutorial.jar Recv 192.168.xx.40 5672 test Zxxxxxxs
     [*] Waiting for messages. To exit press CTRL+C
     [x] Received 'Hello World!'
     [x] Received 'Hello World!'

    To stop retrieving messages, press Ctrl+C to exit.

Java Sample Code

  • Accessing an instance and producing messages
    • VHOST_NAME: name of the virtual host that contains the queue for messages to be sent to
    • QUEUE_NAME: name of the queue for messages to be sent to
    • Hello World!: the message to be sent in this sample
    ConnectionFactory factory = new ConnectionFactory();
     factory.setHost(host);
     factory.setPort(port);
     factory.setVirtualHost("VHOST_NAME");
    
     factory.setUsername(user);
     factory.setPassword(password);
     Connection connection = factory.newConnection();
     Channel channel = connection.createChannel();
    
     channel.queueDeclare(QUEUE_NAME, false, false, false, null);
    
     String message = "Hello World!";
     channel.basicPublish("", QUEUE_NAME, null, message.getBytes("UTF-8"));
     System.out.println(" [x] Sent '" + message + "'");
    
     channel.close();
     connection.close();
  • Accessing an instance and consuming messages
    • VHOST_NAME: name of the virtual host that contains the queue to consume messages
    • QUEUE_NAME: name of the queue to consume messages
    ConnectionFactory factory = new ConnectionFactory();
     factory.setHost(host);
     factory.setPort(port);
     factory.setVirtualHost("VHOST_NAME");
     factory.setUsername(user);
     factory.setPassword(password);
     Connection connection = factory.newConnection();
     Channel channel = connection.createChannel();
    
     channel.queueDeclare(QUEUE_NAME, false, false, false, null);
     System.out.println(" [*] Waiting for messages. To exit press CTRL+C");
    
     Consumer consumer = new DefaultConsumer(channel)
     {
         @Override
         public void handleDelivery(String consumerTag, Envelope envelope, AMQP.BasicProperties properties,
                 byte[] body)
                 throws IOException
         {
             String message = new String(body, "UTF-8");
             System.out.println(" [x] Received '" + message + "'");
         }
     };
     channel.basicConsume(QUEUE_NAME, true, consumer);

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