From 9064623fb146b51b1e17182fd59d72a59dc59828 Mon Sep 17 00:00:00 2001 From: Chris Bono Date: Sat, 24 Aug 2024 16:35:03 -0500 Subject: [PATCH] Use auto-configured PulsarTopicBuilder (#817) Now that Spring Boot `3.4.0-M2` auto-configures the `PulsarTopicBuilder`, this commit updates ITs, samples, and docs accordingly. --- .../pulsar/inttest/app/ImperativeAppConfig.java | 4 ++-- .../pulsar/inttest/app/ReactiveAppConfig.java | 4 ++-- .../inttest/config/DefaultTenantAndNamespaceTests.java | 8 ++++++-- .../pulsar/inttest/config/ImperativeAppConfig.java | 6 ------ .../pulsar/inttest/config/ReactiveAppConfig.java | 6 ------ .../antora/modules/ROOT/pages/reference/pulsar-admin.adoc | 8 ++++---- .../sample-failover-custom-router/build.gradle | 2 -- .../src/main/java/com/example/FailoverConsumerApp.java | 4 ++-- .../sample-imperative-produce-consume/build.gradle | 2 -- .../java/com/example/ImperativeProduceAndConsumeApp.java | 4 ++-- 10 files changed, 18 insertions(+), 30 deletions(-) diff --git a/integration-tests/src/intTest/java/org/springframework/pulsar/inttest/app/ImperativeAppConfig.java b/integration-tests/src/intTest/java/org/springframework/pulsar/inttest/app/ImperativeAppConfig.java index 5e6fbe82..c89e511b 100644 --- a/integration-tests/src/intTest/java/org/springframework/pulsar/inttest/app/ImperativeAppConfig.java +++ b/integration-tests/src/intTest/java/org/springframework/pulsar/inttest/app/ImperativeAppConfig.java @@ -39,8 +39,8 @@ class ImperativeAppConfig { private static final String TOPIC = "pulsar-inttest-topic"; @Bean - PulsarTopic pulsarTestTopic() { - return new PulsarTopicBuilder().name(TOPIC).numberOfPartitions(1).build(); + PulsarTopic pulsarTestTopic(PulsarTopicBuilder topicBuilder) { + return topicBuilder.name(TOPIC).numberOfPartitions(1).build(); } @Bean diff --git a/integration-tests/src/intTest/java/org/springframework/pulsar/inttest/app/ReactiveAppConfig.java b/integration-tests/src/intTest/java/org/springframework/pulsar/inttest/app/ReactiveAppConfig.java index 732027dd..e6ed60e6 100644 --- a/integration-tests/src/intTest/java/org/springframework/pulsar/inttest/app/ReactiveAppConfig.java +++ b/integration-tests/src/intTest/java/org/springframework/pulsar/inttest/app/ReactiveAppConfig.java @@ -43,8 +43,8 @@ class ReactiveAppConfig { private static final String TOPIC = "pulsar-reactive-inttest-topic"; @Bean - PulsarTopic pulsarTestTopic() { - return new PulsarTopicBuilder().name(TOPIC).numberOfPartitions(1).build(); + PulsarTopic pulsarTestTopic(PulsarTopicBuilder topicBuilder) { + return topicBuilder.name(TOPIC).numberOfPartitions(1).build(); } @Bean diff --git a/integration-tests/src/intTest/java/org/springframework/pulsar/inttest/config/DefaultTenantAndNamespaceTests.java b/integration-tests/src/intTest/java/org/springframework/pulsar/inttest/config/DefaultTenantAndNamespaceTests.java index 791a99ac..5a5b337f 100644 --- a/integration-tests/src/intTest/java/org/springframework/pulsar/inttest/config/DefaultTenantAndNamespaceTests.java +++ b/integration-tests/src/intTest/java/org/springframework/pulsar/inttest/config/DefaultTenantAndNamespaceTests.java @@ -50,7 +50,9 @@ class DefaultTenantAndNamespaceTests { static PulsarContainer PULSAR_CONTAINER = new PulsarContainer(PulsarTestContainerSupport.getPulsarImage()); @Nested - @SpringBootTest(classes = ImperativeAppConfig.class) + @SpringBootTest(classes = ImperativeAppConfig.class, + properties = { "spring.pulsar.defaults.topic.tenant=my-tenant-i", + "spring.pulsar.defaults.topic.namespace=my-namespace-i" }) @ExtendWith(OutputCaptureExtension.class) @ActiveProfiles("inttest.pulsar.imperative") class WithImperativeApp { @@ -66,7 +68,9 @@ void produceConsumeWithDefaultTenantNamespace(CapturedOutput output, } @Nested - @SpringBootTest(classes = ReactiveAppConfig.class) + @SpringBootTest(classes = ReactiveAppConfig.class, + properties = { "spring.pulsar.defaults.topic.tenant=my-tenant-r", + "spring.pulsar.defaults.topic.namespace=my-namespace-r" }) @ExtendWith(OutputCaptureExtension.class) @ActiveProfiles("inttest.pulsar.reactive") class WithReactiveApp { diff --git a/integration-tests/src/intTest/java/org/springframework/pulsar/inttest/config/ImperativeAppConfig.java b/integration-tests/src/intTest/java/org/springframework/pulsar/inttest/config/ImperativeAppConfig.java index aaba9ec2..79f4931f 100644 --- a/integration-tests/src/intTest/java/org/springframework/pulsar/inttest/config/ImperativeAppConfig.java +++ b/integration-tests/src/intTest/java/org/springframework/pulsar/inttest/config/ImperativeAppConfig.java @@ -21,7 +21,6 @@ import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.apache.pulsar.client.api.PulsarClient; -import org.apache.pulsar.common.naming.TopicDomain; import org.apache.pulsar.common.policies.data.TenantInfoImpl; import org.springframework.boot.ApplicationRunner; @@ -51,11 +50,6 @@ class ImperativeAppConfig { static final String FQ_TOPIC = "persistent://my-tenant-i/my-namespace-i/dtant-topic-i"; static final String MSG_PREFIX = "DefaultTenantNamespace-i:"; - @Bean - PulsarTopicBuilder topicBuilder() { - return new PulsarTopicBuilder(TopicDomain.persistent, TENANT, NAMESPACE); - } - @Bean PulsarProducerFactory pulsarProducerFactory(PulsarClient pulsarClient, TopicResolver topicResolver, PulsarTopicBuilder topicBuilder) { diff --git a/integration-tests/src/intTest/java/org/springframework/pulsar/inttest/config/ReactiveAppConfig.java b/integration-tests/src/intTest/java/org/springframework/pulsar/inttest/config/ReactiveAppConfig.java index afb45e43..4bc96b92 100644 --- a/integration-tests/src/intTest/java/org/springframework/pulsar/inttest/config/ReactiveAppConfig.java +++ b/integration-tests/src/intTest/java/org/springframework/pulsar/inttest/config/ReactiveAppConfig.java @@ -21,7 +21,6 @@ import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; -import org.apache.pulsar.common.naming.TopicDomain; import org.apache.pulsar.common.policies.data.TenantInfoImpl; import org.apache.pulsar.reactive.client.api.ReactivePulsarClient; @@ -53,11 +52,6 @@ class ReactiveAppConfig { static final String FQ_TOPIC = "persistent://my-tenant-r/my-namespace-r/dtant-topic-r"; static final String MSG_PREFIX = "DefaultTenantNamespace-r:"; - @Bean - PulsarTopicBuilder topicBuilder() { - return new PulsarTopicBuilder(TopicDomain.persistent, TENANT, NAMESPACE); - } - @Bean ReactivePulsarSenderFactory reactivePulsarSenderFactory(ReactivePulsarClient reactivePulsarClient, PulsarTopicBuilder topicBuilder) { diff --git a/spring-pulsar-docs/src/main/antora/modules/ROOT/pages/reference/pulsar-admin.adoc b/spring-pulsar-docs/src/main/antora/modules/ROOT/pages/reference/pulsar-admin.adoc index 6a6ed031..60ab287f 100644 --- a/spring-pulsar-docs/src/main/antora/modules/ROOT/pages/reference/pulsar-admin.adoc +++ b/spring-pulsar-docs/src/main/antora/modules/ROOT/pages/reference/pulsar-admin.adoc @@ -31,15 +31,15 @@ The following example shows how to add `PulsarTopic` beans to let the `PulsarAdm [source,java,indent=0,subs="verbatim"] ---- @Bean -PulsarTopic simpleTopic { +PulsarTopic simpleTopic(PulsarTopicBuilder topicBuilder) { // This will create a non-partitioned persistent topic in the 'public/default' tenant/namespace - return new PulsarTopicBuilder().name("my-topic").build(); + return topicBuilder.name("my-topic").build(); } @Bean -PulsarTopic partitionedTopic { +PulsarTopic partitionedTopic(PulsarTopicBuilder topicBuilder) { // This will create a persistent topic with 3 partitions in the provided tenant and namespace - return new PulsarTopicBuilder() + return topicBuilder .name("persistent://my-tenant/my-namespace/partitioned-topic") .numberOfPartitions(3) .build(); diff --git a/spring-pulsar-sample-apps/sample-failover-custom-router/build.gradle b/spring-pulsar-sample-apps/sample-failover-custom-router/build.gradle index f796f69d..c2d4c904 100644 --- a/spring-pulsar-sample-apps/sample-failover-custom-router/build.gradle +++ b/spring-pulsar-sample-apps/sample-failover-custom-router/build.gradle @@ -25,8 +25,6 @@ dependencies { implementation 'io.zipkin.reporter2:zipkin-reporter-brave' implementation 'io.zipkin.reporter2:zipkin-sender-urlconnection' developmentOnly 'org.springframework.boot:spring-boot-docker-compose' - // TODO remove when new PulsarTopicBuilder published - implementation project(':spring-pulsar') testImplementation project(':spring-pulsar-test') testRuntimeOnly 'ch.qos.logback:logback-classic' testImplementation "org.springframework.boot:spring-boot-starter-test" diff --git a/spring-pulsar-sample-apps/sample-failover-custom-router/src/main/java/com/example/FailoverConsumerApp.java b/spring-pulsar-sample-apps/sample-failover-custom-router/src/main/java/com/example/FailoverConsumerApp.java index a54c53f2..2c42baba 100644 --- a/spring-pulsar-sample-apps/sample-failover-custom-router/src/main/java/com/example/FailoverConsumerApp.java +++ b/spring-pulsar-sample-apps/sample-failover-custom-router/src/main/java/com/example/FailoverConsumerApp.java @@ -45,8 +45,8 @@ public static void main(String[] args) { } @Bean - PulsarTopic failoverDemoTopic() { - return new PulsarTopicBuilder().name(TOPIC).numberOfPartitions(3).build(); + PulsarTopic failoverDemoTopic(PulsarTopicBuilder topicBuilder) { + return topicBuilder.name(TOPIC).numberOfPartitions(3).build(); } @Bean diff --git a/spring-pulsar-sample-apps/sample-imperative-produce-consume/build.gradle b/spring-pulsar-sample-apps/sample-imperative-produce-consume/build.gradle index efecf96c..552f1e9d 100644 --- a/spring-pulsar-sample-apps/sample-imperative-produce-consume/build.gradle +++ b/spring-pulsar-sample-apps/sample-imperative-produce-consume/build.gradle @@ -21,8 +21,6 @@ ext['pulsar.version'] = "${pulsarVersion}" dependencies { implementation 'org.springframework.boot:spring-boot-starter-pulsar' developmentOnly 'org.springframework.boot:spring-boot-docker-compose' - // TODO remove when new PulsarTopicBuilder published - implementation project(':spring-pulsar') implementation(testFixtures(project(":spring-pulsar"))) implementation project(':spring-pulsar-test') testRuntimeOnly 'ch.qos.logback:logback-classic' diff --git a/spring-pulsar-sample-apps/sample-imperative-produce-consume/src/main/java/com/example/ImperativeProduceAndConsumeApp.java b/spring-pulsar-sample-apps/sample-imperative-produce-consume/src/main/java/com/example/ImperativeProduceAndConsumeApp.java index 13231975..e90c56e5 100644 --- a/spring-pulsar-sample-apps/sample-imperative-produce-consume/src/main/java/com/example/ImperativeProduceAndConsumeApp.java +++ b/spring-pulsar-sample-apps/sample-imperative-produce-consume/src/main/java/com/example/ImperativeProduceAndConsumeApp.java @@ -98,8 +98,8 @@ static class ProduceConsumeWithPartitions { private static final String TOPIC = "produce-consume-partitions"; @Bean - PulsarTopic partitionedTopic() { - return new PulsarTopicBuilder().name(TOPIC).numberOfPartitions(3).build(); + PulsarTopic partitionedTopic(PulsarTopicBuilder topicBuilder) { + return topicBuilder.name(TOPIC).numberOfPartitions(3).build(); } @Bean