-
Notifications
You must be signed in to change notification settings - Fork 78
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #655 from ctasada/ctasada/decouple-binding-annotat…
…ions (feat): Decoupled Binding annotations
- Loading branch information
Showing
22 changed files
with
661 additions
and
2 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
name: springwolf-bindings | ||
|
||
on: | ||
push: | ||
branches: | ||
- master | ||
pull_request: | ||
types: [ opened, synchronize, ready_for_review ] | ||
|
||
jobs: | ||
build: | ||
|
||
runs-on: ubuntu-latest | ||
timeout-minutes: 10 | ||
|
||
strategy: | ||
fail-fast: false | ||
matrix: | ||
binding: [ "sns", "sqs" ] | ||
|
||
env: | ||
binding: springwolf-bindings/springwolf-${{ matrix.binding }}-binding | ||
|
||
steps: | ||
- uses: actions/checkout@v4 | ||
|
||
- name: Set up JDK | ||
uses: actions/setup-java@v4 | ||
with: | ||
distribution: 'temurin' | ||
java-version: '17' | ||
|
||
- name: Setup Gradle | ||
uses: gradle/actions/setup-gradle@v3 | ||
|
||
- name: Check formatting (before running tests) on binding | ||
run: ./gradlew -p ${{ env.binding }} spotlessCheck | ||
|
||
- name: Run unit tests | ||
run: ./gradlew -p ${{ env.binding }} test | ||
|
||
- name: Run build, check, analyzeDependencies on binding | ||
run: ./gradlew -p ${{ env.binding }} build | ||
|
||
- name: Publish package | ||
if: github.ref == 'refs/heads/master' | ||
run: ./gradlew -p ${{ env.binding }} publish | ||
env: | ||
ORG_GRADLE_PROJECT_SNAPSHOT: true | ||
|
||
ORG_GRADLE_PROJECT_SIGNINGKEY: ${{secrets.ORG_GRADLE_PROJECT_SIGNINGKEY}} | ||
ORG_GRADLE_PROJECT_SIGNINGPASSWORD: ${{secrets.ORG_GRADLE_PROJECT_SIGNINGPASSWORD}} | ||
|
||
ORG_GRADLE_PROJECT_MAVEN_URL: https://s01.oss.sonatype.org/content/repositories/snapshots/ | ||
ORG_GRADLE_PROJECT_MAVEN_USERNAME: ${{ secrets.MAVEN_USERNAME }} | ||
ORG_GRADLE_PROJECT_MAVEN_PASSWORD: ${{ secrets.MAVEN_PASSWORD }} |
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,43 @@ | ||
plugins { | ||
id 'java-library' | ||
|
||
id 'org.springframework.boot' | ||
id 'io.spring.dependency-management' | ||
id 'ca.cutterslade.analyze' | ||
} | ||
|
||
dependencies { | ||
api project(":springwolf-asyncapi") | ||
api project(":springwolf-core") | ||
|
||
implementation "org.springframework:spring-context" | ||
implementation "org.springframework:spring-core" | ||
implementation "org.springframework.boot:spring-boot-autoconfigure" | ||
|
||
testImplementation "org.assertj:assertj-core:${assertjCoreVersion}" | ||
testImplementation "org.junit.jupiter:junit-jupiter-api:${junitJupiterVersion}" | ||
|
||
testRuntimeOnly "org.junit.jupiter:junit-jupiter:${junitJupiterVersion}" | ||
} | ||
|
||
jar { | ||
enabled = true | ||
archiveClassifier = '' | ||
} | ||
bootJar.enabled = false | ||
|
||
java { | ||
withJavadocJar() | ||
withSourcesJar() | ||
} | ||
|
||
publishing { | ||
publications { | ||
mavenJava(MavenPublication) { | ||
pom { | ||
name = 'springwolf-sns-binding' | ||
description = 'Automated JSON API documentation for AWS SNS Bindings' | ||
} | ||
} | ||
} | ||
} |
31 changes: 31 additions & 0 deletions
31
...src/main/java/io/github/springwolf/bindings/sns/annotations/SnsAsyncOperationBinding.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,31 @@ | ||
// SPDX-License-Identifier: Apache-2.0 | ||
package io.github.springwolf.bindings.sns.annotations; | ||
|
||
import io.github.springwolf.core.asyncapi.annotations.AsyncListener; | ||
import io.github.springwolf.core.asyncapi.annotations.AsyncOperationBinding; | ||
import io.github.springwolf.core.asyncapi.annotations.AsyncPublisher; | ||
|
||
import java.lang.annotation.ElementType; | ||
import java.lang.annotation.Inherited; | ||
import java.lang.annotation.Retention; | ||
import java.lang.annotation.RetentionPolicy; | ||
import java.lang.annotation.Target; | ||
|
||
/** | ||
* {@code @SnsAsyncOperationBinding} is a method-level annotation used in combination with {@link AsyncPublisher} or {@link AsyncListener}. | ||
* It configures the operation binding for the SNS protocol. | ||
*/ | ||
@Retention(RetentionPolicy.RUNTIME) | ||
@Target(value = {ElementType.METHOD, ElementType.ANNOTATION_TYPE}) | ||
@AsyncOperationBinding | ||
@Inherited | ||
public @interface SnsAsyncOperationBinding { | ||
|
||
String type() default "sns"; | ||
|
||
String protocol(); | ||
|
||
SnsAsyncOperationBindingIdentifier endpoint(); | ||
|
||
boolean rawMessageDelivery() default true; | ||
} |
42 changes: 42 additions & 0 deletions
42
...ava/io/github/springwolf/bindings/sns/annotations/SnsAsyncOperationBindingIdentifier.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,42 @@ | ||
// SPDX-License-Identifier: Apache-2.0 | ||
package io.github.springwolf.bindings.sns.annotations; | ||
|
||
import io.github.springwolf.asyncapi.v3.bindings.sns.SNSOperationBindingIdentifier; | ||
|
||
import java.lang.annotation.ElementType; | ||
import java.lang.annotation.Inherited; | ||
import java.lang.annotation.Retention; | ||
import java.lang.annotation.RetentionPolicy; | ||
import java.lang.annotation.Target; | ||
|
||
/** | ||
* @see SNSOperationBindingIdentifier | ||
*/ | ||
@Retention(RetentionPolicy.RUNTIME) | ||
@Target({ElementType.PARAMETER}) | ||
@Inherited | ||
public @interface SnsAsyncOperationBindingIdentifier { | ||
/** | ||
* Optional. The endpoint is a URL | ||
*/ | ||
String url() default ""; | ||
/** | ||
* Optional. The endpoint is an email address | ||
*/ | ||
String email() default ""; | ||
/** | ||
* Optional. The endpoint is a phone number | ||
*/ | ||
String phone() default ""; | ||
/** | ||
* Optional. The target is an ARN. For example, for SQS, the identifier may be an ARN, which will be of the form: | ||
* "arn:aws:sqs:{region}:{account-id}:{queueName}" | ||
*/ | ||
String arn() default ""; | ||
/** | ||
* Optional. The endpoint is identified by a name, which corresponds to an identifying field called 'name' of a | ||
* binding for that protocol on this publish Operation Object. For example, if the protocol is 'sqs' then the name | ||
* refers to the name field sqs binding. We don't use $ref because we are referring, not including. | ||
*/ | ||
String name() default ""; | ||
} |
34 changes: 34 additions & 0 deletions
34
...o/github/springwolf/bindings/sns/configuration/SpringwolfSnsBindingAutoConfiguration.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,34 @@ | ||
// SPDX-License-Identifier: Apache-2.0 | ||
package io.github.springwolf.bindings.sns.configuration; | ||
|
||
import io.github.springwolf.bindings.sns.scanners.messages.SnsMessageBindingProcessor; | ||
import io.github.springwolf.bindings.sns.scanners.operations.SnsOperationBindingProcessor; | ||
import io.github.springwolf.core.asyncapi.scanners.bindings.BindingProcessorPriority; | ||
import io.github.springwolf.core.configuration.properties.SpringwolfConfigConstants; | ||
import org.springframework.boot.autoconfigure.AutoConfiguration; | ||
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; | ||
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; | ||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.core.annotation.Order; | ||
|
||
/** | ||
* Autoconfiguration for the springwolf SQS Binding. | ||
*/ | ||
@AutoConfiguration | ||
@ConditionalOnProperty(name = SpringwolfConfigConstants.SPRINGWOLF_ENABLED, havingValue = "true", matchIfMissing = true) | ||
public class SpringwolfSnsBindingAutoConfiguration { | ||
|
||
@Bean | ||
@Order(value = BindingProcessorPriority.PROTOCOL_BINDING) | ||
@ConditionalOnMissingBean | ||
public SnsMessageBindingProcessor sqsMessageBindingProcessor() { | ||
return new SnsMessageBindingProcessor(); | ||
} | ||
|
||
@Bean | ||
@Order(value = BindingProcessorPriority.PROTOCOL_BINDING) | ||
@ConditionalOnMissingBean | ||
public SnsOperationBindingProcessor sqsOperationBindingProcessor() { | ||
return new SnsOperationBindingProcessor(); | ||
} | ||
} |
35 changes: 35 additions & 0 deletions
35
.../java/io/github/springwolf/bindings/sns/scanners/messages/SnsMessageBindingProcessor.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,35 @@ | ||
// SPDX-License-Identifier: Apache-2.0 | ||
package io.github.springwolf.bindings.sns.scanners.messages; | ||
|
||
import io.github.springwolf.asyncapi.v3.bindings.sns.SNSMessageBinding; | ||
import io.github.springwolf.bindings.sns.annotations.SnsAsyncOperationBinding; | ||
import io.github.springwolf.core.asyncapi.scanners.bindings.messages.MessageBindingProcessor; | ||
import io.github.springwolf.core.asyncapi.scanners.bindings.messages.ProcessedMessageBinding; | ||
import org.springframework.context.EmbeddedValueResolverAware; | ||
import org.springframework.util.StringValueResolver; | ||
|
||
import java.lang.reflect.Method; | ||
import java.util.Arrays; | ||
import java.util.Optional; | ||
|
||
public class SnsMessageBindingProcessor implements MessageBindingProcessor, EmbeddedValueResolverAware { | ||
private StringValueResolver resolver; | ||
|
||
@Override | ||
public void setEmbeddedValueResolver(StringValueResolver resolver) { | ||
this.resolver = resolver; | ||
} | ||
|
||
@Override | ||
public Optional<ProcessedMessageBinding> process(Method method) { | ||
return Arrays.stream(method.getAnnotations()) | ||
.filter(SnsAsyncOperationBinding.class::isInstance) | ||
.map(SnsAsyncOperationBinding.class::cast) | ||
.findAny() | ||
.map(this::mapToMessageBinding); | ||
} | ||
|
||
private ProcessedMessageBinding mapToMessageBinding(SnsAsyncOperationBinding bindingAnnotation) { | ||
return new ProcessedMessageBinding(bindingAnnotation.type(), new SNSMessageBinding()); | ||
} | ||
} |
56 changes: 56 additions & 0 deletions
56
...a/io/github/springwolf/bindings/sns/scanners/operations/SnsOperationBindingProcessor.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,56 @@ | ||
// SPDX-License-Identifier: Apache-2.0 | ||
package io.github.springwolf.bindings.sns.scanners.operations; | ||
|
||
import io.github.springwolf.asyncapi.v3.bindings.sns.SNSOperationBinding; | ||
import io.github.springwolf.asyncapi.v3.bindings.sns.SNSOperationBindingConsumer; | ||
import io.github.springwolf.asyncapi.v3.bindings.sns.SNSOperationBindingIdentifier; | ||
import io.github.springwolf.bindings.sns.annotations.SnsAsyncOperationBinding; | ||
import io.github.springwolf.bindings.sns.annotations.SnsAsyncOperationBindingIdentifier; | ||
import io.github.springwolf.core.asyncapi.scanners.bindings.operations.AbstractOperationBindingProcessor; | ||
import io.github.springwolf.core.asyncapi.scanners.bindings.operations.ProcessedOperationBinding; | ||
|
||
import java.util.List; | ||
|
||
public class SnsOperationBindingProcessor extends AbstractOperationBindingProcessor<SnsAsyncOperationBinding> { | ||
|
||
@Override | ||
protected ProcessedOperationBinding mapToOperationBinding(SnsAsyncOperationBinding bindingAnnotation) { | ||
var identifier = convertAnnotation(bindingAnnotation.endpoint()); | ||
var protocol = readProtocol(bindingAnnotation.protocol()); | ||
|
||
var consumer = SNSOperationBindingConsumer.builder() | ||
.protocol(protocol) | ||
.endpoint(identifier) | ||
.rawMessageDelivery(bindingAnnotation.rawMessageDelivery()) | ||
.build(); | ||
var snsOperationBinding = | ||
SNSOperationBinding.builder().consumers(List.of(consumer)).build(); | ||
return new ProcessedOperationBinding(bindingAnnotation.type(), snsOperationBinding); | ||
} | ||
|
||
private SNSOperationBindingConsumer.Protocol readProtocol(String protocol) { | ||
return SNSOperationBindingConsumer.Protocol.valueOf(protocol.toUpperCase()); | ||
} | ||
|
||
private SNSOperationBindingIdentifier convertAnnotation(SnsAsyncOperationBindingIdentifier identifier) { | ||
var builder = SNSOperationBindingIdentifier.builder(); | ||
|
||
if (!identifier.url().isBlank()) { | ||
builder.url(identifier.url()); | ||
} | ||
if (!identifier.arn().isBlank()) { | ||
builder.arn(identifier.arn()); | ||
} | ||
if (!identifier.name().isBlank()) { | ||
builder.name(identifier.name()); | ||
} | ||
if (!identifier.email().isBlank()) { | ||
builder.email(identifier.email()); | ||
} | ||
if (!identifier.phone().isBlank()) { | ||
builder.phone(identifier.phone()); | ||
} | ||
|
||
return builder.build(); | ||
} | ||
} |
1 change: 1 addition & 0 deletions
1
...esources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports
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 @@ | ||
io.github.springwolf.bindings.sns.configuration.SpringwolfSnsBindingAutoConfiguration |
Oops, something went wrong.