Skip to content

Commit 781adae

Browse files
refactor record in TopicNamesHolder (#4193)
Signed-off-by: moonyoungCHAE <[email protected]>
1 parent a95ff86 commit 781adae

File tree

4 files changed

+13
-39
lines changed

4 files changed

+13
-39
lines changed

spring-kafka/src/main/java/org/springframework/kafka/config/KafkaListenerEndpointRegistrar.java

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -274,14 +274,6 @@ public void registerEndpoint(KafkaListenerEndpoint endpoint) {
274274

275275
private record KafkaListenerEndpointDescriptor(KafkaListenerEndpoint endpoint,
276276
@Nullable KafkaListenerContainerFactory<?> containerFactory) {
277-
278-
private KafkaListenerEndpointDescriptor(KafkaListenerEndpoint endpoint,
279-
@Nullable KafkaListenerContainerFactory<?> containerFactory) {
280-
281-
this.endpoint = endpoint;
282-
this.containerFactory = containerFactory;
283-
}
284-
285277
}
286278

287279
}

spring-kafka/src/main/java/org/springframework/kafka/retrytopic/EndpointCustomizer.java

Lines changed: 1 addition & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -46,24 +46,6 @@ public interface EndpointCustomizer<T extends MethodKafkaListenerEndpoint<?, ?>>
4646
*/
4747
Collection<TopicNamesHolder> customizeEndpointAndCollectTopics(T listenerEndpoint);
4848

49-
class TopicNamesHolder {
50-
51-
private final String mainTopic;
52-
53-
private final @Nullable String customizedTopic;
54-
55-
TopicNamesHolder(String mainTopic, @Nullable String customizedTopic) {
56-
this.mainTopic = mainTopic;
57-
this.customizedTopic = customizedTopic;
58-
}
59-
60-
String getMainTopic() {
61-
return this.mainTopic;
62-
}
63-
64-
@Nullable
65-
String getCustomizedTopic() {
66-
return this.customizedTopic;
67-
}
49+
record TopicNamesHolder(String mainTopic, @Nullable String customizedTopic) {
6850
}
6951
}

spring-kafka/src/main/java/org/springframework/kafka/retrytopic/RetryTopicConfigurer.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -384,8 +384,8 @@ private void processAndRegisterEndpoint(MethodKafkaListenerEndpoint<?, ?> mainEn
384384
.customizeEndpointAndCollectTopics(endpoint)
385385
.forEach(topicNamesHolder ->
386386
this.destinationTopicProcessor
387-
.registerDestinationTopic(topicNamesHolder.getMainTopic(),
388-
topicNamesHolder.getCustomizedTopic(),
387+
.registerDestinationTopic(topicNamesHolder.mainTopic(),
388+
topicNamesHolder.customizedTopic(),
389389
destinationTopicProperties, context));
390390

391391
registrar.registerEndpoint(endpoint, resolvedFactory);

spring-kafka/src/test/java/org/springframework/kafka/retrytopic/EndpointCustomizerFactoryTests.java

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -170,11 +170,11 @@ void shouldCustomizeEndpointForRetryTopicWithTopic(EndpointHandlerMethod beanMet
170170
String topic1WithSuffix = topics[0] + suffix;
171171
String topic2WithSuffix = topics[1] + suffix;
172172
assertThat(holders).hasSize(2).element(0)
173-
.matches(holder -> holder.getMainTopic().equals(topics[0])
174-
&& holder.getCustomizedTopic().equals(topic1WithSuffix));
173+
.matches(holder -> holder.mainTopic().equals(topics[0])
174+
&& holder.customizedTopic().equals(topic1WithSuffix));
175175
assertThat(holders).hasSize(2).element(1)
176-
.matches(holder -> holder.getMainTopic().equals(topics[1])
177-
&& holder.getCustomizedTopic().equals(topic2WithSuffix));
176+
.matches(holder -> holder.mainTopic().equals(topics[1])
177+
&& holder.customizedTopic().equals(topic2WithSuffix));
178178

179179
String testStringSuffix = testString + suffix;
180180
assertThat(endpoint.getTopics()).contains(topic1WithSuffix, topic2WithSuffix);
@@ -191,11 +191,11 @@ void shouldCustomizeEndpointForRetryTopicWithTopic(EndpointHandlerMethod beanMet
191191
(List<EndpointCustomizer.TopicNamesHolder>) endpointCustomizer.customizeEndpointAndCollectTopics(endpointTPO);
192192

193193
assertThat(holdersTPO).hasSize(2).element(0)
194-
.matches(holder -> holder.getMainTopic().equals(topics[0])
195-
&& holder.getCustomizedTopic().equals(topic1WithSuffix));
194+
.matches(holder -> holder.mainTopic().equals(topics[0])
195+
&& holder.customizedTopic().equals(topic1WithSuffix));
196196
assertThat(holdersTPO).hasSize(2).element(1)
197-
.matches(holder -> holder.getMainTopic().equals(topics[1])
198-
&& holder.getCustomizedTopic().equals(topic2WithSuffix));
197+
.matches(holder -> holder.mainTopic().equals(topics[1])
198+
&& holder.customizedTopic().equals(topic2WithSuffix));
199199

200200
assertThat(endpointTPO.getTopics()).isEmpty();
201201
TopicPartitionOffset[] topicPartitionsToAssign = endpointTPO.getTopicPartitionsToAssign();
@@ -226,8 +226,8 @@ private MethodKafkaListenerEndpoint<Object, Object> getEndpoint(boolean isMulti,
226226
}
227227

228228
private Predicate<EndpointCustomizer.TopicNamesHolder> assertMainTopic(int index) {
229-
return holder -> holder.getCustomizedTopic().equals(topics[index])
230-
&& holder.getMainTopic().equals(topics[index]);
229+
return holder -> holder.customizedTopic().equals(topics[index])
230+
&& holder.mainTopic().equals(topics[index]);
231231
}
232232

233233
private boolean equalsTopicPartitionOffset(TopicPartitionOffset tpo1, TopicPartitionOffset tpo2) {

0 commit comments

Comments
 (0)