This topic provides answers to frequently asked questions about sending and receiving messages using software development kits (SDKs).
Can open source clients directly access cloud services?
ApsaraMQ for RabbitMQ is fully compatible with open source RabbitMQ, which allows open source RabbitMQ clients to directly access cloud services. To establish a connection, create a username and password and grant permissions based on the identity verification and permission pattern of your instance. For more information, see Permission Management.
Which programming languages do the open source SDKs support?
ApsaraMQ for RabbitMQ supports all programming languages and frameworks that are supported by open source RabbitMQ SDKs. For more information, see Programming languages and frameworks supported by open source RabbitMQ SDKs over AMQP.
Can I directly use the open source RabbitMQ JMS Client?
ApsaraMQ for RabbitMQ does not currently support the use of the open source RabbitMQ JMS Client.
If automatic ACK is enabled, can I use Reject to requeue a message?
No, you cannot. Use the basicReject method to reject a single message or the basicNack method to reject one or more messages and have them requeued.
How do I set a message ID?
To track and identify messages, you can set the Message ID property on the ApsaraMQ for RabbitMQ producer client to specify a unique identifier for each message. For more information about message IDs, see Message ID.
On the ApsaraMQ for RabbitMQ producer client, you can set the message-id property of Basic.Properties. The following sections provide sample code:
A message ID cannot exceed 255 characters.
Java
AMQP.BasicProperties props = new AMQP.BasicProperties.Builder().messageId("messageid").build();
channel.basicPublish("${ExchangeName}", "RoutingKey", true, props, ("Message Body").getBytes(StandardCharsets.UTF_8));Python
properties = pika.BasicProperties(app_id='example-publisher', content_type='application/json', message_id='messageid')PHP
$msg = new AMQPMessage($msgBody, ['application_headers'=>$amqpTable,'content_type' => 'text/plain', 'delivery_mode' => 2,'message_id' => 'messageid',]);Go
err = ch.Publish( "helloExchange", "hello", false, false, amqp.Publishing { ContentType: "text/plain", Body: []byte(body), MessageId: "messageId", })Node.js
channel.BasicPublish(exchange: "", routingKey: "hello", basicProperties: null, body: body);How do I delete messages from a queue?
You can use the queuePurge method in the Java client library to delete all messages from a specific queue. The following sample code shows how to use the method:
channel.queuePurge("queue-name");How do I set up encrypted transmission on an open source client?
The following example uses port 5672, the default non-encrypted port. To encrypt the transmission, connect to port 5671 and set the SslProtocol of
The SslProtocol of com.rabbitmq.client.ConnectionFactory.
private void setSSL(com.rabbitmq.client.ConnectionFactory factory) throws NoSuchAlgorithmException, KeyStoreException, KeyManagementException {
SSLContext sslContext = SSLContext.getInstance("TLSv1.2");
TrustManagerFactory trustManagerFactory = TrustManagerFactory.getInstance(TrustManagerFactory.getDefaultAlgorithm());
trustManagerFactory.init((KeyStore) null);
sslContext.init(null, trustManagerFactory.getTrustManagers(), null);
factory.useSslProtocol(sslContext);
}What can I do if different consumers have significant differences in memory or CPU utilization because they consume different amounts of data?
This issue can occur because of how connections are distributed across backend service nodes. ApsaraMQ for RabbitMQ uses a distributed deployment with multiple backend nodes, and the gateway uses a polling mechanism to establish connections. If client connections are unevenly distributed, consumers may pull different amounts of data. For example, imagine five clients establishing five connections to three service nodes (A, B, and C). The connections might be distributed unevenly, such as two connections to node A, two to node B, and only one to node C. Because the backend uses a storage-compute separation architecture, each service node pulls a similar amount of data. As a result, the client with the single connection to node C must process all the data pulled by that node, leading to significantly higher resource utilization compared to the other clients.
Solution: Establish multiple connections for each client to ensure they are distributed evenly across the backend nodes. For example, you can establish 50 connections for each client node. This approach balances the amount of data that each client pulls. If your client uses Spring Boot, you can configure the connection mode for consumption.