You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardexpand all lines: site2/docs/client-libraries-java.md
+35-2
Original file line number
Diff line number
Diff line change
@@ -4,9 +4,9 @@ title: Pulsar Java client
4
4
sidebar_label: Java
5
5
---
6
6
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}}**.
8
8
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.
10
10
11
11
Javadoc for the Pulsar client is divided into two domains by package as follows.
12
12
@@ -760,6 +760,39 @@ pulsarClient.newReader()
760
760
761
761
Total hash range size is 65536, so the max end of the range should be less than or equal to 65535.
762
762
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
+

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
+
763
796
## Schema
764
797
765
798
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