All Products
Search
Document Center

Simple Message Queue (formerly MNS):Message attributes

Last Updated:Nov 17, 2025

Message attributes in Simple Message Queue (formerly MNS) are custom metadata that can be added to messages to support a wide range of application scenarios.

Components

Each message attribute consists of the following parts:

  • Name: The unique identifier for an attribute. The name is a case-sensitive string of up to 256 characters and must be unique among all attributes for the message.

  • Type: The data type of the attribute value. Supported types include String, Number, Boolean, and Binary.

  • Value: The content of the attribute, with a maximum length of 4,096 characters.

    Note

    For Binary, the value should be encoded in Base64.

Data types

The following table describes the four supported attribute types:

Data type

Value

Description

String

String

Stores any valid Unicode text.

Number

String

Stores positive or negative numeric values, including integers, floating-point numbers, and scientific notation. Simple Message Queue (formerly MNS) does not validate that the value is a number during transmission but processes it as a string.

Boolean

"true" or "false"

Stores a Boolean value. The value must be the string "true" or "false".

Binary

Base64-encoded string

Stores any binary data, such as compressed data, encrypted data, or images. The data must be Base64-encoded by the SDK or client when sent, and decoded when received.

Note

All attribute values, including binary data, are transmitted as strings over HTTP-based protocols. To ensure the fidelity of the Binary type, the SDK automatically encodes and decodes the value using Base64. If you do not use the SDK provided by Simple Message Queue (formerly MNS), you must handle the Base64 encoding and decoding for the Binary type yourself.

Limits

  • Number of attributes

    Each message can contain a maximum of 50 message attributes.

  • Attribute name

    • Can contain only the following characters: A-Z, a-z, 0-9, underscore (_), hyphen (-), and period (.).

    • Can be up to 256 characters long.

    • Is case-sensitive.

    • Must be unique among all attribute names for the message.

    • Cannot start or end with a period (.).

    • Cannot contain consecutive periods (.), such as "example..name".

  • Attribute value

    The length of an attribute value cannot exceed 4,096 characters.

  • Total message size

    The total size of all message attributes, including names, types, and values, is included in the total message size limit in Simple Message Queue (formerly MNS). For more information about the size limit, see Limits.

Examples

Write message attributes

// 1. Create a message object.
Message message = new Message();
message.setMessageBody("This is the message content");

// 2. Create a map to store the message attributes.
Map<String, MessagePropertyValue> userProperties = new HashMap<>();

// 3. Add attributes for each supported type.
// String
userProperties.put("city", new MessagePropertyValue("hangzhou"));
// Number (integer)
userProperties.put("priority", new MessagePropertyValue(10));
// Number (floating-point number)
userProperties.put("temperature", new MessagePropertyValue(-5.5));
// Boolean
userProperties.put("is_vip", new MessagePropertyValue(true));
// Binary
byte[] binaryData = "some-binary-data".getBytes();
userProperties.put("attachment", new MessagePropertyValue(binaryData));

// 4. Set the attributes for the message.
message.setUserProperties(userProperties);

Read message attributes

// Assume that 'receivedMessage' is a message object that you have obtained.
// Message receivedMessage = ...; 

// 1. Get the attribute map from the message.
Map<String, MessagePropertyValue> userProperties = receivedMessage.getUserProperties();

if (userProperties != null && !userProperties.isEmpty()) {
    // 2. Read and parse the attributes of each type.
    // Read String
    String city = userProperties.get("city").getStringValue();
    System.out.println("City (String): " + city);

    // Read Number (and parse as Double)
    double temperature = Double.parseDouble(userProperties.get("temperature").getStringValue());
    System.out.println("Temperature (Number as Double): " + temperature);

    // Read Number (and parse as Integer)
    int priority = Integer.parseInt(userProperties.get("priority").getStringValue());
    System.out.println("Priority (Number as Integer): " + priority);

    // Read Boolean (and parse)
    boolean isVip = Boolean.parseBoolean(userProperties.get("is_vip").getStringValue());
    System.out.println("Is VIP (Boolean): " + isVip);

    // Read Binary
    byte[] attachment = userProperties.get("attachment").getBinaryValue();
    System.out.println("Attachment (Binary): " + new String(attachment));
}

Read message attributes at subscription endpoints

Note

Message attributes are supported only for queue and HTTP subscriptions.

Queue subscriptions

When a message is pushed to a Simple Message Queue (formerly MNS) queue subscription endpoint, the message attributes are passed as part of the Message object. You can receive the message in the same way as a normal message, and then access userProperties using the methods that the Message object provides. For an example, see Read message attributes.

HTTP subscriptions

When a message is pushed to an HTTP subscription endpoint, the format of the message attributes depends on the Message Format that you specify when you create the subscription (the NotifyContentFormat property of the subscription):

  • JSON: If the format is JSON, the UserProperties message attributes are included as a JSON object in the body of the pushed HTTP POST request. Each attribute contains a Type field and a Value field.

    JSON example

    {
      "TopicOwner": "1234567890",
      "TopicName": "MyTopic",
      "Subscriber": "1234567890",
      "SubscriptionName": "MySubscription",
      "Message": "This is a test message.",
      "MessageId": "A26DAA0E-26C1-5F09-8BCC-CA3F1590A308",
      "MessageMD5": "E784F7B224E9164608EAD4CC76410443",
      "TimeStamp": "2025-02-20T13:41:37.976Z",
      "UserProperties": {
        "source": {
          "Type": "STRING",
          "Value": "mobile-app"
        },
        "image_id": {
          "Type": "NUMBER",
          "Value": "98014"
        },
        "raw_data": {
          "Type": "BINARY",
          "Value": "aGVsbG8gd29ybGQ="
        }
      }
    }
  • XML: If the format is XML, the UserProperties message attributes are included as an XML element in the body of the pushed HTTP POST request.

    XML example

    <?xml version="1.0" encoding="UTF-8"?>
    <Notification>
        <TopicOwner>1234567890</TopicOwner>
        <TopicName>MyTopic</TopicName>
        <Subscriber>1234567890</Subscriber>
        <SubscriptionName>MySubscription</SubscriptionName>
        <Message>This is a test message.</Message>
        <MessageId>A26DAA0E-26C1-5F09-8BCC-CA3F1590A308</MessageId>
        <MessageMD5>E784F7B224E9164608EAD4CC76410443</MessageMD5>
        <TimeStamp>2025-02-20T13:41:37.976Z</TimeStamp>
        <UserProperties>
            <PropertyValue>
                <Name>source</Name>
                <Value>mobile-app</Value>
                <Type>STRING</Type>
            </PropertyValue>
            <PropertyValue>
                <Name>image_id</Name>
                <Value>98014</Value>
                <Type>NUMBER</Type>
            </PropertyValue>
            <PropertyValue>
                <Name>raw_data</Name>
                <Value>aGVsbG8gd29ybGQ=</Value>
                <Type>BINARY</Type>
            </PropertyValue>
        </UserProperties>
    </Notification>
  • SIMPLIFIED: If the format is SIMPLIFIED, Simple Message Queue (formerly MNS) pushes only the raw message content. Message attributes cannot be passed.

References

For more information about the operations for Simple Message Queue (formerly MNS) subscriptions, see the following topics: