-
Notifications
You must be signed in to change notification settings - Fork 77
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add AWS SNS Plugin Although AsyncAPI allows to add more details for the binding, the underlying library jAsyncApi has no support for further binding information. Therefore, only the sns binding without properties is supported. Manual configuration is supported through the usual `@AsyncPublisher` annotation in combination with the `@SnsAsyncOperationBinding` annotation. The code is mostly copied and adjusted based on the other plugins. * chore: Removed duplicated plugin version definition * refactor(sns-plugin): change sns-plugin to use autoconfiguration instead of component scanning Co-authored-by: Timon Back <[email protected]> --------- Co-authored-by: David Müller <[email protected]> Co-authored-by: Timon Back <[email protected]>
- Loading branch information
1 parent
c23bcf0
commit 359599f
Showing
41 changed files
with
1,258 additions
and
7 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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
SPRINGWOLF_VERSION=0.16.0-SNAPSHOT |
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,6 @@ | ||
## Usage | ||
|
||
### Run with docker compose (recommended) | ||
1. Copy the `docker-compose.yml` file to your machine. | ||
2. Run `$ docker-compose up`. | ||
3. Visit `localhost:8080/springwolf/asyncapi-ui.html` or try the API: `$ curl localhost:8080/springwolf/docs`. |
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,76 @@ | ||
plugins { | ||
id 'java' | ||
|
||
id 'org.springframework.boot' | ||
id 'io.spring.dependency-management' | ||
id 'ca.cutterslade.analyze' | ||
|
||
id 'com.bmuschko.docker-spring-boot-application' | ||
} | ||
|
||
dependencyManagement { | ||
imports { | ||
mavenBom "io.awspring.cloud:spring-cloud-aws-dependencies:3.0.2" | ||
} | ||
} | ||
|
||
dependencies { | ||
implementation project(":springwolf-core") | ||
implementation project(":springwolf-plugins:springwolf-sns") | ||
|
||
annotationProcessor project(":springwolf-plugins:springwolf-sns") | ||
runtimeOnly project(":springwolf-ui") | ||
|
||
runtimeOnly "org.springframework.boot:spring-boot-starter-web" | ||
|
||
implementation "org.slf4j:slf4j-api:${slf4jApiVersion}" | ||
implementation "io.swagger.core.v3:swagger-annotations:${swaggerVersion}" | ||
|
||
implementation 'io.awspring.cloud:spring-cloud-aws-sns' | ||
implementation 'io.awspring.cloud:spring-cloud-aws-starter-sns' | ||
permitUnusedDeclared 'io.awspring.cloud:spring-cloud-aws-starter-sns' | ||
implementation "org.springframework.boot:spring-boot-autoconfigure" | ||
implementation "org.springframework.boot:spring-boot" | ||
implementation "org.springframework:spring-context" | ||
implementation "org.springframework:spring-messaging" | ||
|
||
testRuntimeOnly "org.junit.jupiter:junit-jupiter:${junitJupiterVersion}" | ||
|
||
testImplementation "com.vaadin.external.google:android-json:${androidJsonVersion}" | ||
|
||
testImplementation "org.junit.jupiter:junit-jupiter-api:${junitJupiterVersion}" | ||
|
||
testImplementation "org.springframework.boot:spring-boot-test" | ||
testImplementation "org.springframework:spring-beans" | ||
testImplementation "org.springframework:spring-web" | ||
testImplementation "org.springframework:spring-test" | ||
|
||
testImplementation "org.testcontainers:testcontainers:${testcontainersVersion}" | ||
testImplementation "org.testcontainers:junit-jupiter:${testcontainersVersion}" | ||
testImplementation "org.testcontainers:localstack:${testcontainersVersion}" | ||
} | ||
|
||
docker { | ||
springBootApplication { | ||
maintainer = '[email protected]' | ||
baseImage = 'eclipse-temurin:17-jre-focal' | ||
ports = [8080] | ||
images = ["stavshamir/springwolf-sns-example:${project.version}"] | ||
} | ||
|
||
registryCredentials { | ||
username = project.findProperty('DOCKERHUB_USERNAME') ?: '' | ||
password = project.findProperty('DOCKERHUB_TOKEN') ?: '' | ||
} | ||
} | ||
|
||
test { | ||
dependsOn dockerBuildImage | ||
dependsOn spotlessApply // Automatically fix code formatting if possible | ||
|
||
useJUnitPlatform() | ||
|
||
testLogging { | ||
exceptionFormat = 'full' | ||
} | ||
} |
36 changes: 36 additions & 0 deletions
36
springwolf-examples/springwolf-sns-example/docker-compose.yml
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,36 @@ | ||
version: '3' | ||
services: | ||
app: | ||
image: stavshamir/springwolf-sns-example:${SPRINGWOLF_VERSION} | ||
links: | ||
- localstack | ||
environment: | ||
- SPRING_CLOUD_AWS_ENDPOINT=http://localstack:4566 | ||
ports: | ||
- "8080:8080" | ||
depends_on: | ||
- localstack | ||
|
||
localstack: | ||
image: localstack/localstack:2.2.0 | ||
environment: | ||
- DEBUG=${DEBUG-} | ||
- AWS_REGION=eu-central-1 | ||
- SERVICES=sqs,sns | ||
ports: | ||
- "4566:4566" # LocalStack Gateway | ||
# - "4510-4559:4510-4559" # external services port range | ||
volumes: | ||
- "${TMPDIR:-/tmp/localstack}:/tmp/localstack" | ||
- "/var/run/docker.sock:/var/run/docker.sock" | ||
localstack_setup: | ||
image: localstack/localstack:2.2.0 | ||
links: | ||
- localstack | ||
depends_on: | ||
- localstack | ||
restart: "no" | ||
entrypoint: [ "bash", "-c", " | ||
awslocal --endpoint-url=http://localstack:4566 sns create-topic --name another-topic --region eu-central-1; | ||
awslocal --endpoint-url=http://localstack:4566 sns create-topic --name example-topic --region eu-central-1; | ||
" ] |
13 changes: 13 additions & 0 deletions
13
...ain/java/io/github/stavshamir/springwolf/example/sns/SpringwolfSnsExampleApplication.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,13 @@ | ||
// SPDX-License-Identifier: Apache-2.0 | ||
package io.github.stavshamir.springwolf.example.sns; | ||
|
||
import org.springframework.boot.SpringApplication; | ||
import org.springframework.boot.autoconfigure.SpringBootApplication; | ||
|
||
@SpringBootApplication | ||
public class SpringwolfSnsExampleApplication { | ||
|
||
public static void main(String[] args) { | ||
SpringApplication.run(SpringwolfSnsExampleApplication.class, args); | ||
} | ||
} |
37 changes: 37 additions & 0 deletions
37
.../src/main/java/io/github/stavshamir/springwolf/example/sns/consumers/ExampleConsumer.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,37 @@ | ||
// SPDX-License-Identifier: Apache-2.0 | ||
package io.github.stavshamir.springwolf.example.sns.consumers; | ||
|
||
import io.github.stavshamir.springwolf.asyncapi.scanners.channels.operationdata.annotation.AsyncListener; | ||
import io.github.stavshamir.springwolf.asyncapi.scanners.channels.operationdata.annotation.AsyncOperation; | ||
import io.github.stavshamir.springwolf.asyncapi.scanners.channels.operationdata.annotation.SnsAsyncOperationBinding; | ||
import io.github.stavshamir.springwolf.example.sns.dtos.AnotherPayloadDto; | ||
import io.github.stavshamir.springwolf.example.sns.dtos.ExamplePayloadDto; | ||
import io.github.stavshamir.springwolf.example.sns.producers.AnotherProducer; | ||
import lombok.RequiredArgsConstructor; | ||
import lombok.extern.slf4j.Slf4j; | ||
import org.springframework.stereotype.Service; | ||
|
||
@Service | ||
@RequiredArgsConstructor | ||
@Slf4j | ||
public class ExampleConsumer { | ||
private final AnotherProducer anotherProducer; | ||
|
||
@AsyncListener(operation = @AsyncOperation(channelName = "example-topic")) | ||
@SnsAsyncOperationBinding | ||
public void receiveExamplePayload(ExamplePayloadDto payload) { | ||
log.info("Received new message in example-topic: {}", payload.toString()); | ||
|
||
AnotherPayloadDto example = new AnotherPayloadDto(); | ||
example.setExample(payload); | ||
example.setFoo("foo"); | ||
|
||
anotherProducer.sendMessage(example); | ||
} | ||
|
||
@AsyncListener(operation = @AsyncOperation(channelName = "another-topic")) | ||
@SnsAsyncOperationBinding | ||
public void receiveAnotherPayload(AnotherPayloadDto payload) { | ||
log.info("Received new message in another-topic: {}", payload.toString()); | ||
} | ||
} |
23 changes: 23 additions & 0 deletions
23
...ple/src/main/java/io/github/stavshamir/springwolf/example/sns/dtos/AnotherPayloadDto.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,23 @@ | ||
// SPDX-License-Identifier: Apache-2.0 | ||
package io.github.stavshamir.springwolf.example.sns.dtos; | ||
|
||
import io.swagger.v3.oas.annotations.media.Schema; | ||
import lombok.AllArgsConstructor; | ||
import lombok.Data; | ||
import lombok.NoArgsConstructor; | ||
|
||
import static io.swagger.v3.oas.annotations.media.Schema.RequiredMode.NOT_REQUIRED; | ||
import static io.swagger.v3.oas.annotations.media.Schema.RequiredMode.REQUIRED; | ||
|
||
@Schema(description = "Another payload model") | ||
@Data | ||
@AllArgsConstructor | ||
@NoArgsConstructor | ||
public class AnotherPayloadDto { | ||
|
||
@Schema(description = "Foo field", example = "bar", requiredMode = NOT_REQUIRED) | ||
private String foo; | ||
|
||
@Schema(description = "Example field", requiredMode = REQUIRED) | ||
private ExamplePayloadDto example; | ||
} |
30 changes: 30 additions & 0 deletions
30
...ple/src/main/java/io/github/stavshamir/springwolf/example/sns/dtos/ExamplePayloadDto.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,30 @@ | ||
// SPDX-License-Identifier: Apache-2.0 | ||
package io.github.stavshamir.springwolf.example.sns.dtos; | ||
|
||
import io.swagger.v3.oas.annotations.media.Schema; | ||
import lombok.AllArgsConstructor; | ||
import lombok.Data; | ||
import lombok.NoArgsConstructor; | ||
|
||
import static io.swagger.v3.oas.annotations.media.Schema.RequiredMode.REQUIRED; | ||
|
||
@Schema(description = "Example payload model") | ||
@Data | ||
@AllArgsConstructor | ||
@NoArgsConstructor | ||
public class ExamplePayloadDto { | ||
@Schema(description = "Some string field", example = "some string value", requiredMode = REQUIRED) | ||
private String someString; | ||
|
||
@Schema(description = "Some long field", example = "5") | ||
private long someLong; | ||
|
||
@Schema(description = "Some enum field", example = "FOO2", requiredMode = REQUIRED) | ||
private ExampleEnum someEnum; | ||
|
||
public enum ExampleEnum { | ||
FOO1, | ||
FOO2, | ||
FOO3 | ||
} | ||
} |
29 changes: 29 additions & 0 deletions
29
.../src/main/java/io/github/stavshamir/springwolf/example/sns/producers/AnotherProducer.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,29 @@ | ||
// SPDX-License-Identifier: Apache-2.0 | ||
package io.github.stavshamir.springwolf.example.sns.producers; | ||
|
||
import io.awspring.cloud.sns.core.SnsTemplate; | ||
import io.github.stavshamir.springwolf.asyncapi.scanners.channels.operationdata.annotation.AsyncOperation; | ||
import io.github.stavshamir.springwolf.asyncapi.scanners.channels.operationdata.annotation.AsyncPublisher; | ||
import io.github.stavshamir.springwolf.asyncapi.scanners.channels.operationdata.annotation.SnsAsyncOperationBinding; | ||
import io.github.stavshamir.springwolf.example.sns.dtos.AnotherPayloadDto; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.messaging.support.MessageBuilder; | ||
import org.springframework.stereotype.Component; | ||
|
||
@Component | ||
@RequiredArgsConstructor | ||
public class AnotherProducer { | ||
private final SnsTemplate template; | ||
|
||
public static final String TOPIC = "another-topic"; | ||
|
||
@AsyncPublisher( | ||
operation = | ||
@AsyncOperation( | ||
channelName = TOPIC, | ||
description = "Custom, optional description defined in the AsyncPublisher annotation")) | ||
@SnsAsyncOperationBinding | ||
public void sendMessage(AnotherPayloadDto msg) { | ||
template.send(TOPIC, MessageBuilder.withPayload(msg).build()); | ||
} | ||
} |
35 changes: 35 additions & 0 deletions
35
springwolf-examples/springwolf-sns-example/src/main/resources/application.properties
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,35 @@ | ||
######### | ||
# Spring configuration | ||
spring.application.name=Springwolf example project - SNS | ||
|
||
|
||
######### | ||
# Spring AWS configuration | ||
spring.cloud.aws.endpoint=http://localhost:4566 | ||
spring.cloud.aws.region.static=eu-central-1 | ||
spring.cloud.aws.stack.auto=false | ||
spring.cloud.aws.stack.enabled=false | ||
spring.cloud.aws.credentials.secretKey=ABC | ||
spring.cloud.aws.credentials.accessKey=XYZ | ||
|
||
|
||
######### | ||
# Springwolf configuration | ||
springwolf.enabled=true | ||
springwolf.docket.base-package=io.github.stavshamir.springwolf.example.sns | ||
springwolf.docket.info.title=${spring.application.name} | ||
springwolf.docket.info.version=1.0.0 | ||
springwolf.docket.info.description=Springwolf example project to demonstrate springwolfs abilities | ||
springwolf.docket.info.terms-of-service=http://asyncapi.org/terms | ||
springwolf.docket.info.contact.name=springwolf | ||
springwolf.docket.info.contact.email=[email protected] | ||
springwolf.docket.info.contact.url=https://github.com/springwolf/springwolf-core | ||
springwolf.docket.info.license.name=Apache License 2.0 | ||
springwolf.docket.servers.sns.protocol=sns | ||
springwolf.docket.servers.sns.url=http://localhost:4566 | ||
|
||
springwolf.plugin.sns.publishing.enabled=true | ||
|
||
|
||
# For debugging purposes | ||
logging.level.io.github.stavshamir.springwolf=DEBUG |
Oops, something went wrong.