Interface TableViewMessageMapper<T,V>

Type Parameters:
T - the message schema type
V - the type of the values stored in the table view
Functional Interface:
This is a functional interface and can therefore be used as the assignment target for a lambda expression or method reference.

@Public @Evolving @FunctionalInterface public interface TableViewMessageMapper<T,V>
Converts the messages of a topic into the values of a TableView created with TableViewBuilder.createMapped(TableViewMessageMapper) or TableViewBuilder.createMappedAsync(TableViewMessageMapper).

The interface is functional: createMapped(msg -> msg.getProperty("region")) maps each message to a value, and createMapped(msg -> msg) builds a TableView<Message<T>> that exposes the complete messages. Implement the interface as a class to customize onMappingError(Message, Throwable).

The table view invokes both methods on the client's internal thread, one message at a time in the order the messages are read. They must not block. Message pooling is disabled for mapped table views, so the Message passed to the mapper may be retained by the value.

Later versions may add further callbacks as default methods that do nothing unless overridden.

  • Method Summary

    Modifier and Type
    Method
    Description
    map(Message<T> message)
    Maps a message to the value stored in the table view for the message key.
    default boolean
    onMappingError(Message<T> message, Throwable error)
    Called when map(Message) throws for a message.
  • Method Details

    • map

      V map(Message<T> message) throws Exception
      Maps a message to the value stored in the table view for the message key.

      The mapper is only called for keyed messages with a non-empty payload. A keyed message with an empty payload is a tombstone: the key is removed from the view without calling the mapper, so a mapper that derives the value from the key or the properties alone never sees such a message. Returning null has the same effect as a tombstone.

      If the mapper throws, the message is skipped: the key keeps its previous value in the view (or stays absent), listeners are not notified, and onMappingError(Message, Throwable) is called.

      Parameters:
      message - the message to map, never a tombstone
      Returns:
      the value to store for the message key, or null to remove the key
      Throws:
      Exception - if the message cannot be mapped, in which case the message is skipped
    • onMappingError

      default boolean onMappingError(Message<T> message, Throwable error)
      Called when map(Message) throws for a message. The message has already been skipped and the view is unchanged for its key; this callback cannot alter that outcome. It exists to report the failure the way the application needs, for instance to record a metric or to signal another thread that the view can no longer be trusted. An implementation must not block and must not close the table view from this thread.

      The default implementation returns false, which makes the table view log the failure at ERROR level together with the topic, key and message id. Return true to indicate that the failure has been handled and must not be logged. Exceptions thrown by this method are logged and ignored.

      Parameters:
      message - the message that could not be mapped
      error - the exception thrown by map(Message)
      Returns:
      true if the failure has been handled, false to let the table view log it