localstack-spring-boot icon indicating copy to clipboard operation
localstack-spring-boot copied to clipboard

The "simplest thing that could possibly work" for SQS

Open binkley opened this issue 6 years ago • 0 comments

I'm stuck on 2 things:

  • If I do not hard-code an AWS region, I get "There is no EC2 meta data available, because the application is not running in the EC2 environment. Region detection is only possible if the application is running on a EC2 instance"
  • If I do hard-code an AWS region, I get "No valid instance id defined"

And this is something I've seen with every localstack integration with Spring Boot, not just yours. I wonder what "big picture" point I'm missing?

I was rather hoping this project would just work out of the box.

Gradle includes:

  • testImplementation "io.smartup.localstack:localstack-spring-boot-starter:1.1.1"

Listener:

@Component
@RequiredArgsConstructor(onConstructor = @__(@Autowired))
@Slf4j
public class QtrListener {
    private final BobClient bobClient;

    @SqsListener("${my.sqs.queue}")
    public void receive(final Bob bob) {
        log.error("GOT A BOB! " + bob);
        bobClient.update(bob);
    }
}

(BobClient is a simple Feign interface. In the test (below), it is mocked.)

The test:

@ActiveProfiles("test")
@RequiredArgsConstructor(onConstructor = @__(@Autowired))
@SpringBootTest(classes = MyApplication.class, webEnvironment = NONE)
class MyIntegrationTest {
    private final AmazonSQSAsync amazonSQSAsync;

    @MockBean
    private BobClient bobClient;

    @Test
    void shouldListen() {
        final Bob bob = new Bob("Hey dol! merry dol! ring a dong dillo!");

        new QueueMessagingTemplate(amazonSQSAsync).convertAndSend(bob);

        verify(bobClient).update(bob);
    }
}

The properties:

my:
  sqs:
    queue: 'fake-queue'

localstack:
  enabled: true
  sqs:
    enabled: true

spring:
  profiles:
    active: "test"

binkley avatar Feb 23 '19 17:02 binkley