Skip to content

Queue, Redis, Etc (Aws Service Mock Library for Spring Boot)

License

Notifications You must be signed in to change notification settings

jojoldu/spring-boot-aws-mock

Repository files navigation

spring-boot-aws-mock

Build Status Coverage Status Release

Spring Boot Starter support for Amazon Web Service Mocking.

Requirements

Windows OS is not supported

Mock Modules

  • SQS
    • Amazon Simple Queue Service

Install

Mock SQS

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'
}

Usage

Default

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

log

Integration Test

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.

Options

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

Example

About

Queue, Redis, Etc (Aws Service Mock Library for Spring Boot)

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages