🔷
Amazon SQS - Producing & Consuming Messages
Producing Messages
- Producers use AWS SDKs or API calls like
SendMessage
or SendMessageBatch
.
- Messages remain stored in SQS until explicitly deleted by consumers.
- Common pattern: Include attributes such as Order ID, Customer ID, or metadata.
Consuming Messages
- Consumers (EC2, Lambda, on-premise apps, etc.) poll the queue using
ReceiveMessage
.
- Can receive up to 10 messages per API call.
- After processing, messages must be deleted explicitly via
DeleteMessage
.
- Visibility Timeout:
- Period during which a received message is hidden from other consumers.
- Prevents duplicate processing while a consumer is still working on it.
- Default: 30 seconds, configurable up to 12 hours.
Scaling and Monitoring
- CloudWatch metrics like
ApproximateNumberOfMessagesVisible
help monitor queue depth.
- Auto Scaling Groups (ASGs) can be configured to scale based on queue length.
- Consumers can be horizontally scaled to increase processing throughput.