Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Purpose of Amazon SQS message's body as against message's attributes

What is the purpose of using message body in SQS while you're already able to add message attributes?

Let's take an example, we want to push a message to new-user queue when a new user registered, I imagine the message will have an attribute userId, I don't see the use of body here.

like image 493
Thịnh Phạm Avatar asked Dec 15 '16 05:12

Thịnh Phạm


People also ask

How do I send a message attribute in SQS?

Sending a message with attributes If you send a message to a First-In-First-Out (FIFO) queue, make sure that the sendMessage method executes after you provide the message group ID. If you use the SendMessageBatch method instead of SendMessage , you must specify message attributes for each message in the batch.

What is the use of message attributes in SQS?

You can use message attributes to attach custom metadata to Amazon SQS messages for your applications. You can use message system attributes to store metadata for other AWS services, such as AWS X-Ray.

What is the purpose of the SQS message visibility timeout?

To prevent other consumers from processing the message again, Amazon SQS sets a visibility timeout, a period of time during which Amazon SQS prevents other consumers from receiving and processing the message. The default visibility timeout for a message is 30 seconds. The minimum is 0 seconds. The maximum is 12 hours.

What is message attribute?

Message attributes are optional and separate from—but are sent together with—the message body. The receiver can use this information to decide how to handle the message without having to process the message body first.


1 Answers

Message attributes are supposed to be used as message metadata (like timestamp or possibly some category) and not the message itself.

Ideally, message payload should be given in the message body

So, for example if you are supporting JSON and XML payloads then possibly you can put payload type as message attribute and then when you fetch the message, based on this payload type attribute you decide between the JSON message processor or XML message processor. This is just a superficial example to explain the usage of attributes and body

Following is the extract from AWS Doc

Amazon SQS provides support for message attributes. Message attributes allow you to provide structured metadata items (such as timestamps, geospatial data, signatures, and identifiers) about the message. Message attributes are optional and separate from, but sent along with, the message body. This information can be used by the receiver of the message to help decide how to handle the message without having to first process the message body. Each message can have up to 10 attributes. To specify message attributes, you can use the AWS Management Console, AWS software development kits (SDKs), or query API.

like image 109
Arafat Nalkhande Avatar answered Sep 28 '22 08:09

Arafat Nalkhande