From de3b627e812bd4f1d5939aa194c4b3820e36e223 Mon Sep 17 00:00:00 2001 From: Assad Riaz Date: Tue, 22 Oct 2024 14:29:52 +0200 Subject: [PATCH 1/2] Refactor GooglePubSubConfig --- .../changelog/EntityChangedEventPubSubPublisher.java | 4 ++-- .../rutebanken/tiamat/config/GooglePubSubConfig.java | 6 ------ .../tiamat/config/PubsubOutboundGateway.java | 10 ++++++++++ 3 files changed, 12 insertions(+), 8 deletions(-) create mode 100644 src/main/java/org/rutebanken/tiamat/config/PubsubOutboundGateway.java diff --git a/src/main/java/org/rutebanken/tiamat/changelog/EntityChangedEventPubSubPublisher.java b/src/main/java/org/rutebanken/tiamat/changelog/EntityChangedEventPubSubPublisher.java index 32b89c404..092da3ccf 100644 --- a/src/main/java/org/rutebanken/tiamat/changelog/EntityChangedEventPubSubPublisher.java +++ b/src/main/java/org/rutebanken/tiamat/changelog/EntityChangedEventPubSubPublisher.java @@ -15,7 +15,7 @@ package org.rutebanken.tiamat.changelog; -import org.rutebanken.tiamat.config.GooglePubSubConfig; +import org.rutebanken.tiamat.config.PubsubOutboundGateway; import org.rutebanken.tiamat.model.EntityInVersionStructure; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; @@ -29,7 +29,7 @@ public class EntityChangedEventPubSubPublisher extends EntityChangedEventPublisher implements EntityChangedListener { @Autowired - private GooglePubSubConfig.PubsubOutboundGateway pubsubOutboundGateway; + private PubsubOutboundGateway pubsubOutboundGateway; @Value("${changelog.gcp.publish.enabled:true}") private boolean pubSubPublish; diff --git a/src/main/java/org/rutebanken/tiamat/config/GooglePubSubConfig.java b/src/main/java/org/rutebanken/tiamat/config/GooglePubSubConfig.java index 643447623..d8fd1957a 100644 --- a/src/main/java/org/rutebanken/tiamat/config/GooglePubSubConfig.java +++ b/src/main/java/org/rutebanken/tiamat/config/GooglePubSubConfig.java @@ -6,7 +6,6 @@ import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Profile; -import org.springframework.integration.annotation.MessagingGateway; import org.springframework.integration.annotation.ServiceActivator; import org.springframework.messaging.MessageHandler; @@ -21,9 +20,4 @@ public class GooglePubSubConfig { public MessageHandler messageSender(PubSubTemplate pubsubTemplate) { return new PubSubMessageHandler(pubsubTemplate, pubSubTopic); } - - @MessagingGateway(defaultRequestChannel = "pubsubOutputChannel") - public interface PubsubOutboundGateway { - void sendToPubsub(String text); - } } diff --git a/src/main/java/org/rutebanken/tiamat/config/PubsubOutboundGateway.java b/src/main/java/org/rutebanken/tiamat/config/PubsubOutboundGateway.java new file mode 100644 index 000000000..51886ad80 --- /dev/null +++ b/src/main/java/org/rutebanken/tiamat/config/PubsubOutboundGateway.java @@ -0,0 +1,10 @@ +package org.rutebanken.tiamat.config; + +import org.springframework.context.annotation.Profile; +import org.springframework.integration.annotation.MessagingGateway; + +@Profile("google-pubsub") +@MessagingGateway(defaultRequestChannel = "pubsubOutputChannel") +public interface PubsubOutboundGateway { + void sendToPubsub(String text); +} From d8feaab139d98ccdead069c016a82cf5f15d8b5a Mon Sep 17 00:00:00 2001 From: Assad Riaz Date: Tue, 22 Oct 2024 15:19:13 +0200 Subject: [PATCH 2/2] Refactor EntityChangedEventPubSubPublisher to use PubsubTemplate instead for spring-integration-core component. Removed GooglePubSubConfig.java and PubsubOutboundGateway.java, removed spring-integration-core dependency from pom --- pom.xml | 6 ----- .../EntityChangedEventPubSubPublisher.java | 11 +++++---- .../tiamat/config/GooglePubSubConfig.java | 23 ------------------- .../tiamat/config/PubsubOutboundGateway.java | 10 -------- 4 files changed, 7 insertions(+), 43 deletions(-) delete mode 100644 src/main/java/org/rutebanken/tiamat/config/GooglePubSubConfig.java delete mode 100644 src/main/java/org/rutebanken/tiamat/config/PubsubOutboundGateway.java diff --git a/pom.xml b/pom.xml index 8c56a196d..a62612235 100644 --- a/pom.xml +++ b/pom.xml @@ -76,12 +76,6 @@ spring-cloud-gcp-starter-pubsub ${spring-cloud-gcp.version} - - - org.springframework.integration - spring-integration-core - - org.springframework.boot spring-boot-starter-actuator diff --git a/src/main/java/org/rutebanken/tiamat/changelog/EntityChangedEventPubSubPublisher.java b/src/main/java/org/rutebanken/tiamat/changelog/EntityChangedEventPubSubPublisher.java index 092da3ccf..0f642a17e 100644 --- a/src/main/java/org/rutebanken/tiamat/changelog/EntityChangedEventPubSubPublisher.java +++ b/src/main/java/org/rutebanken/tiamat/changelog/EntityChangedEventPubSubPublisher.java @@ -15,7 +15,7 @@ package org.rutebanken.tiamat.changelog; -import org.rutebanken.tiamat.config.PubsubOutboundGateway; +import com.google.cloud.spring.pubsub.core.PubSubTemplate; import org.rutebanken.tiamat.model.EntityInVersionStructure; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; @@ -29,7 +29,10 @@ public class EntityChangedEventPubSubPublisher extends EntityChangedEventPublisher implements EntityChangedListener { @Autowired - private PubsubOutboundGateway pubsubOutboundGateway; + private PubSubTemplate pubSubTemplate; + + @Value("${changelog.topic.name:ror.tiamat.changelog}") + private String pubSubTopic; @Value("${changelog.gcp.publish.enabled:true}") private boolean pubSubPublish; @@ -37,7 +40,7 @@ public class EntityChangedEventPubSubPublisher extends EntityChangedEventPublish @Override public void onChange(EntityInVersionStructure entity) { if (pubSubPublish && isLoggedEntity(entity)) { - pubsubOutboundGateway.sendToPubsub(toEntityChangedEvent(entity, false).toString()); + pubSubTemplate.publish(pubSubTopic,toEntityChangedEvent(entity, false).toString()); } } @@ -46,7 +49,7 @@ public void onChange(EntityInVersionStructure entity) { public void onDelete(EntityInVersionStructure entity) { if (pubSubPublish && isLoggedEntity(entity)) { - pubsubOutboundGateway.sendToPubsub(toEntityChangedEvent(entity, true).toString()); + pubSubTemplate.publish(pubSubTopic,toEntityChangedEvent(entity, true).toString()); } } } diff --git a/src/main/java/org/rutebanken/tiamat/config/GooglePubSubConfig.java b/src/main/java/org/rutebanken/tiamat/config/GooglePubSubConfig.java deleted file mode 100644 index d8fd1957a..000000000 --- a/src/main/java/org/rutebanken/tiamat/config/GooglePubSubConfig.java +++ /dev/null @@ -1,23 +0,0 @@ -package org.rutebanken.tiamat.config; - -import com.google.cloud.spring.pubsub.core.PubSubTemplate; -import com.google.cloud.spring.pubsub.integration.outbound.PubSubMessageHandler; -import org.springframework.beans.factory.annotation.Value; -import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.Configuration; -import org.springframework.context.annotation.Profile; -import org.springframework.integration.annotation.ServiceActivator; -import org.springframework.messaging.MessageHandler; - -@Configuration -@Profile("google-pubsub") -public class GooglePubSubConfig { - @Value("${changelog.topic.name:ror.tiamat.changelog}") - private String pubSubTopic; - - @Bean - @ServiceActivator(inputChannel = "pubsubOutputChannel") - public MessageHandler messageSender(PubSubTemplate pubsubTemplate) { - return new PubSubMessageHandler(pubsubTemplate, pubSubTopic); - } -} diff --git a/src/main/java/org/rutebanken/tiamat/config/PubsubOutboundGateway.java b/src/main/java/org/rutebanken/tiamat/config/PubsubOutboundGateway.java deleted file mode 100644 index 51886ad80..000000000 --- a/src/main/java/org/rutebanken/tiamat/config/PubsubOutboundGateway.java +++ /dev/null @@ -1,10 +0,0 @@ -package org.rutebanken.tiamat.config; - -import org.springframework.context.annotation.Profile; -import org.springframework.integration.annotation.MessagingGateway; - -@Profile("google-pubsub") -@MessagingGateway(defaultRequestChannel = "pubsubOutputChannel") -public interface PubsubOutboundGateway { - void sendToPubsub(String text); -}