Message Attributes and Metadata
You'll learn: How to attach custom information to messages that helps consumers filter, route, and understand them without parsing the entire message body.
What Are Message Attributes?
When you send a message through a queue or topic, the actual content (the body) contains your data—perhaps a JSON order or a status update. Message attributes are extra labels you attach alongside that body, like sticky notes on an envelope. These key-value pairs provide metadata that describes the message without requiring consumers to open and parse it.
Think of attributes as the information printed on the outside of a package: sender, priority, fragile label, delivery instructions. The delivery driver (your consumer) can make decisions based on these labels without opening the box.
Why Use Attributes?
Filtering: SNS topics use attributes to decide which subscribers receive which messages. A subscriber might say "only send me messages where orderType = 'priority'" without receiving and discarding irrelevant messages.
Routing: Attributes help route messages to different processing queues based on metadata like region, customer tier, or message type.
Context: Consumers get useful information (timestamp, correlation ID, source system) without digging through the payload, improving performance and logging.
Common Attributes
- Content type:
application/jsonortext/plain - Priority level:
high,low - Correlation ID: links related messages
- Timestamp: when the message was created
- Source/Region: where it originated
Attributes keep routing logic lightweight and enable powerful filtering patterns in event-driven systems.
Key Takeaway:
Message attributes are metadata labels attached to messages, enabling efficient filtering, routing, and context without parsing the message body itself.