Skip to content

Commit 7c8f575

Browse files
authored
[Doc] Add new section of content for TableView (#13956)
* Draft version * add tableview to introductory paragraph add tableview to introductory paragraph * Updates as per review comments
1 parent 1d4ca6b commit 7c8f575

File tree

2 files changed

+35
-2
lines changed

2 files changed

+35
-2
lines changed

site2/docs/assets/tableview.png

52 KB
Loading

site2/docs/client-libraries-java.md

+35-2
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@ title: Pulsar Java client
44
sidebar_label: Java
55
---
66

7-
You can use a Pulsar Java client to create the Java [producer](#producer), [consumer](#consumer), and [readers](#reader) of messages and to perform [administrative tasks](admin-api-overview.md). The current Java client version is **{{pulsar:version}}**.
7+
You can use a Pulsar Java client to create the Java [producer](#producer), [consumer](#consumer), [readers](#reader) and [TableView]](#tableview) of messages and to perform [administrative tasks](admin-api-overview.md). The current Java client version is **{{pulsar:version}}**.
88

9-
All the methods in [producer](#producer), [consumer](#consumer), and [reader](#reader) of a Java client are thread-safe.
9+
All the methods in [producer](#producer), [consumer](#consumer), [readers](#reader) and [TableView]](#tableview) of a Java client are thread-safe.
1010

1111
Javadoc for the Pulsar client is divided into two domains by package as follows.
1212

@@ -760,6 +760,39 @@ pulsarClient.newReader()
760760
761761
Total hash range size is 65536, so the max end of the range should be less than or equal to 65535.
762762
763+
764+
## TableView
765+
766+
The TableView interface serves an encapsulated access pattern, providing a continuously updated key-value map view of the compacted topic data. Messages without keys will be ignored.
767+
768+
With TableView, Pulsar clients can fetch all the message updates from a topic and construct a map with the latest values of each key. These values can then be used to build a local cache of data. In addition, you can register consumers with the TableView by specifying a listener to perform a scan of the map and then receive notifications when new messages are received. Consequently, event handling can be triggered to serve use cases, such as event-driven applications and message monitoring.
769+
770+
> **Note:** Each TableView uses one Reader instance per partition, and reads the topic starting from the compacted view by default. It is highly recommended to enable automatic compaction by [configuring the topic compaction policies](cookbooks-compaction.md#configuring-compaction-to-run-automatically) for the given topic or namespace. More frequent compaction results in shorter startup times because less data is replayed to reconstruct the TableView of the topic.
771+
772+
The following figure illustrates the dynamic construction of a TableView updated with newer values of each key.
773+
![TableView](assets/tableview.png)
774+
775+
### Configure TableView
776+
777+
The following is an example of how to configure a TableView.
778+
779+
```
780+
try (TableView<String> tv = client.newTableViewBuilder(Schema.STRING)
781+
.topic("tableview-test")
782+
.create()) {
783+
String value = tv.get("my-key");
784+
System.out.println("Key's value: " + value);
785+
}
786+
```
787+
788+
You can use the available parameters in the `loadConf` configuration or related [API](https://pulsar.apache.org/api/client/2.10.0-SNAPSHOT/org/apache/pulsar/client/api/TableViewBuilder.html) to customize your TableView.
789+
790+
| Name | Type| Required? | <div style="width:300px">Description</div> | Default
791+
|---|---|---|---|---
792+
| `topic` | string | yes | The topic name of the TableView. | N/A
793+
| `autoUpdatePartitionInterval` | int | no | The interval to check for newly added partitions. | 60 (seconds)
794+
795+
763796
## Schema
764797
765798
In Pulsar, all message data consists of byte arrays "under the hood." [Message schemas](schema-get-started.md) enable you to use other types of data when constructing and handling messages (from simple types like strings to more complex, application-specific types). If you construct, say, a [producer](#producer) without specifying a schema, then the producer can only produce messages of type `byte[]`. The following is an example.

0 commit comments

Comments
 (0)