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?

ApsaraMQ 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 ApsaraMQ 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 Manage static usernames and passwords.

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

ApsaraMQ for RabbitMQ supports all the programming languages or frameworks supported by open source RabbitMQ. For more information, see Programming languages and frameworks supported by open source RabbitMQ SDK over AMQP.

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

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

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

If automatic ACK is enabled, can I use the Reject method to requeue a message?

No, you cannot. You can use the basicReject method to reject and requeue a message or use the basicNack method to reject and requeue one or more messages.

  • Call the basicReject method to reject and requeue a message
    ParameterDescription
    deliveryTagThe unique identifier that is used to deliver messages in the channel.
    requeueSpecifies 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 the dead-letter exchange. For more information, see Dead-letter exchange.
  • Call the basicNack method to reject and requeue one or more messages
    ParameterDescription
    deliveryTagThe unique identifier that is used to deliver messages in the channel.
    multipleSpecifies whether to reject multiple messages. If you set this parameter to true, the message with the specified delivery tag and unacknowledged messages before the specified delivery tag are rejected. If you set this parameter to false, only the message with the specified delivery tag is rejected.
    requeueSpecifies 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 the dead-letter exchange. For more information, see Dead-letter exchange.

    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 unique ID for each message on the ApsaraMQ for RabbitMQ producer client.

On the ApsaraMQ for RabbitMQ producer client, configure the message-id parameter of the Basic.Properties field. Sample code:

Java

AMQP.BasicProperties props = new AMQP.BasicProperties.Builder().messageId("messageid").build(); 
channel.basicPublish("${ExchangeName}", "BindingKey", true, props, ("messageBody" + i).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 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");