Skip to content

Commit

Permalink
GH-344 - Polishing.
Browse files Browse the repository at this point in the history
Switch to DelegatingEventExternalizer APIs changed to return CompletableFuture. Imports, formatting. Drop dependencies not needed.
  • Loading branch information
odrotbohm committed Nov 1, 2023
1 parent f41d337 commit 21a8282
Show file tree
Hide file tree
Showing 12 changed files with 172 additions and 186 deletions.
1 change: 1 addition & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
<spring.version>6.1.0-RC1</spring.version> <!-- For Javadoc links only -->
<spring-boot.version>3.2.0-RC1</spring-boot.version>
<spring-cloud-aws-bom.version>3.0.2</spring-cloud-aws-bom.version>

</properties>

<developers>
Expand Down
6 changes: 0 additions & 6 deletions spring-modulith-events/spring-modulith-events-aws-sns/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,6 @@
<artifactId>spring-cloud-aws-sns</artifactId>
</dependency>

<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<optional>true</optional>
</dependency>

<!-- Test dependencies -->

<dependency>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,11 @@
import io.awspring.cloud.sns.core.SnsNotification;
import io.awspring.cloud.sns.core.SnsOperations;
import io.awspring.cloud.sns.core.SnsTemplate;

import java.util.concurrent.CompletableFuture;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import software.amazon.awssdk.services.sns.model.InvalidParameterException;

import org.springframework.beans.factory.BeanFactory;
import org.springframework.boot.autoconfigure.AutoConfiguration;
import org.springframework.boot.autoconfigure.AutoConfigureAfter;
Expand All @@ -30,7 +31,6 @@
import org.springframework.context.annotation.Bean;
import org.springframework.context.expression.BeanFactoryResolver;
import org.springframework.expression.spel.support.StandardEvaluationContext;
import org.springframework.messaging.MessageDeliveryException;
import org.springframework.modulith.events.EventExternalizationConfiguration;
import org.springframework.modulith.events.config.EventExternalizationAutoConfiguration;
import org.springframework.modulith.events.support.BrokerRouting;
Expand All @@ -40,6 +40,7 @@
* Auto-configuration to set up a {@link DelegatingEventExternalizer} to externalize events to SNS.
*
* @author Maciej Walkowiak
* @author Oliver Drotbohm
* @since 1.1
*/
@AutoConfiguration
Expand All @@ -64,22 +65,17 @@ DelegatingEventExternalizer snsEventExternalizer(EventExternalizationConfigurati
return new DelegatingEventExternalizer(configuration, (target, payload) -> {

var routing = BrokerRouting.of(target, context);

var builder = SnsNotification.builder(payload);
var key = routing.getKey(payload);

// when routing key is set, SNS topic must be a FIFO topic
if (key != null) {
builder.groupId(key);
}
try {
operations.sendNotification(routing.getTarget(), builder.build());
} catch (MessageDeliveryException e) {
// message delivery may fail if groupId is set and topic is not a FIFO topic, or content based deduplication has not been set on topic attributes.
if (e.getCause() instanceof InvalidParameterException) {
logger.error("Failed to send notification to SNS topic {}:{}", routing.getTarget(), e.getCause().getMessage());
}
throw e;
}

operations.sendNotification(routing.getTarget(), builder.build());

return CompletableFuture.completedFuture(null);
});
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* SNS event externalization support.
* AWS SNS event externalization support.
*/
@org.springframework.lang.NonNullApi
package org.springframework.modulith.events.aws.sns;
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,17 @@
*/
package org.springframework.modulith.events.aws.sns;

import static org.assertj.core.api.Assertions.*;
import static org.mockito.Mockito.*;

import io.awspring.cloud.sns.core.SnsOperations;
import org.junit.jupiter.api.Test;

import org.junit.jupiter.api.Test;
import org.springframework.boot.autoconfigure.AutoConfigurations;
import org.springframework.boot.test.context.runner.ApplicationContextRunner;
import org.springframework.modulith.events.EventExternalizationConfiguration;
import org.springframework.modulith.events.support.DelegatingEventExternalizer;

import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.Mockito.mock;

/**
* Integration tests for {@link SnsEventExternalizerConfiguration}.
*
Expand All @@ -34,7 +34,7 @@
*/
class SnsEventExternalizerConfigurationIntegrationTests {

@Test // GH-342
@Test // GH-344
void registersExternalizerByDefault() {

basicSetup()
Expand All @@ -43,7 +43,7 @@ void registersExternalizerByDefault() {
});
}

@Test // GH-342
@Test // GH-344
void disablesExternalizationIfConfigured() {

basicSetup()
Expand Down
Loading

0 comments on commit 21a8282

Please sign in to comment.