Skip to content

Conversation

@JooHyukKim
Copy link
Contributor

Resolves #3135

Copy link
Member

@artembilan artembilan left a 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());
Copy link
Member

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.

// When
Collection<MessageListenerContainer> listeners = registry.getListenerContainersMatching(s -> true);
// Then
assertThrows(UnsupportedOperationException.class, () -> listeners.add(mock(MessageListenerContainer.class)));
Copy link
Member

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.

Copy link
Contributor Author

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) {
Copy link
Member

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.

@JooHyukKim
Copy link
Contributor Author

I've updated the author list and added documentation for the new feature in whats-new.adoc and kafkalistener-lifecycle.adoc.

I noticed there seems to be limited documentation on KafkaListenerEndpointRegistry, particularly methods like getListenerContainers() and getListenerContainer(String). I can
address this in a future PR to enhance docs further. WDYT, @artembilan?

@artembilan
Copy link
Member

Sure! You can add those couple sentences just in this PR. We have a release on Monday, so it will be reviewed immediately .
Thanks

@JooHyukKim JooHyukKim requested a review from artembilan March 16, 2024 06:49
@JooHyukKim
Copy link
Contributor Author

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.
Copy link
Member

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?

Copy link
Contributor Author

@JooHyukKim JooHyukKim Mar 18, 2024

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.

Copy link
Contributor Author

@JooHyukKim JooHyukKim Mar 18, 2024

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 👍🏼

Copy link
Member

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!

Copy link
Contributor Author

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?

Copy link
Member

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

Copy link
Contributor Author

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

Copy link
Contributor Author

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.
Copy link
Member

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!

@JooHyukKim JooHyukKim requested a review from artembilan March 19, 2024 15:22
Copy link
Member

@artembilan artembilan left a 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);
Copy link
Member

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.
Copy link
Member

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.

Copy link
Contributor Author

@JooHyukKim JooHyukKim Mar 19, 2024

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.

@JooHyukKim JooHyukKim requested a review from artembilan March 19, 2024 23:09
@artembilan artembilan merged commit d8e7299 into spring-projects:main Mar 20, 2024
@artembilan
Copy link
Member

@JooHyukKim ,

thank you very much for the contribution; looking forward for more!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Adding new KafkaListenerEndpointRegistry.getListenerContainersMatchingId(predicate: Predicate<String>)

2 participants