All Products
Search
Document Center

:How do I specify a message ID?

Last Updated:Jun 02, 2026

Specify a unique message ID on ApsaraMQ for RabbitMQ producers to track and identify messages.

What is a message ID?

A message ID is an optional short string property that uniquely identifies a message, useful for tracking sales orders and tickets. ApsaraMQ for RabbitMQ servers do not guarantee idempotence—consumers may receive the same message multiple times. To prevent duplicate processing from affecting your business, assign a unique message ID and implement idempotence on ApsaraMQ for RabbitMQ consumers. For more information, see Implementing idempotence.

Set a message ID

Set the message ID in the basic properties on ApsaraMQ for RabbitMQ producers:

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