Skip to main content

Work with TableView

After setting up your clients, you can explore more to start working with TableView.

Configure TableView

The following is an example of how to configure a TableView.

TableView<String> tv = client.newTableViewBuilder(Schema.STRING)
.topic("my-tableview")
.create()

You can use the available parameters in the loadConf configuration or the API TableViewBuilder to customize your TableView.

NameTypeRequired?
Description
Default
topicstringyesThe topic name of the TableView.N/A
autoUpdatePartitionIntervalintnoThe interval to check for newly added partitions.60 (seconds)
subscriptionNamestringnoThe subscription name of the TableView.null
Tombstone (null-value) messages

TableView treats a message with a null payload as a tombstone - the key is removed from the map.

  • forEach(action) iterates over the current map snapshot only, so it does not surface keys that have been tombstoned.
  • forEachAndListen(action) first runs forEach over the current non-tombstoned entries, then registers the action as a live listener. Every subsequent update - including tombstones - is delivered to the listener as action.accept(key, null). If you need to react to deletions (for example, to clean up downstream state), check for value == null in your listener.

Register listeners

You can register listeners for both existing messages on a topic and new messages coming into the topic by using forEachAndListen, and specify to perform operations for all existing messages by using forEach.

The following is an example of how to register listeners with TableView.

// Register listeners for all existing and incoming messages
tv.forEachAndListen((key, value) -> /*operations on all existing and incoming messages*/)

// Register actions for all existing messages
tv.forEach((key, value) -> /*operations on all existing messages*/)