Class PubSubUtil

java.lang.Object
com.linkedin.venice.pubsub.PubSubUtil

public final class PubSubUtil extends Object
  • Constructor Details

    • PubSubUtil

      public PubSubUtil()
  • Method Details

    • getPubSubBrokerAddress

      public static String getPubSubBrokerAddress(Properties properties)
    • getPubSubBrokerAddress

      public static String getPubSubBrokerAddress(VeniceProperties properties)
    • getPubSubBrokerAddressWithDefault

      public static String getPubSubBrokerAddressWithDefault(VeniceProperties properties, String defaultValue)
    • getPubSubBrokerAddressOrFail

      public static String getPubSubBrokerAddressOrFail(VeniceProperties properties)
    • getPubSubBrokerAddressOrFail

      public static String getPubSubBrokerAddressOrFail(Properties properties)
    • addPubSubBrokerAddress

      public static Properties addPubSubBrokerAddress(Properties properties, String brokerAddress)
    • generatePubSubClientId

      public static String generatePubSubClientId(PubSubClientType pubSubClientType, String clientName, String brokerAddress)
      Generates a standardized and unique client ID for PubSub clients.

      This ensures uniqueness in client IDs, preventing naming collisions that could cause InstanceAlreadyExistsException during JMX metric registration. If multiple PubSub clients share the same client ID, underlying client libraries (e.g., Kafka) may fail JMX registration, resulting in runtime errors. By appending a timestamp, this method guarantees that each generated ID is unique.

      If the provided client name is null, it defaults to "venice-pubsub-client" followed by the host name. If the broker address is null, it defaults to an empty string. The generated client ID follows the format:

      clientName-brokerAddress-timestamp

      Parameters:
      clientName - The name of the client (can be null, defaults to "venice-pubsub-client" + host name).
      brokerAddress - The PubSub broker address (can be null, defaults to an empty string).
      Returns:
      A unique client ID in the format: clientName-brokerAddress-timestamp.
    • getPubSubProducerConfigPrefix

      public static String getPubSubProducerConfigPrefix(String adapterConfigPrefix)
    • getPubSubConsumerConfigPrefix

      public static String getPubSubConsumerConfigPrefix(String adapterConfigPrefix)
    • getPubSubAdminConfigPrefix

      public static String getPubSubAdminConfigPrefix(String adapterConfigPrefix)
    • getPubSubSecurityProtocolOrDefault

      public static PubSubSecurityProtocol getPubSubSecurityProtocolOrDefault(VeniceProperties properties)
      TODO: Enforce explicit configuration of the PubSub security protocol in all components. Avoid defaulting to PubSubSecurityProtocol.PLAINTEXT. If the protocol is not explicitly defined via configuration, fail fast during startup to prevent silent misconfigurations.
      Parameters:
      properties - VeniceProperties containing configuration keys
      Returns:
      the resolved PubSubSecurityProtocol
    • getPubSubSecurityProtocolOrDefault

      public static PubSubSecurityProtocol getPubSubSecurityProtocolOrDefault(Properties properties)
      Returns the PubSubSecurityProtocol configured in the given Properties, falling back to PLAINTEXT if no value is found.
      Parameters:
      properties - the Java Properties object to extract the security protocol from
      Returns:
      the resolved PubSubSecurityProtocol, or PLAINTEXT if not specified
    • isPubSubSslProtocol

      public static boolean isPubSubSslProtocol(PubSubSecurityProtocol pubSubSecurityProtocol)
      Checks if the provided PubSubSecurityProtocol requires SSL.
      Parameters:
      pubSubSecurityProtocol - the security protocol to check
      Returns:
      true if the protocol uses SSL (either SSL or SASL_SSL), false otherwise
    • isPubSubSslProtocol

      public static boolean isPubSubSslProtocol(String pubSubSecurityProtocol)
      Checks if the given security protocol name corresponds to a protocol that requires SSL.
      Parameters:
      pubSubSecurityProtocol - the name of the security protocol (case-insensitive)
      Returns:
      true if the protocol uses SSL, false otherwise
      Throws:
      IllegalArgumentException - if the name does not correspond to a valid PubSubSecurityProtocol
    • diffPubSubPositions

      public static long diffPubSubPositions(PubSubPosition position1, PubSubPosition position2)
      Computes the difference in numeric offsets between two PubSubPosition instances.

      If both positions are EARLIEST or both are LATEST, returns 0.

      If one of the positions is EARLIEST and the other is LATEST, it returns Long.MIN_VALUE or Long.MAX_VALUE to represent symbolic extremes.

      Parameters:
      position1 - The first position.
      position2 - The second position.
      Returns:
      The numeric difference: (position1 - position2).
      Throws:
      IllegalArgumentException - if either position is null.
    • comparePubSubPositions

      public static int comparePubSubPositions(PubSubPosition position1, PubSubPosition position2)
      Compares two PubSubPosition instances by their symbolic or numeric ordering.

      This method defines the following ordering: EARLIEST < numeric offsets < LATEST

      Parameters:
      position1 - The first position.
      position2 - The second position.
      Returns:
      A negative integer, zero, or a positive integer if position1 is less than, equal to, or greater than position2, respectively.
      Throws:
      IllegalArgumentException - if either position is null.