Skip to content

Commit f40986b

Browse files
committed
Move default tenant/namespace config prop under spring.pulsar.defaults.topic
1 parent d635c7c commit f40986b

File tree

5 files changed

+60
-33
lines changed

5 files changed

+60
-33
lines changed

spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/pulsar/PulsarConfiguration.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -182,9 +182,10 @@ PulsarFunctionAdministration pulsarFunctionAdministration(PulsarAdministration p
182182
@Bean
183183
@Scope("prototype")
184184
@ConditionalOnMissingBean
185+
@ConditionalOnProperty(name = "spring.pulsar.defaults.topic.enabled", havingValue = "true", matchIfMissing = true)
185186
PulsarTopicBuilder pulsarTopicBuilder() {
186-
return new PulsarTopicBuilder(TopicDomain.persistent, this.properties.getDefaults().getTenant(),
187-
this.properties.getDefaults().getNamespace());
187+
return new PulsarTopicBuilder(TopicDomain.persistent, this.properties.getDefaults().getTopic().getTenant(),
188+
this.properties.getDefaults().getTopic().getNamespace());
188189
}
189190

190191
}

spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/pulsar/PulsarProperties.java

Lines changed: 39 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -250,41 +250,21 @@ public Authentication getAuthentication() {
250250

251251
public static class Defaults {
252252

253-
/**
254-
* Default tenant to use when producing or consuming messages against a
255-
* non-fully-qualified topic URL. When not specified Pulsar uses a default tenant
256-
* of 'public'.
257-
*/
258-
private String tenant;
259-
260-
/**
261-
* Default namespace to use when producing or consuming messages against a
262-
* non-fully-qualified topic URL. When not specified Pulsar uses a default
263-
* namespace of 'default'.
264-
*/
265-
private String namespace;
266-
267253
/**
268254
* List of mappings from message type to topic name and schema info to use as a
269255
* defaults when a topic name and/or schema is not explicitly specified when
270256
* producing or consuming messages of the mapped type.
271257
*/
272258
private List<TypeMapping> typeMappings = new ArrayList<>();
273259

274-
public String getTenant() {
275-
return this.tenant;
276-
}
260+
private Topic topic = new Topic();
277261

278-
public void setTenant(String tenant) {
279-
this.tenant = tenant;
262+
public Topic getTopic() {
263+
return this.topic;
280264
}
281265

282-
public String getNamespace() {
283-
return this.namespace;
284-
}
285-
286-
public void setNamespace(String namespace) {
287-
this.namespace = namespace;
266+
public void setTopic(Topic topic) {
267+
this.topic = topic;
288268
}
289269

290270
public List<TypeMapping> getTypeMappings() {
@@ -331,6 +311,40 @@ public record SchemaInfo(SchemaType schemaType, Class<?> messageKeyType) {
331311

332312
}
333313

314+
public static class Topic {
315+
316+
/**
317+
* Default tenant to use when producing or consuming messages against a
318+
* non-fully-qualified topic URL. When not specified Pulsar uses a default
319+
* tenant of 'public'.
320+
*/
321+
private String tenant;
322+
323+
/**
324+
* Default namespace to use when producing or consuming messages against a
325+
* non-fully-qualified topic URL. When not specified Pulsar uses a default
326+
* namespace of 'default'.
327+
*/
328+
private String namespace;
329+
330+
public String getTenant() {
331+
return this.tenant;
332+
}
333+
334+
public void setTenant(String tenant) {
335+
this.tenant = tenant;
336+
}
337+
338+
public String getNamespace() {
339+
return this.namespace;
340+
}
341+
342+
public void setNamespace(String namespace) {
343+
this.namespace = namespace;
344+
}
345+
346+
}
347+
334348
}
335349

336350
public static class Function {

spring-boot-project/spring-boot-autoconfigure/src/main/resources/META-INF/additional-spring-configuration-metadata.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2068,6 +2068,12 @@
20682068
"name": "spring.neo4j.uri",
20692069
"defaultValue": "bolt://localhost:7687"
20702070
},
2071+
{
2072+
"name": "spring.pulsar.defaults.topic.enabled",
2073+
"type": "java.lang.Boolean",
2074+
"description": "Whether to enable default tenant and namespace support for topics.",
2075+
"defaultValue": true
2076+
},
20712077
{
20722078
"name": "spring.pulsar.function.enabled",
20732079
"type": "java.lang.Boolean",

spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/pulsar/PulsarConfigurationTests.java

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -333,11 +333,17 @@ void whenHasUserDefinedBeanDoesNotAutoConfigureBean() {
333333
.run((context) -> assertThat(context).getBean(PulsarTopicBuilder.class).isSameAs(topicBuilder));
334334
}
335335

336+
@Test
337+
void whenHasDefaultsTopicDisabledPropertyDoesNotCreateBean() {
338+
this.contextRunner.withPropertyValues("spring.pulsar.defaults.topic.enabled=false")
339+
.run((context) -> assertThat(context).doesNotHaveBean(PulsarTopicBuilder.class));
340+
}
341+
336342
@Test
337343
void whenHasDefaultsTenantAndNamespaceAppliedToTopicBuilder() {
338344
List<String> properties = new ArrayList<>();
339-
properties.add("spring.pulsar.defaults.tenant=my-tenant");
340-
properties.add("spring.pulsar.defaults.namespace=my-namespace");
345+
properties.add("spring.pulsar.defaults.topic.tenant=my-tenant");
346+
properties.add("spring.pulsar.defaults.topic.namespace=my-namespace");
341347
this.contextRunner.withPropertyValues(properties.toArray(String[]::new))
342348
.run((context) -> assertThat(context).getBean(PulsarTopicBuilder.class)
343349
.asInstanceOf(InstanceOfAssertFactories.type(PulsarTopicBuilder.class))

spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/pulsar/PulsarPropertiesTests.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -247,7 +247,7 @@ class DefaultsTenantNamespaceProperties {
247247

248248
@Test
249249
void bindWhenValuesNotSpecified() {
250-
assertThat(new PulsarProperties().getDefaults()).satisfies((defaults) -> {
250+
assertThat(new PulsarProperties().getDefaults().getTopic()).satisfies((defaults) -> {
251251
assertThat(defaults.getTenant()).isNull();
252252
assertThat(defaults.getNamespace()).isNull();
253253
});
@@ -256,9 +256,9 @@ void bindWhenValuesNotSpecified() {
256256
@Test
257257
void bindWhenValuesSpecified() {
258258
Map<String, String> map = new HashMap<>();
259-
map.put("spring.pulsar.defaults.tenant", "my-tenant");
260-
map.put("spring.pulsar.defaults.namespace", "my-namespace");
261-
PulsarProperties.Defaults properties = bindProperties(map).getDefaults();
259+
map.put("spring.pulsar.defaults.topic.tenant", "my-tenant");
260+
map.put("spring.pulsar.defaults.topic.namespace", "my-namespace");
261+
PulsarProperties.Defaults.Topic properties = bindProperties(map).getDefaults().getTopic();
262262
assertThat(properties.getTenant()).isEqualTo("my-tenant");
263263
assertThat(properties.getNamespace()).isEqualTo("my-namespace");
264264
}

0 commit comments

Comments
 (0)