Work with TableView

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

Configure TableView

  • Java
  • C++

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

  1. TableView<String> tv = client.newTableViewBuilder(Schema.STRING)
  2. .topic("my-tableview")
  3. .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

This feature is supported in C++ client 3.2.0 or later versions.

  1. ClientConfiguration clientConfiguration;
  2. clientConfiguration.setPartititionsUpdateInterval(100);
  3. Client client("pulsar://localhost:6650", clientConfiguration);
  4. TableViewConfiguration tableViewConfiguration{schemaInfo, "test-subscription-name"};
  5. TableView tableView;
  6. client.createTableView("my-tableview", tableViewConfiguration, tableView)

You can use the following parameters to customize your TableView.

NameTypeRequired?
Description
Default
topicstringyesThe topic name of the TableView.N/A
schemaInfostructnoDeclare the schema of the data that this TableView can accept. The schema is checked against the schema of the topic, and the TableView creation fails if it’s incompatible.N/A
subscriptionNamestringnoThe subscription name of the TableView.reader-{random string}
partititionsUpdateIntervalintnoTopic partitions update interval in seconds. In the C++ client, partititionsUpdateInterval is global within the same client.60

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.

  • Java
  • C++
  1. // Register listeners for all existing and incoming messages
  2. tv.forEachAndListen((key, value) -> /*operations on all existing and incoming messages*/)
  3. // Register actions for all existing messages
  4. tv.forEach((key, value) -> /*operations on all existing messages*/)
  1. ```cpp
  2. // Register listeners for all existing and incoming messages
  3. tableView.forEach([](const std::string& key, const std::string& value) {});
  4. // Register actions for all existing messages
  5. tableView.forEachAndListen([](const std::string& key, const std::string& value) {});
  6. ```