-
Notifications
You must be signed in to change notification settings - Fork 3.6k
[pip] PIP-373 Support to specify message listeners in TableView constructor #23167
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
Open
heesung-sn
wants to merge
2
commits into
apache:master
Choose a base branch
from
heesung-sn:pip-371
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 1 commit
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
# PIP-371: Support to specify message listeners in TableView constructor | ||
|
||
# Background knowledge | ||
|
||
### TableView | ||
Ref: https://pulsar.apache.org/docs/next/concepts-clients/#tableview | ||
|
||
### TableView Listeners | ||
TableView runs the registered listeners on each received message. TableView users could utilize TableView Listeners for event-sourcing applications. | ||
|
||
### How to Register TableView Listeners | ||
|
||
Currently, `TableView#foreachAndListen` and `TableView#listen` interfaces are used to register listeners. | ||
|
||
# Motivation | ||
issue : https://github.com/apache/pulsar/issues/23158 | ||
|
||
As reported in the above issue, currently, the TableView listener registration methods, `foreachAndListen` and `listen`, are being called after `TableView#start()`. This timing issue can result in some messages being missed or not handled if the listeners are registered too late. | ||
|
||
Additionally, the current implementation of these listeners does not distinguish between existing messages (those present before the TableView started) and tail (future) messages (those received after the TableView started). Some business logic may require different handling for these two types of messages, but the current design does not support this differentiation. | ||
|
||
|
||
|
||
# Goals | ||
|
||
## In Scope | ||
|
||
- Support specifying TableView Listeners in TableView builder and constructor, so that TableView can register listeners as part of instance init and accordingly call them for all messages. | ||
- Support specifying TableView Listeners for existing and tail messages separately. | ||
- This design is based on Pulsar-Java-Client. | ||
|
||
# Detailed Design | ||
|
||
## Design & Implementation Details | ||
|
||
Add followings in TableViewBuilder.java | ||
```java | ||
/** | ||
* Set the message listeners. | ||
* If {@link TableViewBuilder#existingMessageListeners} are not specified, | ||
* these listeners are used for both | ||
* existing and tailing(future) messages in the topic. | ||
* @param listeners message listeners | ||
* @return the {@link TableViewBuilder} builder instance | ||
*/ | ||
TableViewBuilder<T> messageListeners(BiConsumer<String, T>... listeners); | ||
|
||
/** | ||
* Set the message listeners separately for existing messages in the topic. | ||
* @param listeners message listeners | ||
* @return the {@link TableViewBuilder} builder instance | ||
*/ | ||
TableViewBuilder<T> existingMessageListeners(BiConsumer<String, T>... listeners); | ||
|
||
``` | ||
|
||
|
||
Add followings in TableViewConfigurationData.java | ||
```java | ||
private BiConsumer[] messageListeners; | ||
private BiConsumer[] existingMessageListeners; | ||
``` | ||
|
||
Add followings in TableViewImpl.java | ||
```java | ||
private final List<BiConsumer<String, T>> existingMessageListeners; | ||
``` | ||
|
||
Update followings in TableViewImpl.java | ||
```java | ||
|
||
// before | ||
private void handleMessage(Message<T> msg) | ||
// after | ||
private void handleMessage(Message<T> msg, boolean handleExistingMessage) | ||
|
||
``` | ||
|
||
# Backward & Forward Compatibility | ||
|
||
Compatible. | ||
|
||
# Links | ||
|
||
<!-- | ||
Updated afterwards | ||
--> | ||
* Mailing List discussion thread: | ||
* Mailing List voting thread: |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
I don't think that it's a great idea to use this for both types. If someone wants the listener on both types, why not just register it for the other type of listener separately?
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.
That will require setting the same listener for both, which I think is redundant.
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.
I dont have strong opinion here, but I thought that we want the client design for less code.