-
Notifications
You must be signed in to change notification settings - Fork 1.7k
GH-3135 : Adding new ListenerContainerRegistry.getListenerContainersMatchingId(Predicate) for easier usage.
#3137
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
artembilan
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please, add your name to the @author list of all the affected classes.
Also consider to mention this new feature in the whats-new.adoc and in the kafkalistener-lifecycle.adoc.
Thanks
| .stream() | ||
| .filter(entry -> idMatcher.test(entry.getKey())) | ||
| .map(Map.Entry::getValue) | ||
| .collect(Collectors.toList()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is just toList() API.
spring-kafka/src/main/java/org/springframework/kafka/config/KafkaListenerEndpointRegistry.java
Show resolved
Hide resolved
spring-kafka/src/main/java/org/springframework/kafka/listener/ListenerContainerRegistry.java
Show resolved
Hide resolved
| // When | ||
| Collection<MessageListenerContainer> listeners = registry.getListenerContainersMatching(s -> true); | ||
| // Then | ||
| assertThrows(UnsupportedOperationException.class, () -> listeners.add(mock(MessageListenerContainer.class))); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why don't use assertThatExceptionOfType(UnsupportedOperationException.class) instead?
It also probably going to fail on Checkstyle since we have a limited set of allowed static method imports.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Right, looking now there is no pre-existing usage of assertThatExceptionOfType()
| names.forEach(name -> registerListenerWithId(registry, name)); | ||
| } | ||
|
|
||
| private void registerListenerWithId(KafkaListenerEndpointRegistry registry, String id) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks like these both methods can be static.
|
I've updated the author list and added documentation for the new feature in I noticed there seems to be limited documentation on |
|
Sure! You can add those couple sentences just in this PR. We have a release on Monday, so it will be reviewed immediately . |
|
Added some more doc as discussed 👍🏼 cc. @artembilan |
| == Retrieve MessageListenerContainers with by matching a Predicate | ||
|
|
||
| Starting with version 3.2, the `ListenerContainerRegistry` introduces the `getListenerContainersMatching` method. | ||
| This method filters `MessageListenerContainer` instances based on a `Predicate<String>` applied to their IDs. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
After your great docs I wonder if we could extend this new feature to something like this BiPredicate<String, MessageListenerContainer>. This way we may filter desired containers not only by their ids, but via some other option form the container itself.
WDYT?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Makes sense 👍🏼
I wonder if we should have both or just BiPredicate<String, MessageListenerContainer>. 🤔
Extended feature sounds very powerful, but might be too verbose/overkill in someway, knowing that only id has been used and is the key to Map containing MessageContainerListener.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since the String, MessageListenerContainer pair in BiPredicate technically represents the key-value pair Map<String, MessageListenerContainer> listenerContainers stored in the registry, my suggestion is to have both current method and the extended version. I can promise to commit to writing the latter.
But I would follow your call @artembilan 👍🏼
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK. Let's have two of them!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we do a separate PR or do everything in this one?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This one is OK.
Thanks
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Alright, hopefully it would probably take an hour or two
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Trying to build locally, before re-requesting review 😆
| == Retrieve MessageListenerContainers with by matching a Predicate | ||
|
|
||
| Starting with version 3.2, the `ListenerContainerRegistry` introduces the `getListenerContainersMatching` method. | ||
| This method filters `MessageListenerContainer` instances based on a `Predicate<String>` applied to their IDs. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK. Let's have two of them!
…stenerContainer> idAndContainerMatcher)
artembilan
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The API is great: only some cosmetic concerns in regards of our code style rules.
Thanks
| * @see #getListenerContainerIds() | ||
| * @see #getListenerContainersMatching(Predicate) | ||
| */ | ||
| Collection<MessageListenerContainer> getListenerContainersMatching(BiPredicate<String, MessageListenerContainer> idAndContainerMatcher); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's see if you can follow the rule no more than 120 symbols per line!
| [[get-listener-containers-matching]] | ||
| == Enhanced Retrieval of MessageListenerContainers | ||
|
|
||
| Introduced in version 3.2, the `ListenerContainerRegistry` provides advanced methods for dynamically filtering `MessageListenerContainer` instances, enhancing management capabilities. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This file is fully specific to particular version we mention in the beginning of the file.
More over the content of the file is just a list of topics with links to details.
You do show enough in the kafkalistener-lifecycle.adoc, but that all must not be duplicated in What's New file.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
True, thank you for pointing out!
Modified the part to only show the essence.
...kafka/src/test/java/org/springframework/kafka/config/KafkaListenerEndpointRegistryTests.java
Show resolved
Hide resolved
|
thank you very much for the contribution; looking forward for more! |
Resolves #3135