Package com.linkedin.venice.pubsub
Class PubSubUtil
java.lang.Object
com.linkedin.venice.pubsub.PubSubUtil
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic PropertiesaddPubSubBrokerAddress(Properties properties, String brokerAddress) static longcalculateSeekOffset(long baseOffset, boolean isInclusive) Calculates the seek offset based on the base offset and inclusiveness flag.static <T extends PubSubPosition>
longcomputeOffsetDelta(PubSubTopicPartition partition, PubSubPosition position1, PubSubPosition position2, PubSubConsumerAdapter consumerAdapter) static PubSubPositionfromKafkaOffset(long offset) static StringgeneratePubSubClientId(PubSubClientType pubSubClientType, String clientName, String brokerAddress) Generates a standardized and unique client ID for PubSub clients.static byte[]getBase64DecodedBytes(String bytesString) static StringgetBase64EncodedString(byte[] byteBuffer) static StringgetPubSubAdminConfigPrefix(String adapterConfigPrefix) static StringgetPubSubBrokerAddress(VeniceProperties properties) static StringgetPubSubBrokerAddress(Properties properties) static StringgetPubSubBrokerAddressOrFail(VeniceProperties properties) static StringgetPubSubBrokerAddressOrFail(Properties properties) static StringgetPubSubBrokerAddressWithDefault(VeniceProperties properties, String defaultValue) static StringgetPubSubConsumerConfigPrefix(String adapterConfigPrefix) static StringgetPubSubPositionString(PubSubPositionDeserializer pubSubPositionDeserializer, ByteBuffer pubSubPosition) static StringgetPubSubProducerConfigPrefix(String adapterConfigPrefix) static PubSubSecurityProtocolgetPubSubSecurityProtocolOrDefault(VeniceProperties properties) TODO: Enforce explicit configuration of the PubSub security protocol in all components.static PubSubSecurityProtocolgetPubSubSecurityProtocolOrDefault(Properties properties) Returns thePubSubSecurityProtocolconfigured in the givenProperties, falling back to PLAINTEXT if no value is found.static booleanisPubSubSslProtocol(PubSubSecurityProtocol pubSubSecurityProtocol) Checks if the providedPubSubSecurityProtocolrequires SSL.static booleanisPubSubSslProtocol(String pubSubSecurityProtocol) Checks if the given security protocol name corresponds to a protocol that requires SSL.static PubSubPositionparsePositionWireFormat(String positionWireFormatString, PubSubPositionDeserializer pubSubPositionDeserializer) Parses a position wire format string and converts it to a PubSubPosition.
-
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
InstanceAlreadyExistsExceptionduring 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 thePubSubSecurityProtocolconfigured in the givenProperties, falling back to PLAINTEXT if no value is found.- Parameters:
properties- the JavaPropertiesobject to extract the security protocol from- Returns:
- the resolved
PubSubSecurityProtocol, or PLAINTEXT if not specified
-
isPubSubSslProtocol
Checks if the providedPubSubSecurityProtocolrequires SSL.- Parameters:
pubSubSecurityProtocol- the security protocol to check- Returns:
trueif the protocol uses SSL (either SSL or SASL_SSL),falseotherwise
-
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:
trueif the protocol uses SSL,falseotherwise- Throws:
IllegalArgumentException- if the name does not correspond to a validPubSubSecurityProtocol
-
computeOffsetDelta
public static <T extends PubSubPosition> long computeOffsetDelta(PubSubTopicPartition partition, PubSubPosition position1, PubSubPosition position2, PubSubConsumerAdapter consumerAdapter) -
calculateSeekOffset
public static long calculateSeekOffset(long baseOffset, boolean isInclusive) Calculates the seek offset based on the base offset and inclusiveness flag.- Parameters:
baseOffset- the base offset to calculate fromisInclusive- if true, returns the base offset; if false, returns base offset + 1- Returns:
- the calculated seek offset
-
fromKafkaOffset
-
getBase64EncodedString
-
getBase64DecodedBytes
-
parsePositionWireFormat
public static PubSubPosition parsePositionWireFormat(String positionWireFormatString, PubSubPositionDeserializer pubSubPositionDeserializer) Parses a position wire format string and converts it to a PubSubPosition. The input string should be in the format "typeId:base64EncodedWfBytes".- Parameters:
positionWireFormatString- the position wire format string to parsepubSubPositionDeserializer- the deserializer to convert wire format to position- Returns:
- the parsed PubSubPosition
- Throws:
IllegalArgumentException- if the input string format is invalid
-
getPubSubPositionString
public static String getPubSubPositionString(PubSubPositionDeserializer pubSubPositionDeserializer, ByteBuffer pubSubPosition)
-