Skip to content

Commit e84652d

Browse files
authored
Add AWS SQS Plugin (#333)
* feat: Add basic SQS example * feat: wip: Add SQS plugin (currently copy of amqp) * feat: Add springwolf-sqs pipeline * test: Fix sqs docker container test * feat: Implement SqsListener scanner * feat: Bugfixing * feat: Add SQS to README * feat: Allow SQS publishing * feat(publishing!): Send payload as string and type to construct payload type * feat(kafka): Add publish example -> anotherDto example * feat(sqs): minor cleanups * feat(publishing): Test publishing functionality Also fix build.gradle dependencies and minor cleanup * feat(ui): Add sqs to mock-server * chore(sqs): Use AsyncOperationBinding code from master * feat(publishing): Whitelist publishing classes based on basePackage
1 parent 035a8db commit e84652d

File tree

51 files changed

+1945
-65
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

51 files changed

+1945
-65
lines changed
Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
name: springwolf-sqs
2+
3+
on:
4+
push:
5+
branches:
6+
- master
7+
paths:
8+
- '.github/workflows/springwolf-sqs.yml'
9+
- 'springwolf-core/**'
10+
- 'springwolf-plugins/springwolf-sqs-plugin/**'
11+
- 'springwolf-examples/springwolf-sqs-example/**'
12+
pull_request:
13+
types: [ opened, synchronize, ready_for_review ]
14+
15+
env:
16+
plugin: springwolf-plugins/springwolf-sqs-plugin
17+
example: springwolf-examples/springwolf-sqs-example
18+
19+
jobs:
20+
build:
21+
22+
runs-on: ubuntu-latest
23+
24+
steps:
25+
- uses: actions/checkout@v3
26+
27+
- name: Setup spectral
28+
run: |
29+
echo 'extends: ["spectral:asyncapi"]' > .spectral.yaml
30+
- name: Lint asyncapi.json with spectral
31+
uses: addnab/docker-run-action@v3
32+
with:
33+
image: stoplight/spectral:latest
34+
options: -v ${{ github.workspace }}:${{ github.workspace }} -w ${{ github.workspace }}
35+
run: spectral lint --ruleset ./.spectral.yaml --fail-on-unmatched-globs ./${{ env.example }}/src/test/resources/asyncapi.json
36+
37+
- name: Set up JDK
38+
uses: actions/setup-java@v3
39+
with:
40+
distribution: 'temurin'
41+
java-version: '17'
42+
43+
- name: Setup Gradle
44+
uses: gradle/gradle-build-action@v2
45+
46+
- name: Check formatting (before running tests) on plugin
47+
run: ./gradlew -p ${{ env.plugin }} spotlessCheck
48+
49+
- name: Check formatting (before running tests) on example
50+
run: ./gradlew -p ${{ env.example }} spotlessCheck
51+
52+
- name: Run unit tests
53+
run: ./gradlew -p ${{ env.plugin }} test
54+
55+
- name: Run integration tests
56+
run: ./gradlew -p ${{ env.example }} test
57+
58+
- name: Run build, check, analyzeDependencies on plugin
59+
run: ./gradlew -p ${{ env.plugin }} build
60+
61+
- name: Run build, check, analyzeDependencies on example
62+
run: ./gradlew -p ${{ env.example }} build
63+
64+
- name: Publish docker image
65+
if: github.ref == 'refs/heads/master'
66+
run: ./gradlew -p ${{ env.example }} dockerBuildImage dockerPushImage
67+
env:
68+
ORG_GRADLE_PROJECT_SNAPSHOT: true
69+
70+
ORG_GRADLE_PROJECT_DOCKERHUB_USERNAME: ${{ secrets.DOCKERHUB_USERNAME }}
71+
ORG_GRADLE_PROJECT_DOCKERHUB_TOKEN: ${{ secrets.DOCKERHUB_TOKEN }}
72+
73+
- name: Publish package
74+
if: github.ref == 'refs/heads/master'
75+
run: ./gradlew -p ${{ env.plugin }} publish
76+
env:
77+
ORG_GRADLE_PROJECT_SNAPSHOT: true
78+
79+
ORG_GRADLE_PROJECT_SIGNINGKEY: ${{secrets.ORG_GRADLE_PROJECT_SIGNINGKEY}}
80+
ORG_GRADLE_PROJECT_SIGNINGPASSWORD: ${{secrets.ORG_GRADLE_PROJECT_SIGNINGPASSWORD}}
81+
82+
ORG_GRADLE_PROJECT_MAVEN_URL: https://s01.oss.sonatype.org/content/repositories/snapshots/
83+
ORG_GRADLE_PROJECT_MAVEN_USERNAME: ${{ secrets.MAVEN_USERNAME }}
84+
ORG_GRADLE_PROJECT_MAVEN_PASSWORD: ${{ secrets.MAVEN_PASSWORD }}

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,11 @@ springwolf-add-ons/springwolf-common-model-converters/build/
99
springwolf-examples/springwolf-amqp-example/build/
1010
springwolf-examples/springwolf-cloud-stream-example/build/
1111
springwolf-examples/springwolf-kafka-example/build/
12+
springwolf-examples/springwolf-sqs-example/build/
1213
springwolf-plugins/springwolf-amqp-plugin/build/
1314
springwolf-plugins/springwolf-cloud-stream-plugin/build/
1415
springwolf-plugins/springwolf-kafka-plugin/build/
16+
springwolf-plugins/springwolf-sqs-plugin/build/
1517

1618
.gradle/
1719
.idea/

README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,10 @@
44

55
[![License](https://img.shields.io/badge/License-Apache%202.0-blue.svg)](https://opensource.org/licenses/Apache-2.0)
66
![springwolf-core](https://github.com/springwolf/springwolf-core/workflows/springwolf-core/badge.svg)
7-
![springwolf-kafka](https://github.com/springwolf/springwolf-core/workflows/springwolf-kafka/badge.svg)
87
![springwolf-amqp](https://github.com/springwolf/springwolf-core/workflows/springwolf-amqp/badge.svg)
98
![springwolf-cloud-stream](https://github.com/springwolf/springwolf-core/workflows/springwolf-cloud-stream/badge.svg)
9+
![springwolf-kafka](https://github.com/springwolf/springwolf-core/workflows/springwolf-kafka/badge.svg)
10+
![springwolf-sqs](https://github.com/springwolf/springwolf-core/workflows/springwolf-sqs/badge.svg)
1011
![springwolf-common-model-converters](https://github.com/springwolf/springwolf-core/actions/workflows/springwolf-common-model-converters.yml/badge.svg)
1112

1213
> We are on discord for any question, discussion, request etc.
@@ -63,6 +64,7 @@ payload and allows you to publish it to the correct channel with a single click.
6364
|-------------------------------------------------------------------------------------------------------------------------------------------|---------------------------------------------------------------------------------------------------------------------------------------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
6465
| [Core](https://github.com/springwolf/springwolf-core/tree/master/springwolf-core) | | ![Maven Central](https://img.shields.io/maven-central/v/io.github.springwolf/springwolf-core?color=green&label=springwolf-core&style=plastic) | ![Sonatype Nexus (Snapshots)](https://img.shields.io/nexus/s/io.github.springwolf/springwolf-core?label=springwolf-core&server=https%3A%2F%2Fs01.oss.sonatype.org&style=plastic) |
6566
| [AMQP](https://github.com/springwolf/springwolf-core/tree/master/springwolf-plugins/springwolf-amqp-plugin) | [AMQP Example](https://github.com/springwolf/springwolf-core/tree/master/springwolf-examples/springwolf-amqp-example) | ![Maven Central](https://img.shields.io/maven-central/v/io.github.springwolf/springwolf-amqp?color=green&label=springwolf-amqp&style=plastic) | ![Sonatype Nexus (Snapshots)](https://img.shields.io/nexus/s/io.github.springwolf/springwolf-amqp?label=springwolf-amqp&server=https%3A%2F%2Fs01.oss.sonatype.org&style=plastic) |
67+
| [AWS SQS](https://github.com/springwolf/springwolf-core/tree/master/springwolf-plugins/springwolf-sqs-plugin) | [AWS SQS Example](https://github.com/springwolf/springwolf-core/tree/master/springwolf-examples/springwolf-sqs-example) | ![Maven Central](https://img.shields.io/maven-central/v/io.github.springwolf/springwolf-sqs?color=green&label=springwolf-sqs&style=plastic) | ![Sonatype Nexus (Snapshots)](https://img.shields.io/nexus/s/io.github.springwolf/springwolf-sqs?label=springwolf-sqs&server=https%3A%2F%2Fs01.oss.sonatype.org&style=plastic) |
6668
| [Cloud Stream](https://github.com/springwolf/springwolf-core/tree/master/springwolf-plugins/springwolf-cloud-stream-plugin) | [Cloud Stream Example](https://github.com/springwolf/springwolf-core/tree/master/springwolf-examples/springwolf-cloud-stream-example) | ![Maven Central](https://img.shields.io/maven-central/v/io.github.springwolf/springwolf-cloud-stream?color=green&label=springwolf-cloud-stream&style=plastic) | ![Sonatype Nexus (Snapshots)](https://img.shields.io/nexus/s/io.github.springwolf/springwolf-cloud-stream?label=springwolf-cloud-stream&server=https%3A%2F%2Fs01.oss.sonatype.org&style=plastic) |
6769
| [Kafka](https://github.com/springwolf/springwolf-core/tree/master/springwolf-plugins/springwolf-kafka-plugin) | [Kafka Example](https://github.com/springwolf/springwolf-core/tree/master/springwolf-examples/springwolf-kafka-example) | ![Maven Central](https://img.shields.io/maven-central/v/io.github.springwolf/springwolf-kafka?color=green&label=springwolf-kafka&style=plastic) | ![Sonatype Nexus (Snapshots)](https://img.shields.io/nexus/s/io.github.springwolf/springwolf-kafka?label=springwolf-kafka&server=https%3A%2F%2Fs01.oss.sonatype.org&style=plastic) |
6870
| [Common Model Converter](https://github.com/springwolf/springwolf-core/tree/master/springwolf-add-ons/springwolf-common-model-converters) | | ![Maven Central](https://img.shields.io/maven-central/v/io.github.springwolf/springwolf-common-model-converters?color=green&label=springwolf-common-model-converters&style=plastic) | ![Sonatype Nexus (Snapshots)](https://img.shields.io/nexus/s/io.github.springwolf/springwolf-common-model-converters?label=springwolf-common-model-converters&server=https%3A%2F%2Fs01.oss.sonatype.org&style=plastic) |

build.gradle

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ allprojects {
5151
project.name == 'springwolf-amqp' ||
5252
project.name == 'springwolf-cloud-stream' ||
5353
project.name == 'springwolf-kafka' ||
54+
project.name == 'springwolf-sqs' ||
5455
project.name == 'springwolf-ui' ||
5556
project.name == 'springwolf-common-model-converters')
5657
tasks.withType(PublishToMavenRepository).configureEach { it.enabled = publishingEnabled }

settings.gradle

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,19 @@ rootProject.name = 'springwolf-core'
33
include(
44
'springwolf-core',
55
'springwolf-plugins:springwolf-amqp-plugin',
6-
'springwolf-plugins:springwolf-kafka-plugin',
76
'springwolf-plugins:springwolf-cloud-stream-plugin',
8-
'springwolf-examples:springwolf-kafka-example',
7+
'springwolf-plugins:springwolf-kafka-plugin',
8+
'springwolf-plugins:springwolf-sqs-plugin',
99
'springwolf-examples:springwolf-amqp-example',
1010
'springwolf-examples:springwolf-cloud-stream-example',
11+
'springwolf-examples:springwolf-kafka-example',
12+
'springwolf-examples:springwolf-sqs-example',
1113
'springwolf-ui',
1214
'springwolf-add-ons:springwolf-common-model-converters'
1315
)
1416

1517
project(':springwolf-plugins:springwolf-amqp-plugin').name = 'springwolf-amqp'
1618
project(':springwolf-plugins:springwolf-cloud-stream-plugin').name = 'springwolf-cloud-stream'
1719
project(':springwolf-plugins:springwolf-kafka-plugin').name = 'springwolf-kafka'
20+
project(':springwolf-plugins:springwolf-sqs-plugin').name = 'springwolf-sqs'
1821

springwolf-core/src/main/java/io/github/stavshamir/springwolf/asyncapi/controller/dtos/MessageDto.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,5 +15,9 @@ public class MessageDto {
1515

1616
private final Map<String, String> headers;
1717

18-
private final Map<String, ?> payload;
18+
@Builder.Default
19+
private final String payload = "";
20+
21+
@Builder.Default
22+
private final String payloadType = String.class.getCanonicalName();
1923
}

springwolf-core/src/test/java/io/github/stavshamir/springwolf/asyncapi/controller/dtos/MessageDtoDeserializationTest.java

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,20 @@ class MessageDtoDeserializationTest {
1313
private static final ObjectMapper objectMapper = Json.mapper();
1414

1515
@Test
16-
void testCanBeSerialized() throws IOException {
17-
String content =
18-
"{\"headers\": { \"some-header-key\" : \"some-header-value\" }, \"payload\": { \"some-payload-key\" : \"some-payload-value\" }}";
16+
void testCanBeSerialized() throws IOException, ClassNotFoundException {
17+
String content = "{" + "\"headers\": { \"some-header-key\" : \"some-header-value\" }, "
18+
+ "\"payload\": \"{\\\"some-payload-key\\\":\\\"some-payload-value\\\"}\", "
19+
+ "\"payloadType\": \""
20+
+ MessageDto.class.getCanonicalName() + "\"" + "}";
1921

2022
MessageDto value = objectMapper.readValue(content, MessageDto.class);
2123

2224
assertThat(value).isNotNull();
2325
assertThat(value.getHeaders()).isEqualTo(singletonMap("some-header-key", "some-header-value"));
24-
assertThat(value.getPayload()).isEqualTo(singletonMap("some-payload-key", "some-payload-value"));
26+
assertThat(value.getPayload())
27+
.isEqualTo(
28+
new ObjectMapper().writeValueAsString(singletonMap("some-payload-key", "some-payload-value")));
29+
assertThat(value.getPayloadType())
30+
.isEqualTo("io.github.stavshamir.springwolf.asyncapi.controller.dtos.MessageDto");
2531
}
2632
}

springwolf-examples/springwolf-kafka-example/src/main/java/io/github/stavshamir/springwolf/example/kafka/configuration/CustomWebSecurityConfigurerAdapter.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import org.springframework.context.annotation.Configuration;
55
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
66
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
7+
import org.springframework.security.config.annotation.web.configurers.AbstractHttpConfigurer;
78
import org.springframework.security.web.SecurityFilterChain;
89

910
/**
@@ -25,6 +26,9 @@ public SecurityFilterChain filterChain(HttpSecurity http) throws Exception {
2526
.permitAll()
2627
.anyRequest()
2728
.denyAll())
29+
// Please review the following lines before copying them to your application
30+
.cors(AbstractHttpConfigurer::disable)
31+
.csrf(AbstractHttpConfigurer::disable)
2832
.build();
2933
}
3034
}

springwolf-examples/springwolf-kafka-example/src/main/java/io/github/stavshamir/springwolf/example/kafka/consumers/ExampleConsumer.java

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,25 +2,30 @@
22

33
import io.github.stavshamir.springwolf.example.kafka.dtos.AnotherPayloadDto;
44
import io.github.stavshamir.springwolf.example.kafka.dtos.ExamplePayloadDto;
5+
import io.github.stavshamir.springwolf.example.kafka.producers.AnotherProducer;
6+
import lombok.RequiredArgsConstructor;
57
import lombok.extern.slf4j.Slf4j;
68
import org.springframework.kafka.annotation.KafkaListener;
79
import org.springframework.stereotype.Service;
810

911
import java.util.List;
1012

1113
@Service
14+
@RequiredArgsConstructor
1215
@Slf4j
1316
public class ExampleConsumer {
1417

15-
private final ExampleService exampleService;
16-
17-
public ExampleConsumer(ExampleService exampleService) {
18-
this.exampleService = exampleService;
19-
}
18+
private final AnotherProducer anotherProducer;
2019

2120
@KafkaListener(topics = "example-topic")
2221
public void receiveExamplePayload(ExamplePayloadDto payload) {
23-
exampleService.doSomething(payload);
22+
log.info("Received new message in example-queue: {}", payload.toString());
23+
24+
AnotherPayloadDto example = new AnotherPayloadDto();
25+
example.setExample(payload);
26+
example.setFoo("foo");
27+
28+
anotherProducer.sendMessage(example);
2429
}
2530

2631
@KafkaListener(topics = "another-topic", groupId = "example-group-id", batch = "true")

springwolf-examples/springwolf-kafka-example/src/main/java/io/github/stavshamir/springwolf/example/kafka/consumers/ExampleService.java

Lines changed: 0 additions & 14 deletions
This file was deleted.

0 commit comments

Comments
 (0)