This topic provides answers to frequently asked questions (FAQ) when you use SDKs to send and receive messages.

Can open source RabbitMQ clients directly access Alibaba Cloud services?

Message Queue for RabbitMQ is compatible with open source RabbitMQ. Open source RabbitMQ clients can directly access Alibaba Cloud services. You must first generate a pair of static username and password in the Message Queue for RabbitMQ console. Then, your client can use the pair of static username and password to directly access Alibaba Cloud services. For more information about how to create a pair of static username and password, see Create a static username/password pair.

Which programming languages that open source RabbitMQ SDK supports are supported by Message Queue for RabbitMQ?

Message Queue for RabbitMQ supports all the programming languages or frameworks supported by open source RabbitMQ. For more information, see Table 1.

Can I directly use open source RabbitMQ JMS clients in Message Queue for RabbitMQ?

Message Queue for RabbitMQ does not allow you to directly use open source RabbitMQ Java Message Service (JMS) clients. You must first add dependencies to your Maven project. Then, you can use an open source RabbitMQ JMS client to access Message Queue for RabbitMQ and send and receive messages. For more information about how to add dependencies to your Maven project to send and receive messages, see Overview.

Which interfaces are not supported by the JMS standard?

Message Queue for RabbitMQ supports JMS 1.1. For more information about compatible interfaces, see Compatibility.

Can messages be rejected and requeued if automatic ACK is used?

No, messages cannot be rejected or requeued if automatic acknowledgment (ACK) is used. You can use the basicReject method to reject and requeue a single message or use the basicNack method to reject and requeue one or more messages.

Parameter Description
deliveryTag The unique identifier for the delivery of a message on the channel.
requeue Specifies whether to requeue the rejected message. If you set this parameter to true, the rejected message is requeued. If you set this parameter to false, the rejected message is discarded or sent to a dead-letter exchange. For more information, see Dead-letter exchanges.
Sample code
channel.basicConsume("test", false, "consumertag", new DefaultConsumer(channel) {
   @Override
    public void handleDelivery(String consumerTag, Envelope envelope,
                      AMQP.BasicProperties properties, byte[] body)
            throws IOException {
        System.out.println("Rejected: " + new String(body, "UTF-8") + ", deliveryTag: " + envelope.getDeliveryTag() + ", messageId: " + properties.getMessageId());
        channel.basicReject(envelope.getDeliveryTag(), true);
    }
});
Parameter Description
deliveryTag The unique identifier for the delivery of a message on the channel.
multiple Specifies whether to reject multiple messages. If you set this parameter to true, unacknowledged delivered messages up to and including the message with the specified delivery tag are rejected. If you set this parameter to false, only the message with the specified delivery tag is rejected.
requeue Specifies whether to requeue the rejected messages. If you set this parameter to true, the rejected messages are requeued. If you set this parameter to false, the rejected messages are discarded or sent to dead-letter exchanges. For more information, see Dead-letter exchanges.
Sample code
channel.basicConsume("test", false, "consumertag", new DefaultConsumer(channel) {
   @Override
    public void handleDelivery(String consumerTag, Envelope envelope,
                      AMQP.BasicProperties properties, byte[] body)
            throws IOException {
        System.out.println("Rejected: " + new String(body, "UTF-8") + ", deliveryTag: " + envelope.getDeliveryTag() + ", messageId: " + properties.getMessageId());
        channel.basicNack(envelope.getDeliveryTag(), true, true);
    }
});

How do I specify a message ID?

To track and identify messages, you can specify a message ID for each message on Message Queue for RabbitMQ producers.

Specify message IDs in the message-id property in Basic.Properties on Message Queue for RabbitMQ producers. The following code provides examples on how to specify a message ID:

AMQP.BasicProperties props = new AMQP.BasicProperties.Builder().messageId("messageid").build(); channel.basicPublish("${ExchangeName}", "BindingKey", true, props, ("Send message body").getBytes(StandardCharsets.UTF_8));

properties = pika.BasicProperties(app_id='example-publisher', content_type='application/json', 'message_id'='messageid')

$msg = new AMQPMessage($msgBody, ['application_headers'=>$amqpTable,'content_type' => 'text/plain', 'delivery_mode' => 2,'message_id' => 'messageid',]);

err = ch.Publish( "helloExchange", "hello", false, false, amqp.Publishing { ContentType: "text/plain", Body: []byte(body), MessageId: "messageId", })

channel.BasicPublish(exchange: "", routingKey: "hello", basicProperties: null, body: body);

How do I delete messages from a queue?

You call the queuePurge method in the Java client library to delete all messages from a queue. The following code provides an example on how to call the queuePurge method:

channel.queuePurge("queue-name");