This project consists of a single Java Spring Boot application designed to demonstrate the use of Amazon Simple Queue Service (SQS) for sending and receiving messages. This application showcases how to integrate AWS SQS with Spring Boot, providing a scalable and reliable messaging solution.
This project contains two main components:
- Sender: Sends messages to an Amazon SQS queue.
- Receiver: Receives messages from an Amazon SQS queue.
-
Sender Application:
- Exposes a REST endpoint to send messages to the SQS queue.
- Utilizes AWS SDK for Java to interact with SQS.
-
Receiver Application:
- Continuously polls the SQS queue for new messages.
- Processes received messages.
- Java 11 or higher
- Maven
- AWS account with access to SQS
- AWS CLI configured with your credentials
-
Create an SQS Queue:
- Go to the AWS Management Console.
- Navigate to the SQS service.
- Create a new queue (standard or FIFO).
- Note the Queue URL for later use.
-
Configure AWS Credentials:
- Ensure your AWS credentials are configured correctly. This can be done using the AWS CLI:
aws configure
- Ensure your AWS credentials are configured correctly. This can be done using the AWS CLI:
Open another terminal and execute the following command to create an SQS queue:
Start LocalStack:
Run the following command to start LocalStack:
docker-compose up localstack
This will start LocalStack and all services configured in the docker-compose.yml
file.
aws --endpoint-url=http://localhost:4566 sqs create-queue --queue-name my-queue
This will create a queue named my-queue
in LocalStack.
To send a message to the SQS queue, you can use the following command:
aws --endpoint-url=http://localhost:4566 sqs send-message --queue-url http://localhost:4566/000000000000/my-queue --message-body "My test message"
You can receive messages from the SQS queue with the following command:
aws --endpoint-url=http://localhost:4566 sqs receive-message --queue-url http://localhost:4566/000000000000/my-queue
This will return any available messages in the my-queue
.
- Sender Message:
- Use a tool like
curl
or Postman to send a POST request to theapi/v1/sqs
endpoint:curl -X POST "http://localhost:8080/api/v1/sqs" -d "message=Hello World"
- Use a tool like
This project is licensed under the MIT License. See the LICENSE file for details.