tencent cloud

TDMQ for RabbitMQ

Release Notes and Announcements
Release Notes
Announcements
Product Introduction
Introduction and Selection of the TDMQ Product Series
What Is TDMQ for RabbitMQ
Strengths
Use Cases
Description of Differences Between Managed Edition and Serverless Edition
Open-Source Version Support Description
Comparison with Open-Source RabbitMQ
High Availability
Use Limits
TDMQ for RabbitMQ-Related Concepts
Regions
Related Cloud Services
Billing
Billing Overview
Pricing
Billing Example
Convert to Monthly Subscription from Hourly Postpaid
Renewal
Viewing Consumption Details
Overdue Payments
Refund
Getting Started
Getting Started Guide
Step 1: Preparations
Step 2: Creating a RabbitMQ Cluster
Step 3: Configuring a Vhost
Step 4: Using the SDK to Send and Receive Messages
Step 5: Querying a Message
Step 6: Deleting Resources
User Guide
Usage Process Guide
Configuring the Account Permission
Creating a Cluster
Configuring a Vhost
Connecting to the Cluster
Managing Messages
Configure Advanced Feature
Managing the Cluster
Viewing Monitoring Data and Configuring Alarm Policy
Use Cases
Use Instructions of Use Cases
RabbitMQ Client Use Cases
RabbitMQ Message Reliability Use Cases
Usage Instructions for MQTT Protocol Supported by RabbitMQ
Migrate Cluster
Migrating RabbitMQ to Cloud
Step 1. Purchasing a TDMQ Instance
Step 2: Migrating Metadata to the Cloud
Step 3: Enabling Dual Read-Write
API Reference (Managed Edition)
API Overview
API Reference (Serverless Edition)
History
Introduction
API Category
Making API Requests
Relevant APIs for RabbitMQ Serverless PAAS Capacity
RabbitMQ Serverless Instance Management APIs
Data Types
Error Codes
SDK Documentation
SDK Overview
Spring Boot Starter Integration
Spring Cloud Stream Integration
Java SDK
Go SDK
Python SDK
PHP SDK
Security and Compliance
Permission Management
Network Security
Deletion Protection
Change Records
CloudAudit
FAQs
Service Level Agreement
Contact Us
DokumentasiTDMQ for RabbitMQSDK DocumentationSpring Boot Starter Integration

Spring Boot Starter Integration

PDF
Mode fokus
Ukuran font
Terakhir diperbarui: 2026-01-05 11:19:43

Scenarios

This document introduces how to use an open-source SDK (taking the Spring Boot Starter SDK as an example) to send and receive messages, so as to help you better understand the complete process of sending and receiving messages.

Prerequisites

You have obtained the related client connection parameters as instructed in SDK Overview.

Operation Steps

Step 1: Adding Dependencies

Add dependencies to pom.xml.
<!--rabbitmq-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-amqp</artifactId>
</dependency>

Step 2: Preparing Configurations

1. Add RabbitMQ configuration information to the configuration file (taking the YAML configuration as an example).
spring:
rabbitmq:
# The host address can be obtained in the console, or use the RabbitMQ service address.
host: 1.14.235.155
port: 5672
# The name of the role to be used can be obtained from the role management console.
username: admin
# Role token.
password: eyJrZXlJZ....
# The full name of the vhost can be obtained from the vhost tab in the cluster console.
virtual-host: test_vhost
Parameter
Description
host
Cluster access address, which can be obtained from the Client Access module on the basic cluster information page.
port
Cluster access address port, which can be obtained from the Client Access module on the basic cluster information page.
username
Username. Enter the username created in the console.
password
User password. Enter the password specified during user creation in the console.
virtual-host
Vhost name, which can be obtained from the vhost list in the console.
2. Create a configuration file loading program (taking the fanout exchange as an example).
Note:
For configuration details of other types of exchanges, see Demo.
/**
* Fanout exchange configuration.
*/
@Configuration
public class FanoutRabbitConfig {

/**
* Exchange.
*/
@Bean
public FanoutExchange fanoutExchange() {
return new FanoutExchange("fanout-logs", true, false);
}


/**
* Message queue.
*/
@Bean
public Queue fanoutQueueA() {
return new Queue("ps_queue", true);
}

@Bean
public Queue fanoutQueueB() {
// The dead letter queue can be bound in this way.
Map<String, Object> requestParam = new HashMap<>();
requestParam.put("x-dead-letter-exchange", "my-deadLetter-exchange");
// Set the message expiration period.
requestParam.put("x-message-ttl", 60000);
return new Queue("ps_queue1", true, false,true, requestParam);
}

/**
* Bind the message queue to the exchange.
*/
@Bean
public Binding bindingFanoutA() {
return BindingBuilder.bind(fanoutQueueA())
.to(fanoutExchange());
}

@Bean
public Binding bindingFanoutB() {
return BindingBuilder.bind(fanoutQueueB())
.to(fanoutExchange());
}
}
Parameter
Description
fanout-logs
Name of the bound exchange, which can be obtained from the exchange list in the console.
ps_queue
Name of the first queue bound to the exchange, which can be obtained from the queue list in the console.
my-deadLetter-exchange
Dead letter exchange name, which can be obtained from the exchange list in the console.
ps_queue1
Name of the second queue bound to the exchange, which can be obtained from the queue list in the console.

Step 3: Sending Messages

Create and compile the message sending program DemoApplication.java, and use RabbitTemplate to send messages.
@Autowired
private RabbitTemplate rabbitTemplate;

public String send() {
String msg = "This is a new message.";
// Send a message.
// Parameter description: Parameter 1 (exchange name, which can be obtained from the exchange list in the console); parameter 2 (Routing Key); parameter 3 (message content).
rabbitTemplate.convertAndSend("direct_logs", "", msg);
return "success";
}

Step 4: Consuming Messages

Create and compile the message receiving program FanoutReceiver.java (taking the fanout exchange as an example).
@Component
public class FanoutReceiver {
// Register a listener to listen to the specified message queue.
@RabbitHandler
@RabbitListener(queues = "test_queue") //Name of the queue bound to the exchange, which can be obtained from the queue list in the console.
public void listenerPsQueue(String msg) {
// Business processing...
System.out.println("(ps_queue) receiver message. [" + msg + "]");
}
}

Step 5: Viewing Messages

If you want to confirm whether the message is successfully sent to TDMQ for RabbitMQ, you can log in to the console and choose Cluster > Queue to go to the basic information page to view the details of consumers accessing the cluster.

Note:
For other usage examples, see the Spring AMQP official website.


Bantuan dan Dukungan

Apakah halaman ini membantu?

masukan