Spring Boot Starter support for Amazon Web Service Mocking.
Windows OS is not supported
- SQS
- Amazon Simple Queue Service
build.gradle
repositories {
maven { url 'https://jitpack.io' }
}
dependencies {
compile 'com.github.jojoldu.spring-boot-aws-mock:mock-sqs-spring-boot-starter:0.4.1'
}
application.yml
cloud:
aws:
region:
static: ap-northeast-2 //aws region code (required)
stack:
auto: false // default required
sqs:
mock:
enabled: true
queues:
-
name: 'key1'
Controller.java
public class SampleController {
@Autowired private QueueMessagingTemplate messagingTemplate;
@PostMapping("/url")
public String save(@RequestBody RequestDto requestDto){
String queueName = "key1";
messagingTemplate.convertAndSend(queueName, requestDto);
...
}
@SqsListener(value = "key1")
public void receive(String message, @Header("SenderId") String senderId) throws IOException {
...
}
}
Run Test & Show Log
During integration testing, you must specify any port to prevent mock sqs server port conflicts.
src/test/resources/application.yml or application.properteis
sqs:
mock:
randomPortEnabled: true
This will run the server with the new port each time the Spring context is executed.
sqs:
mock:
enabled: true //required
randomPortEnabled: true
host: localhost
port: 9324
queues:
-
name: 'key1-dlq'
-
name: 'key1'
defaultVisibilityTimeout: 1
delay: 0
receiveMessageWait: 0
deadLettersQueue:
name: "point-dlq"
maxReceiveCount: 1
-
sqs.mock.enabled
- false (default, not use local mock sqs)
- true (use local mock sqs)
-
sqs.mock.randomPortEnabled
- false (default, not use local mock sqs)
- true (use random port)
-
sqs.mock.host
- sqs server host
- default: localhost
-
sqs.mock.port
- sqs server port
- default: 9324
AWS SQS | MOCK SQS | Default Value |
---|---|---|
VisibilityTimeout | defaultVisibilityTimeout | 30 (s) |
DelaySeconds | delay | 0 (s) |
ReceiveMessageWaitTimeSeconds | receiveMessageWait | 0 (s) |
RedrivePolicy | deadLettersQueue | null |
RedrivePolicy.name | deadLettersQueue.name | null |
RedrivePolicy.maxReceiveCount | deadLettersQueue.maxReceiveCount | null |
- Basic Sample Project
- Divided Provider Application & Consumer Application