-
-
Notifications
You must be signed in to change notification settings - Fork 317
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
cb1adcc
commit f1692dd
Showing
21 changed files
with
828 additions
and
40 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
45 changes: 45 additions & 0 deletions
45
...spring-cloud-aws-sqs-sample/src/main/java/io/awspring/cloud/sqs/sample/MessageSender.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
/* | ||
* Copyright 2013-2022 the original author or authors. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* https://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package io.awspring.cloud.sqs.sample; | ||
|
||
import java.time.LocalDate; | ||
|
||
import io.awspring.cloud.messaging.core.QueueMessagingTemplate; | ||
|
||
import org.springframework.boot.context.event.ApplicationReadyEvent; | ||
import org.springframework.context.event.EventListener; | ||
import org.springframework.messaging.support.MessageBuilder; | ||
import org.springframework.stereotype.Component; | ||
|
||
@Component | ||
class MessageSender { | ||
|
||
private final QueueMessagingTemplate queueMessagingTemplate; | ||
|
||
MessageSender(QueueMessagingTemplate queueMessagingTemplate) { | ||
this.queueMessagingTemplate = queueMessagingTemplate; | ||
} | ||
|
||
@EventListener(ApplicationReadyEvent.class) | ||
public void sendMessage() { | ||
this.queueMessagingTemplate.send("InfrastructureStack-spring-aws", | ||
MessageBuilder.withPayload("Spring cloud Aws SQS sample!").build()); | ||
this.queueMessagingTemplate.convertAndSend("InfrastructureStack-aws-pojo", | ||
new Person("Joe", "Doe", LocalDate.of(2000, 1, 12))); | ||
} | ||
|
||
} |
40 changes: 40 additions & 0 deletions
40
...pring-cloud-aws-sqs-sample/src/main/java/io/awspring/cloud/sqs/sample/SampleListener.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
/* | ||
* Copyright 2013-2022 the original author or authors. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* https://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package io.awspring.cloud.sqs.sample; | ||
|
||
import io.awspring.cloud.messaging.listener.annotation.SqsListener; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
import org.springframework.stereotype.Component; | ||
|
||
@Component | ||
class SampleListener { | ||
|
||
private static final Logger LOGGER = LoggerFactory.getLogger(SampleListener.class); | ||
|
||
@SqsListener("InfrastructureStack-spring-aws") | ||
public void listenToMessage(String message) { | ||
LOGGER.info("This is message you want to see: {}", message); | ||
} | ||
|
||
@SqsListener("InfrastructureStack-aws-pojo") | ||
public void listenToPerson(Person person) { | ||
LOGGER.info(person.toString()); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
78 changes: 78 additions & 0 deletions
78
...-aws-sqs-sample/src/test/java/io/awspring/cloud/sqs/sample/SqsSampleApplicationTests.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
/* | ||
* Copyright 2013-2022 the original author or authors. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* https://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package io.awspring.cloud.sqs.sample; | ||
|
||
import java.io.IOException; | ||
|
||
import io.awspring.cloud.messaging.core.QueueMessagingTemplate; | ||
import io.awspring.cloud.test.sqs.SqsTest; | ||
import org.junit.jupiter.api.BeforeAll; | ||
import org.junit.jupiter.api.Test; | ||
import org.testcontainers.containers.localstack.LocalStackContainer; | ||
import org.testcontainers.junit.jupiter.Container; | ||
import org.testcontainers.junit.jupiter.Testcontainers; | ||
import org.testcontainers.utility.DockerImageName; | ||
|
||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.boot.test.mock.mockito.SpyBean; | ||
import org.springframework.test.context.DynamicPropertyRegistry; | ||
import org.springframework.test.context.DynamicPropertySource; | ||
|
||
import static org.awaitility.Awaitility.await; | ||
import static org.mockito.Mockito.verify; | ||
import static org.testcontainers.containers.localstack.LocalStackContainer.Service.SQS; | ||
|
||
@SqsTest(properties = { "cloud.aws.credentials.access-key=noop", "cloud.aws.credentials.secret-key=noop", | ||
"cloud.aws.region.static=eu-west-1" }) | ||
@Testcontainers | ||
class SqsSampleApplicationTests { | ||
This comment has been minimized.
Sorry, something went wrong. |
||
|
||
private static final String QUEUE_NAME = "InfrastructureStack-spring-aws"; | ||
|
||
// create an SQS locally running equivalent with Localstack and Testcontainers | ||
@Container | ||
static LocalStackContainer localstack = new LocalStackContainer( | ||
DockerImageName.parse("localstack/localstack:0.14.0")).withServices(SQS).withReuse(true); | ||
|
||
@Autowired | ||
private QueueMessagingTemplate queueMessagingTemplate; | ||
|
||
@SpyBean | ||
private SampleListener sampleListener; | ||
|
||
@BeforeAll | ||
static void beforeAll() throws IOException, InterruptedException { | ||
// create needed queues in SQS | ||
localstack.execInContainer("awslocal", "sqs", "create-queue", "--queue-name", QUEUE_NAME); | ||
This comment has been minimized.
Sorry, something went wrong.
driverpt
|
||
} | ||
|
||
@Test | ||
void receivesMessage() { | ||
// send a message | ||
queueMessagingTemplate.convertAndSend(QUEUE_NAME, "hello"); | ||
|
||
// verify that bean handling the message was invoked | ||
await().untilAsserted(() -> verify(sampleListener).listenToMessage("hello")); | ||
This comment has been minimized.
Sorry, something went wrong.
driverpt
|
||
} | ||
|
||
@DynamicPropertySource | ||
static void registerSqsProperties(DynamicPropertyRegistry registry) { | ||
// overwrite SQS endpoint with one provided by Localstack | ||
registry.add("cloud.aws.sqs.endpoint", () -> localstack.getEndpointOverride(SQS).toString()); | ||
This comment has been minimized.
Sorry, something went wrong. |
||
} | ||
|
||
} |
15 changes: 15 additions & 0 deletions
15
spring-cloud-aws-samples/spring-cloud-aws-sqs-sample/src/test/resources/logback-test.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
<configuration> | ||
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender"> | ||
<encoder> | ||
<pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %logger - %msg%n</pattern> | ||
</encoder> | ||
</appender> | ||
|
||
<root level="INFO"> | ||
<appender-ref ref="STDOUT"/> | ||
</root> | ||
|
||
<logger name="org.testcontainers" level="INFO"/> | ||
<logger name="com.github.dockerjava" level="WARN"/> | ||
<logger name="io.awspring" level="INFO"/> | ||
</configuration> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<!-- | ||
~ Copyright 2013-2019 the original author or authors. | ||
~ | ||
~ Licensed under the Apache License, Version 2.0 (the "License"); | ||
~ you may not use this file except in compliance with the License. | ||
~ You may obtain a copy of the License at | ||
~ | ||
~ https://www.apache.org/licenses/LICENSE-2.0 | ||
~ | ||
~ Unless required by applicable law or agreed to in writing, software | ||
~ distributed under the License is distributed on an "AS IS" BASIS, | ||
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
~ See the License for the specific language governing permissions and | ||
~ limitations under the License. | ||
--> | ||
|
||
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xmlns="http://maven.apache.org/POM/4.0.0" | ||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
<modelVersion>4.0.0</modelVersion> | ||
<parent> | ||
<groupId>io.awspring.cloud</groupId> | ||
<artifactId>spring-cloud-aws</artifactId> | ||
<version>2.4.0-SNAPSHOT</version> | ||
</parent> | ||
<artifactId>spring-cloud-aws-test</artifactId> | ||
<name>Spring Cloud AWS Test</name> | ||
<description>Spring Cloud AWS Test</description> | ||
<url>https://projects.spring.io/spring-cloud</url> | ||
|
||
<properties> | ||
<main.basedir>${basedir}/../..</main.basedir> | ||
</properties> | ||
<dependencies> | ||
<dependency> | ||
<groupId>io.awspring.cloud</groupId> | ||
<artifactId>spring-cloud-aws-autoconfigure</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>io.awspring.cloud</groupId> | ||
<artifactId>spring-cloud-aws-messaging</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.springframework.boot</groupId> | ||
<artifactId>spring-boot-test-autoconfigure</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.springframework</groupId> | ||
<artifactId>spring-test</artifactId> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>org.junit.jupiter</groupId> | ||
<artifactId>junit-jupiter-api</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.assertj</groupId> | ||
<artifactId>assertj-core</artifactId> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>org.awaitility</groupId> | ||
<artifactId>awaitility</artifactId> | ||
<scope>test</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.testcontainers</groupId> | ||
<artifactId>localstack</artifactId> | ||
<scope>test</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.testcontainers</groupId> | ||
<artifactId>junit-jupiter</artifactId> | ||
<scope>test</scope> | ||
</dependency> | ||
</dependencies> | ||
</project> |
Oops, something went wrong.
Shouldn't this go into
<properties>
?