Skip to content

Commit 34bde00

Browse files
authored
Merge pull request #18 from majusko/feature/issue-12-configurable-delimiter
resolves #12
2 parents 8c64b6d + d0ad975 commit 34bde00

File tree

4 files changed

+18
-10
lines changed

4 files changed

+18
-10
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@ pulsar.connectionTimeoutSec=10
9191
pulsar.operationTimeoutSec=15
9292
pulsar.startingBackoffIntervalMs=100
9393
pulsar.maxBackoffIntervalSec=10
94+
pulsar.consumerNameDelimiter=
9495
```
9596

9697
Properties explained:
@@ -104,6 +105,7 @@ Properties explained:
104105
- `pulsar.operationTimeoutSec` - Operation timeout.
105106
- `pulsar.startingBackoffIntervalMs` - Duration of time for a backoff interval (Retry algorithm).
106107
- `pulsar.maxBackoffIntervalSec` - The maximum duration of time for a backoff interval (Retry algorithm).
108+
- `pulsar.consumerNameDelimiter` - Consumer names are connection of bean name and method with a delimiter. By default there is no delimiter and words are connected together.
107109

108110
## Contributing
109111

src/main/java/io/github/majusko/pulsar/PulsarProperties.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ public class PulsarProperties {
1313
private Integer operationTimeoutSec = 15;
1414
private Integer startingBackoffIntervalMs = 100;
1515
private Integer maxBackoffIntervalSec = 10;
16+
private String consumerNameDelimiter = "";
1617

1718
public String getServiceUrl() {
1819
return serviceUrl;
@@ -85,4 +86,12 @@ public Integer getMaxBackoffIntervalSec() {
8586
public void setMaxBackoffIntervalSec(Integer maxBackoffIntervalSec) {
8687
this.maxBackoffIntervalSec = maxBackoffIntervalSec;
8788
}
89+
90+
public String getConsumerNameDelimiter() {
91+
return consumerNameDelimiter;
92+
}
93+
94+
public void setConsumerNameDelimiter(String consumerNameDelimiter) {
95+
this.consumerNameDelimiter = consumerNameDelimiter;
96+
}
8897
}

src/main/java/io/github/majusko/pulsar/collector/ConsumerCollector.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
package io.github.majusko.pulsar.collector;
22

33
import io.github.majusko.pulsar.annotation.PulsarConsumer;
4+
import org.springframework.beans.factory.annotation.Value;
45
import org.springframework.beans.factory.config.BeanPostProcessor;
56
import org.springframework.context.annotation.Configuration;
6-
import org.springframework.stereotype.Component;
77

88
import java.util.Arrays;
99
import java.util.Map;
@@ -14,6 +14,9 @@
1414
@Configuration
1515
public class ConsumerCollector implements BeanPostProcessor {
1616

17+
@Value("${pulsar.consumerNameDelimiter:}")
18+
private String consumerNameDelimiter;
19+
1720
private Map<String, ConsumerHolder> consumers = new ConcurrentHashMap<>();
1821

1922
@Override
@@ -23,7 +26,7 @@ public Object postProcessBeforeInitialization(Object bean, String beanName) {
2326
consumers.putAll(Arrays.stream(beanClass.getDeclaredMethods())
2427
.filter($ -> $.isAnnotationPresent(PulsarConsumer.class))
2528
.collect(Collectors.toMap(
26-
method -> beanClass.getName() + "#" + method.getName(),
29+
method -> beanClass.getName() + consumerNameDelimiter + method.getName(),
2730
method -> new ConsumerHolder(method.getAnnotation(PulsarConsumer.class), method, bean))));
2831

2932
return bean;

src/test/java/io/github/majusko/pulsar/PulsarJavaSpringBootStarterApplicationTests.java

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,20 +6,14 @@
66
import io.github.majusko.pulsar.consumer.ConsumerBuilder;
77
import io.github.majusko.pulsar.producer.ProducerFactory;
88
import io.github.majusko.pulsar.producer.PulsarTemplate;
9+
import org.apache.commons.lang3.tuple.ImmutablePair;
910
import org.apache.pulsar.client.api.Consumer;
1011
import org.apache.pulsar.client.api.PulsarClientException;
11-
import org.apache.commons.lang3.tuple.ImmutablePair;
1212
import org.junit.jupiter.api.Assertions;
1313
import org.junit.jupiter.api.Test;
14-
import org.junit.jupiter.api.extension.ExtendWith;
1514
import org.springframework.beans.factory.annotation.Autowired;
16-
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
1715
import org.springframework.boot.test.context.SpringBootTest;
18-
import org.springframework.context.annotation.ComponentScan;
19-
import org.springframework.context.annotation.FilterType;
2016
import org.springframework.context.annotation.Import;
21-
import org.springframework.test.context.ContextConfiguration;
22-
import org.springframework.test.context.junit.jupiter.SpringExtension;
2317

2418
import java.util.HashSet;
2519
import java.util.List;
@@ -62,7 +56,7 @@ void testConsumerRegistration1() throws Exception {
6256
@Test
6357
void testConsumerRegistration2() {
6458
final Class<TestConsumerConfiguration> clazz = TestConsumerConfiguration.class;
65-
final String descriptor = clazz.getName() + "#" + clazz.getMethods()[0].getName();
59+
final String descriptor = clazz.getName() + clazz.getMethods()[0].getName();
6660
final ConsumerHolder consumerHolder = consumerCollector.getConsumer(descriptor).orElse(null);
6761

6862
Assertions.assertNotNull(consumerHolder);

0 commit comments

Comments
 (0)