Class PubSubUtil
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic Properties
addPubSubBrokerAddress
(Properties properties, String brokerAddress) static int
comparePubSubPositions
(PubSubPosition position1, PubSubPosition position2) Compares twoPubSubPosition
instances by their symbolic or numeric ordering.static long
diffPubSubPositions
(PubSubPosition position1, PubSubPosition position2) Computes the difference in numeric offsets between twoPubSubPosition
instances.static String
generatePubSubClientId
(PubSubClientType pubSubClientType, String clientName, String brokerAddress) Generates a standardized and unique client ID for PubSub clients.static String
getPubSubAdminConfigPrefix
(String adapterConfigPrefix) static String
getPubSubBrokerAddress
(VeniceProperties properties) static String
getPubSubBrokerAddress
(Properties properties) static String
getPubSubBrokerAddressOrFail
(VeniceProperties properties) static String
getPubSubBrokerAddressOrFail
(Properties properties) static String
getPubSubBrokerAddressWithDefault
(VeniceProperties properties, String defaultValue) static String
getPubSubConsumerConfigPrefix
(String adapterConfigPrefix) static String
getPubSubProducerConfigPrefix
(String adapterConfigPrefix) static PubSubSecurityProtocol
getPubSubSecurityProtocolOrDefault
(VeniceProperties properties) TODO: Enforce explicit configuration of the PubSub security protocol in all components.static PubSubSecurityProtocol
getPubSubSecurityProtocolOrDefault
(Properties properties) Returns thePubSubSecurityProtocol
configured in the givenProperties
, falling back to PLAINTEXT if no value is found.static boolean
isPubSubSslProtocol
(PubSubSecurityProtocol pubSubSecurityProtocol) Checks if the providedPubSubSecurityProtocol
requires SSL.static boolean
isPubSubSslProtocol
(String pubSubSecurityProtocol) Checks if the given security protocol name corresponds to a protocol that requires SSL.
-
Constructor Details
-
PubSubUtil
public PubSubUtil()
-
-
Method Details
-
getPubSubBrokerAddress
-
getPubSubBrokerAddress
-
getPubSubBrokerAddressWithDefault
public static String getPubSubBrokerAddressWithDefault(VeniceProperties properties, String defaultValue) -
getPubSubBrokerAddressOrFail
-
getPubSubBrokerAddressOrFail
-
addPubSubBrokerAddress
-
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
-
getPubSubConsumerConfigPrefix
-
getPubSubAdminConfigPrefix
-
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
Returns thePubSubSecurityProtocol
configured in the givenProperties
, falling back to PLAINTEXT if no value is found.- Parameters:
properties
- the JavaProperties
object to extract the security protocol from- Returns:
- the resolved
PubSubSecurityProtocol
, or PLAINTEXT if not specified
-
isPubSubSslProtocol
Checks if the providedPubSubSecurityProtocol
requires SSL.- Parameters:
pubSubSecurityProtocol
- the security protocol to check- Returns:
true
if the protocol uses SSL (either SSL or SASL_SSL),false
otherwise
-
isPubSubSslProtocol
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 validPubSubSecurityProtocol
-
diffPubSubPositions
Computes the difference in numeric offsets between twoPubSubPosition
instances.If both positions are
EARLIEST
or both areLATEST
, returns0
.If one of the positions is
EARLIEST
and the other isLATEST
, it returnsLong.MIN_VALUE
orLong.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 isnull
.
-
comparePubSubPositions
Compares twoPubSubPosition
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 isnull
.
-