Menu
Amazon Simple Notification Service
Developer Guide (API Version 2010-03-31)

Using Message Attributes for Structuring the Message

This section provides additional information and examples for using message attributes to structure a message and send a push notification message to a mobile endpoint.

The following Java example shows how to send a push notification message to a mobile endpoint and how to use the optional message attributes for structuring the message. If an attribute is not sent, a default value is auto-set in its place.

Note

The push notification message cannot exceed 256 bytes, which is the maximum size allowed by Baidu.

Copy
Map<String, MessageAttributeValue> messageAttributes = new HashMap<String, MessageAttributeValue>(); // Insert your desired value of Deploy Status here. 1 = DEV, 2 = PROD messageAttributes.put("AWS.SNS.MOBILE.BAIDU.DeployStatus", new MessageAttributeValue().withDataType("String").withStringValue("1")); // Insert your desired value of Message Type here. 0 = IN-APP MESSAGE, 1 = ALERT NOTIFICATION messageAttributes.put("AWS.SNS.MOBILE.BAIDU.MessageType", new MessageAttributeValue().withDataType("String").withStringValue("1")); // Insert your desired value of Message Key messageAttributes.put("AWS.SNS.MOBILE.BAIDU.MessageKey", new MessageAttributeValue().withDataType("String").withStringValue("test-message")); PublishRequest publishRequest = new PublishRequest(); publishRequest.setMessageAttributes(messageAttributes); String message = "{\"title\":\"Test_Title\",\"description\":\"Test_Description\"}"; publishRequest.setMessage(message); publishRequest.setTargetArn("arn:aws:sns:us-west-2:999999999999:endpoint/BAIDU/TestApp/309fc7d3-bc53-3b63-ac42-e359260ac740"); PublishResult publishResult = snsClient.publish(publishRequest);

Note the following considerations when using the optional message attributes for structuring the message:

  • AWS.SNS.MOBILE.BAIDU.DeployStatus

    Possible Values (Default = 1):

    1 – Tags the notification as being sent in a development environment

    2 – Tags the notification as being sent in a production environment

  • AWS.SNS.MOBILE.BAIDU.MessageType

    Possible Values (Default = 1):

    0 – Generates an in-app message

    1 – Generates an alert notification. Alert notifications are restricted to the following format:

    Copy
    {"title":"<TITLE>","description":"<DESCRIPTION>"}

    <TITLE> and <DESCRIPTION> are the title and description you desire for your alert notification. If the message is incorrectly formatted JSON, the request fails.

  • AWS.SNS.MOBILE.BAIDU.MessageKey

    A short message identifier you can attach to your message