aws-sdk-java-v2-messaging
giuseppe-trisciuoglio/developer-kit
AWS messaging patterns for SQS queues and SNS topics using Java SDK 2.x
What is aws-sdk-java-v2-messaging?
Provides AWS SDK for Java 2.x patterns for SQS and SNS messaging, including queue creation, message send/receive, FIFO queues, dead letter queues, subscriptions, and Spring Boot integration. Use when building event-driven architectures or implementing message buffering with AWS services.
- Create and manage SQS queues (standard and FIFO) with configurable attributes
- Send and receive messages with long polling and batch operations
- Configure dead letter queues (DLQ) for error handling and failed message tracking
- Implement pub/sub patterns with SNS topics and SQS subscriptions
- Process messages with validation and idempotent handling
- Integrate messaging with Spring Boot applications using dependency injection
How to install aws-sdk-java-v2-messaging
npx skills add https://github.com/giuseppe-trisciuoglio/developer-kit --skill aws-sdk-java-v2-messaging- AWS SDK for Java 2.x dependencies (sqs and sns artifacts)
- AWS credentials configured via environment variables or IAM roles
- AWS account with permissions to create/manage SQS queues and SNS topics
- Java 8 or later
How to use aws-sdk-java-v2-messaging
- 1.Configure SQS and SNS clients with region and credentials provider
- 2.Create queues or topics with appropriate attributes (FIFO, DLQ, etc.)
- 3.Send messages and validate messageId is returned
- 4.Receive messages using long polling (20-40 second wait time)
- 5.Process and validate message payload before business logic
- 6.Delete messages only after successful processing
- 7.Monitor CloudWatch metrics and check DLQ periodically for failed messages
Use cases
- Building asynchronous job processing systems with SQS queues and DLQ fallback
- Implementing event notifications across services using SNS topics and SQS subscriptions
- Creating order processing pipelines with FIFO queues to maintain message order
- Setting up message-driven microservices with Spring Boot and AWS messaging
- Handling distributed system communication with long polling and message acknowledgment
- Java backend developers building event-driven architectures
- DevOps engineers setting up AWS messaging infrastructure
- Spring Boot application developers integrating with SQS/SNS
- Teams implementing asynchronous processing and pub/sub patterns
aws-sdk-java-v2-messaging FAQ
Use FIFO queues when message order and exactly-once processing matter (e.g., orders, financial transactions). Standard queues are faster and cheaper but offer best-effort ordering. FIFO has a 300 msg/sec throughput limit per queue.
Always configure a dead letter queue (DLQ) using redrivePolicy, delete messages only after successful processing, and monitor the DLQ for failed messages. Implement idempotent processing to handle duplicate deliveries.
Long polling waits up to the specified time (20-40 seconds) for messages to arrive instead of returning immediately if empty. It reduces API calls, lowers costs, and improves responsiveness compared to short polling.
Subscribe an SQS queue to an SNS topic by providing the queue ARN as the subscription endpoint with protocol 'sqs'. Messages published to the topic are automatically delivered to subscribed queues.
Both SQS and SNS have a maximum message size of 256KB. Larger payloads require storing data externally (e.g., S3) and sending only the reference in the message.
Full instructions (SKILL.md)
Source of truth, from giuseppe-trisciuoglio/developer-kit.
name: aws-sdk-java-v2-messaging description: Provides AWS messaging patterns using AWS SDK for Java 2.x for SQS queues and SNS topics. Handles sending/receiving messages, FIFO queues, DLQ, subscriptions, and pub/sub patterns. Use when implementing messaging with SQS or SNS. allowed-tools: Read, Write, Edit, Bash, Glob, Grep
AWS SDK for Java 2.x - Messaging (SQS & SNS)
Overview
Provides patterns for SQS queues and SNS topics with AWS SDK for Java 2.x: client setup, queue management, message operations, subscriptions, and Spring Boot integration.
When to Use
- Setting up SQS queues (standard or FIFO) for message buffering
- Implementing pub/sub with SNS topics and subscriptions
- Processing messages from SQS queues with long polling
- Configuring dead letter queues (DLQ) for error handling
- Integrating AWS messaging with Spring Boot applications
- Building event-driven architectures with SQS/SNS
Examples
Quick Setup
Dependencies:
<dependency>
<groupId>software.amazon.awssdk</groupId>
<artifactId>sqs</artifactId>
</dependency>
<dependency>
<groupId>software.amazon.awssdk</groupId>
<artifactId>sns</artifactId>
</dependency>
Client Configuration:
SqsClient sqsClient = SqsClient.builder()
.region(Region.US_EAST_1)
.credentialsProvider(DefaultCredentialsProvider.create())
.build();
SnsClient snsClient = SnsClient.builder()
.region(Region.US_EAST_1)
.build();
SQS Operations
Create and Send Message:
String queueUrl = sqsClient.createQueue(CreateQueueRequest.builder()
.queueName("my-queue")
.build()).queueUrl();
String messageId = sqsClient.sendMessage(SendMessageRequest.builder()
.queueUrl(queueUrl)
.messageBody("Hello, SQS!")
.build()).messageId();
Receive and Delete Message:
ReceiveMessageResponse response = sqsClient.receiveMessage(ReceiveMessageRequest.builder()
.queueUrl(queueUrl)
.maxNumberOfMessages(10)
.waitTimeSeconds(20)
.build());
response.messages().forEach(message -> {
processMessage(message.body());
sqsClient.deleteMessage(DeleteMessageRequest.builder()
.queueUrl(queueUrl)
.receiptHandle(message.receiptHandle())
.build());
});
FIFO Queue:
Map<QueueAttributeName, String> attributes = Map.of(
QueueAttributeName.FIFO_QUEUE, "true",
QueueAttributeName.CONTENT_BASED_DEDUPLICATION, "true"
);
String fifoQueueUrl = sqsClient.createQueue(CreateQueueRequest.builder()
.queueName("my-queue.fifo")
.attributes(attributes)
.build()).queueUrl();
sqsClient.sendMessage(SendMessageRequest.builder()
.queueUrl(fifoQueueUrl)
.messageBody("Order #12345")
.messageGroupId("orders")
.messageDeduplicationId(UUID.randomUUID().toString())
.build());
SNS Operations
Create Topic and Publish:
String topicArn = snsClient.createTopic(CreateTopicRequest.builder()
.name("my-topic")
.build()).topicArn();
snsClient.publish(PublishRequest.builder()
.topicArn(topicArn)
.subject("Test Notification")
.message("Hello, SNS!")
.build());
SNS to SQS Subscription:
String queueArn = sqsClient.getQueueAttributes(GetQueueAttributesRequest.builder()
.queueUrl(queueUrl)
.attributeNames(QueueAttributeName.QUEUE_ARN)
.build()).attributes().get(QueueAttributeName.QUEUE_ARN);
snsClient.subscribe(SubscribeRequest.builder()
.protocol("sqs")
.endpoint(queueArn)
.topicArn(topicArn)
.build());
Spring Boot Integration
@Service
@RequiredArgsConstructor
public class OrderNotificationService {
private final SnsClient snsClient;
private final ObjectMapper objectMapper;
@Value("${aws.sns.order-topic-arn}")
private String orderTopicArn;
public void sendOrderNotification(Order order) throws JsonProcessingException {
snsClient.publish(PublishRequest.builder()
.topicArn(orderTopicArn)
.subject("New Order Received")
.message(objectMapper.writeValueAsString(order))
.messageAttributes(Map.of(
"orderType", MessageAttributeValue.builder()
.dataType("String")
.stringValue(order.getType())
.build()))
.build());
}
}
Instructions
Implement Message Processing (with Validation)
- Create queues/topics with appropriate configuration
- Send messages and validate
messageIdis returned - Receive messages with long polling (
waitTimeSeconds: 20) - Process messages - validate payload before processing
- Delete messages only after successful processing - verify deletion response
- Check DLQ periodically for failed messages using
redrivePolicy - Verify delivery - monitor CloudWatch
NumberOfMessagesSentmetric
Validation Checklist:
// After send
if (messageId == null || messageId.isEmpty()) {
throw new MessagingException("Message send failed - no messageId returned");
}
// After receive
if (response.messages().isEmpty()) {
log.debug("No messages available - normal with long polling");
}
// After delete
if (!deleteResponse.sdkHttpResponse().isSuccessful()) {
throw new MessagingException("Message deletion failed");
}
Setup Credentials
export AWS_ACCESS_KEY_ID=your-access-key
export AWS_SECRET_ACCESS_KEY=your-secret-key
export AWS_REGION=us-east-1
Monitor and Debug
- CloudWatch metrics:
ApproximateNumberOfMessages,NumberOfMessagesSent,NumberOfMessagesReceived - Enable SDK logging:
software.amazon.awssdkat DEBUG level - Use X-Ray for distributed tracing
Best Practices
SQS:
- Use long polling (20-40s) to reduce empty responses and costs
- Always delete messages after successful processing
- Implement idempotent processing for duplicate handling
- Configure DLQ (
redrivePolicy) for failed messages - Use FIFO queues when order matters (300 msg/sec limit)
SNS:
- Use filter policies to reduce unnecessary deliveries
- Keep messages under 256KB
- Implement retry with exponential backoff
- Monitor
NumberOfNotificationFailedmetric
General:
- Use IAM roles over static credentials
- Reuse clients (they are thread-safe)
- Test with LocalStack or Testcontainers
Detailed References
- references/detailed-sqs-operations.md
- references/detailed-sns-operations.md
- references/spring-boot-integration.md
- references/aws-official-documentation.md
Constraints and Warnings
- Message Size: Maximum 256KB for SQS and SNS
- Visibility Timeout: Undeleted messages reappear after timeout - always delete after processing
- Input Validation: Sanitize message body before processing - messages may contain untrusted payloads
- FIFO Naming: Must end with
.fifosuffix - FIFO Throughput: 300 msg/sec per queue (use partitioning for higher throughput)
- Message Retention: SQS retains messages max 14 days
- DLQ Required: Configure dead letter queue to prevent message loss
- Region-Specific: SQS queues are region-specific; cross-region requires SNS
Related skills
More from giuseppe-trisciuoglio/developer-kit and the wider catalog.

aws-sdk-java-v2-rds
AWS RDS management patterns using AWS SDK for Java 2.x

aws-sdk-java-v2-s3
AWS SDK for Java 2.x patterns for S3 bucket management, uploads, downloads, and multipart transfers.

aws-sdk-java-v2-secrets-manager
Retrieve, cache, and rotate AWS Secrets Manager credentials in Java 2.x applications with Spring Boot integration.

better-auth
Provides Better Auth integration patterns for NestJS backend and Next.js frontend with Drizzle ORM and PostgreSQL. Use when setting up Better Auth with NestJS backend, integrating Next.js App Router frontend, configuring Drizzle ORM schema, implementing social login (GitHub, Google), adding plugins (2FA, Organization, SSO, Magic Link, Passkey), implementing email/password authentication with session management, or creating protected routes and middleware.

bug-fix-brief
Generates a structured Bug Fix Brief (BFB) to document issue corrections. Includes root cause analysis, repro steps, fix options, and fix checklist. Use when user asks to create a BFB, document a bug fix, or generate a bug correction document.

chunking-strategy
Optimize document chunking for RAG systems with size, overlap, and semantic boundary recommendations.