Skip to content

[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
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
89 changes: 89 additions & 0 deletions pip/pip-373.md
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: