Interface TableViewBuilder<T>


@Public @Evolving public interface TableViewBuilder<T>
TableViewBuilder is used to configure and create instances of TableView.
Since:
2.10.0
See Also:
  • Method Details

    • loadConf

      TableViewBuilder<T> loadConf(Map<String,Object> config)
      Load the configuration from provided config map.

      Example:

       Map<String, Object> config = new HashMap<>();
       config.put("topicName", "test-topic");
       config.put("autoUpdatePartitionsSeconds", "300");
      
       TableViewBuilder<byte[]> builder = ...;
       builder = builder.loadConf(config);
      
       TableView<byte[]> tableView = builder.create();
       
      Parameters:
      config - configuration to load
      Returns:
      the TableViewBuilder instance
    • create

      Finalize the creation of the TableView instance.

      This method will block until the tableView is created successfully or an exception is thrown.

      Returns:
      the TableView instance
      Throws:
      PulsarClientException - if the tableView creation fails
    • createAsync

      CompletableFuture<TableView<T>> createAsync()
      Finalize the creation of the TableView instance in asynchronous mode.

      This method will return a CompletableFuture that can be used to access the instance when it's ready.

      Returns:
      the TableView instance
    • createMapped

      <V> TableView<V> createMapped(TableViewMessageMapper<T,V> mapper) throws PulsarClientException
      Creates a TableView instance where the values are produced by a user-defined mapper from each message.

      This provides a flexible way to create a key-value view over a topic, allowing users to extract data from the message payload, properties, and other metadata into a custom object of type V. To get a view of the full Message objects, use msg -> msg as the mapper. Message pooling is not used for mapped table views, so it is safe to keep a reference to the Message instance passed to the mapper. A retained Message holds more than its payload, though: it also keeps its metadata, schema and a reference to the connection it was received on. For a topic with many keys, prefer a mapper that copies the needed fields into a value object over msg -> msg.

      A keyed message with an empty payload is a tombstone: the key is removed from the view and the mapper is not called for it. If the mapper returns null, the message is also treated as a tombstone. If the mapper throws, the message is skipped and TableViewMessageMapper.onMappingError(Message, Throwable) is called; the key keeps its previous value.

      A topicCompactionStrategyClassName loaded with loadConf(Map) is rejected for mapped table views: a TopicCompactionStrategy compares values of the topic's schema type, which a mapped table view does not store.

      Type Parameters:
      V - the type of the values in the TableView
      Parameters:
      mapper - the mapper that produces the value of type V for each Message
      Returns:
      the TableView instance
      Throws:
      PulsarClientException - if the tableView creation fails
      IllegalArgumentException - if the mapper is null or a topic compaction strategy is configured
    • createMappedAsync

      <V> CompletableFuture<TableView<V>> createMappedAsync(TableViewMessageMapper<T,V> mapper)
      Creates a TableView instance in asynchronous mode where the values are produced by a user-defined mapper from each message.

      See createMapped(TableViewMessageMapper) for the mapping contract.

      Type Parameters:
      V - the type of the values in the TableView
      Parameters:
      mapper - the mapper that produces the value of type V for each Message
      Returns:
      a future that can be used to access the TableView instance when it's ready; it fails with IllegalArgumentException if the mapper is null or a topic compaction strategy is configured
    • topic

      TableViewBuilder<T> topic(String topic)
      Set the topic name of the TableView.
      Parameters:
      topic - the name of the topic to create the TableView
      Returns:
      the TableViewBuilder builder instance
    • autoUpdatePartitionsInterval

      TableViewBuilder<T> autoUpdatePartitionsInterval(int interval, TimeUnit unit)
      Set the interval of updating partitions (default: 1 minute).
      Parameters:
      interval - the interval of updating partitions
      unit - the time unit of the interval
      Returns:
      the TableViewBuilder builder instance
    • subscriptionName

      TableViewBuilder<T> subscriptionName(String subscriptionName)
      Set the subscription name of the TableView.
      Parameters:
      subscriptionName - the name of the subscription to the topic
      Returns:
      the TableViewBuilder builder instance
    • cryptoKeyReader

      TableViewBuilder<T> cryptoKeyReader(CryptoKeyReader cryptoKeyReader)
      Set the CryptoKeyReader to decrypt the message payloads.
      Parameters:
      cryptoKeyReader - CryptoKeyReader object
      Returns:
      the TableViewBuilder builder instance
    • defaultCryptoKeyReader

      TableViewBuilder<T> defaultCryptoKeyReader(String privateKey)
      Set the default implementation of CryptoKeyReader.

      Configure the key reader to be used to decrypt message payloads.

      Parameters:
      privateKey - the private key that is always used to decrypt message payloads.
      Returns:
      the TableViewBuilder builder instance
    • defaultCryptoKeyReader

      TableViewBuilder<T> defaultCryptoKeyReader(Map<String,String> privateKeys)
      Set the default implementation of CryptoKeyReader.

      Configure the key reader to be used to decrypt message payloads.

      Parameters:
      privateKeys - the map of private key names and their URIs used to decrypt message payloads.
      Returns:
      the TableViewBuilder builder instance
    • cryptoFailureAction

      TableViewBuilder<T> cryptoFailureAction(ConsumerCryptoFailureAction action)
      Set the ConsumerCryptoFailureAction to specify.
      Parameters:
      action - the action to take when the decoding fails
      Returns:
      the TableViewBuilder builder instance