Class SchemaResolverProperties


  • public class SchemaResolverProperties
    extends BaseProperties
    A class for configuring Schema Resolver properties. This class is used by SchemaResolver
    See Also:
    SchemaResolver
    • Field Detail

      • FIND_LATEST_ARTIFACT

        public static final String FIND_LATEST_ARTIFACT
        Optional boolean flag that determines whether serializer classes should attempt to locate the most recent artifact in the registry for the given groupId and artifactId combination. GroupId and artifactId are configured via ArtifactReferenceResolverStrategy.
        See Also:
        Constant Field Values
      • EXPLICIT_ARTIFACT_VERSION

        public static final String EXPLICIT_ARTIFACT_VERSION
        Optional property that explicitly sets the version used for querying an artifact in the registry. This property is only applicable for serializers. Overrides the version returned by the ArtifactReferenceResolverStrategy

        Note: If this property and the FIND_LATEST_ARTIFACT are set to true, this property takes precedence.

        See Also:
        Constant Field Values
      • EXPLICIT_ARTIFACT_ARTIFACT_ID

        public static final String EXPLICIT_ARTIFACT_ARTIFACT_ID
        Optional property that explicitly sets the artifactId used for querying an artifact in the registry. This property is only applicable for serializers. Overrides the artifactId returned by the ArtifactReferenceResolverStrategy
        See Also:
        Constant Field Values
      • EXPLICIT_ARTIFACT_GROUP_ID

        public static final String EXPLICIT_ARTIFACT_GROUP_ID
        Optional property that explicitly sets the groupId used for querying an artifact in the registry. This property is only applicable for serializers. Overrides the groupId returned by the ArtifactReferenceResolverStrategy
        See Also:
        Constant Field Values
      • TRUST_STORE_PATH

        public static final String TRUST_STORE_PATH
        Property key for specifying the path to the trust store file.

        This property is used to set the path to the trust store file that contains trusted CA certificates. It's used when connecting to a schema registry over HTTPS and the server's certificate is not in the default trust store defined by the JDK.

        The value should be a String representing the file path to the trust store or null when not in use.

        Example usage:

         properties.put(TRUST_STORE_PATH, "/path/to/truststore.jks");
         
        See Also:
        Constant Field Values
      • TRUST_STORE_PASSWORD

        public static final String TRUST_STORE_PASSWORD
        Property key for specifying the password of the trust store.

        This property is used when TRUST_STORE_PATH is provided. It provides the password required to access the trust store. When TRUST_STORE_PATH is not set, this property will have no effect.

        The value should be a String representing the password of the trust store or null when not in use.

        Example usage:

         properties.put(TRUST_STORE_PASSWORD, "truststore_password");
         
        See Also:
        Constant Field Values
      • VALIDATE_CERTIFICATE

        public static final String VALIDATE_CERTIFICATE
        Property key for enabling or disabling certificate validation.

        This property determines whether the client should validate the server's SSL certificate when connecting to the schema registry over HTTPS.

        By Default this property is set to true.

        The value should be a Boolean or a String that can be parsed as a boolean. If set to true, certificate validation will be performed. If set to false, certificate validation will be skipped (not recommended for production use).

        Example usage:

         // Using a Boolean
         properties.put(VALIDATE_CERTIFICATE, true);
        
         // Using a String
         properties.put(VALIDATE_CERTIFICATE, "true");
         
        See Also:
        Constant Field Values
      • ARTIFACT_RESOLVER_STRATEGY

        public static final String ARTIFACT_RESOLVER_STRATEGY
        Property key for specifying a class that implements ArtifactReferenceResolverStrategy

        This property allows the user to specify either an existing ArtifactReferenceResolverStrategy or provide a custom implementation. The ArtifactReferenceResolverStrategy is responsible for determining the specific ArtifactReference for a given data record, enabling the system to locate or register the correct schema in the registry.

        The value associated with this key should be one of:

        • A String representing the fully qualified class name of a class implementing the ArtifactReferenceResolverStrategy interface
        • A Class object of a class implementing the ArtifactReferenceResolverStrategy interface

        The specified class must have a public no-argument constructor.

        Example usage (both examples have equivalent functionality):

         // Using a class name
         properties.put(ARTIFACT_RESOLVER_STRATEGY, "com.example.CustomArtifactReferenceResolverStrategy");
        
         // Using a Class object
         properties.put(ARTIFACT_RESOLVER_STRATEGY, CustomArtifactReferenceResolverStrategy.class);
         

        This property is used exclusively by SchemaResolver.resolveSchema(Record)

        See Also:
        ArtifactReferenceResolverStrategy, Constant Field Values
      • CACHE_TTL_MS

        public static final String CACHE_TTL_MS
        Specifies the time-to-live (TTL) for cached schema artifacts in milliseconds. This property determines how long a schema remains valid in the cache before it needs to be fetched again from the registry on the next relevant look up. Special value: 0: Disables caching. Schemas will be fetched from the registry on every request. The following types are supported for configuration:
        • Long or Number: millisecond value
          properties.put(CACHE_TTL_MS, 5000L);
        • String: Millisecond value as a String
          properties.put(CACHE_TTL_MS, "5000");
        • Duration: Java Duration object with any temporal unit
          properties.put(CACHE_TTL_MS, Duration.ofMillis(5000));
          properties.put(CACHE_TTL_MS, Duration.ofSeconds(5));
          properties.put(CACHE_TTL_MS, Duration.ofMinutes(1));
          Note: Duration values must be non-negative and must not exceed the maximum value that can be represented in milliseconds (Duration.ofMillis(Long.MAX_VALUE)). Exceeding these limits will result in an IllegalArgumentException during configuration.
        Any positive value sets the TTL in milliseconds. A longer TTL can improve performance by reducing registry calls, but may increase the risk of using outdated schemas. A shorter TTL ensures more up-to-date schemas but may increase load on the registry. Default value: 30000 (30 seconds)
        See Also:
        Constant Field Values
      • CACHE_LATEST

        public static final String CACHE_LATEST
        Controls the caching behavior of schema lookups that use 'latest' or no version. When enabled, these lookups will create an additional cache entry to allow subsequent latest/no-version lookups to use the cache. When disabled, only the resolved version is cached, requiring subsequent latest/no-version lookups to be fetched from the registry.

        Values:

        • true: Creates additional cache entry for latest/no-version lookups
        • false: Only caches the resolved version

        NOTE:

        • This property does not effect the schema lookup result when an explicit version is specified.
        • This property only affects caching behavior for serialization but does not apply to schema references. When using this property, schema references do not interact with the cache and are resolved by lookups to the registry.

        Default value: true

        See Also:
        Constant Field Values
      • USE_CACHED_ON_ERROR

        public static final String USE_CACHED_ON_ERROR
        Controls whether to use cached schemas when schema registry lookup errors occur. When enabled, schema resolution will use cached schemas instead of throwing exceptions after REQUEST_ATTEMPTS are exhausted. This is useful in environments where using a potentially stale schema is preferable to service interruptions.

        Values:

        • true: Uses cached schemas when schema registry lookup errors occur
        • false: Throws exception when schema registry lookup errors occur

        NOTE:

        • In normal conditions, the cache will still be used first.
        • This property only takes effect when an attempt to retrieve an expired schema from the registry causes an error.

        Default value: false

        See Also:
        REQUEST_ATTEMPTS, Constant Field Values
      • REQUEST_ATTEMPTS

        public static final String REQUEST_ATTEMPTS
        Specifies the number of attempts to make when communicating with the schema registry before giving up. Valid values are positive long values (1 - Long.MAX_VALUE). When used with USE_CACHED_ON_ERROR this property specifies the number of attempts before falling back to the last cached value.

        A value must be specified as a positive long value. Values less than or equal to 0 will result in an exception during configuration. Null values are also not allowed.

        Default value: 3

        See Also:
        USE_CACHED_ON_ERROR, Constant Field Values
      • REQUEST_ATTEMPT_BACKOFF_MS

        public static final String REQUEST_ATTEMPT_BACKOFF_MS
        Specifies the backoff time in milliseconds between retry attempts when communicating with the schema registry. Valid values are non-negative long values (0 - Max Long) or a Duration object.

        The following types are supported for configuration:

        • Long or Number: millisecond value
          properties.put(REQUEST_ATTEMPT_BACKOFF_MS, 500L);
        • String: Millisecond value as a String
          properties.put(REQUEST_ATTEMPT_BACKOFF_MS, "500");
        • Duration: Java Duration object with any temporal unit
          properties.put(REQUEST_ATTEMPT_BACKOFF_MS, Duration.ofMillis(500));
          properties.put(REQUEST_ATTEMPT_BACKOFF_MS, Duration.ofSeconds(0.5));
          Note: Duration values must be non-negative and must not exceed the maximum value that can be represented in milliseconds (Duration.ofMillis(Long.MAX_VALUE)). Exceeding these limits will result in an exception during configuration.

        Default value: 500 (milliseconds)

        See Also:
        Constant Field Values
      • AUTO_REGISTER_ARTIFACT

        public static final String AUTO_REGISTER_ARTIFACT
        Controls whether schemas should be automatically registered when they don't exist in the registry during serialization. When enabled, the serializer will attempt to register new schemas in the registry when they are not found. When disabled, serialization will fail with an exception if the schema is not found.

        Values:

        • true: Automatically register schemas when not found
        • false: Throw an exception when schemas are not found

        Default value: false

        See Also:
        Constant Field Values
      • SCHEMA_LOCATION

        public static final String SCHEMA_LOCATION
        Specifies the classpath resource path to the schema to be used for validation. This should be a path that can be resolved from the classpath using Thread.currentThread().getContextClassLoader().getResource(schemaLocation). For example: "com/example/schemas/myschema.json". The default is null.
        See Also:
        Constant Field Values
      • AUTO_REGISTER_ARTIFACT_IF_EXISTS

        public static final String AUTO_REGISTER_ARTIFACT_IF_EXISTS
        Controls the behavior when auto-registering an artifact that might already exist in the registry. This property determines how the system handles artifact registration when a similar artifact already exists in the registry.

        Possible values:

        • FAIL: Fails the registration if the artifact already exists
        • CREATE_VERSION: Creates a new version of the existing artifact
        • FIND_OR_CREATE_VERSION: Uses the existing artifact if it exists, otherwise creates a new version

        This property is used in conjunction with AUTO_REGISTER_ARTIFACT when automatically registering schemas to the registry during serialization.

        Default value: FIND_OR_CREATE_VERSION

        See Also:
        AUTO_REGISTER_ARTIFACT, Constant Field Values
    • Constructor Detail

      • SchemaResolverProperties

        public SchemaResolverProperties()
        Constructs a new SchemaResolverProperties instance with default properties.
      • SchemaResolverProperties

        public SchemaResolverProperties​(Map<String,​?> map)
        Constructs a new SchemaResolverProperties instance with default properties then applies properties from the passed in map.
        Parameters:
        map - A map that is applied after the default properties are applied.
    • Method Detail

      • getRegistryUrl

        public String getRegistryUrl()
        Retrieves the URL of the Solace Schema Registry.
        Returns:
        The Schema Registry URL as a String.
      • getAuthUsername

        public String getAuthUsername()
        Retrieves the username for authentication with the Auth Service.
        Returns:
        The Auth Service username as a String.
      • getAuthPassword

        public String getAuthPassword()
        Retrieves the password for authentication with the Auth Service.
        Returns:
        The Auth Service password as a String.
      • findLatestArtifact

        public boolean findLatestArtifact()
        Retrieves the FIND_LATEST_ARTIFACT boolean flag that determines whether serializer classes should attempt to locate the most recent artifact in the registry for the given groupId and artifactId combination.
        Returns:
        The boolean value of the FIND_LATEST_ARTIFACT boolean flag.
      • getExplicitArtifactVersion

        public String getExplicitArtifactVersion()
        Retrieves the EXPLICIT_ARTIFACT_VERSION which is used to explicitly set the version for querying an artifact in the registry.
        Returns:
        The explicitly set artifact version as a String, or null if not set.
      • getExplicitArtifactArtifactId

        public String getExplicitArtifactArtifactId()
        Retrieves the EXPLICIT_ARTIFACT_ARTIFACT_ID which is used to explicitly set the artifactId for querying an artifact in the registry.
        Returns:
        The explicitly set artifactId as a String, or null if not set.
      • getExplicitArtifactGroupId

        public String getExplicitArtifactGroupId()
        Retrieves the EXPLICIT_ARTIFACT_GROUP_ID which is used to explicitly set the groupId for querying an artifact in the registry.
        Returns:
        The explicitly set groupId as a String, or null if not set.
      • getTrustStorePath

        public String getTrustStorePath()
        Gets the path to the trust store file.

        This method retrieves the value associated with the TRUST_STORE_PATH key in the configuration.

        Returns:
        A String representing the path to the trust store file, or null if not set.
        Throws:
        IllegalStateException - if the value associated with TRUST_STORE_PATH is not a String.
      • getTrustStorePassword

        public String getTrustStorePassword()
        Gets the password for the trust store.

        This method retrieves the value associated with the TRUST_STORE_PASSWORD key in the configuration.

        Returns:
        A String representing the password for the trust store, or null if not set.
        Throws:
        IllegalStateException - if the value associated with TRUST_STORE_PASSWORD is not a String.
      • getValidateCertificate

        public boolean getValidateCertificate()
        Gets the certificate validation setting.

        This method retrieves the value associated with the VALIDATE_CERTIFICATE key in the configuration.

        Returns:
        A boolean indicating whether certificate validation is enabled. Returns true if validation is enabled, false otherwise.
        Throws:
        IllegalStateException - if the value associated with VALIDATE_CERTIFICATE is not a boolean or a String that can be parsed as a boolean.
      • getArtifactReferenceResolverStrategyClass

        public Class<?> getArtifactReferenceResolverStrategyClass()
        Retrieves an instance of an ArtifactReferenceResolverStrategy.

        The ARTIFACT_RESOLVER_STRATEGY key in the configuration can be:

        • A String representing the fully qualified class name of a class implementing the ArtifactReferenceResolverStrategy interface
        • A Class object of a class implementing the ArtifactReferenceResolverStrategy interface
        Returns:
        An ArtifactReferenceResolverStrategy instance.
        Throws:
        IllegalStateException - if:
        • No ArtifactReferenceResolverStrategy is found for the ARTIFACT_RESOLVER_STRATEGY key
        • The class specified by the ARTIFACT_RESOLVER_STRATEGY key is not found
        • The object specified by the ARTIFACT_RESOLVER_STRATEGY key is neither a String, nor Class
        See Also:
        ArtifactReferenceResolverStrategy
      • getCacheTTL

        public Duration getCacheTTL()
        Retrieves the cache time-to-live (TTL) duration specified by the CACHE_TTL_MS configuration in milliseconds.

        This method attempts to retrieve and convert the cache TTL value from the configuration that was set using the CACHE_TTL_MS key. The TTL duration determines how long a schema remains valid in the cache before it needs to be fetched again from the registry. A value of zero indicates that caching is disabled.

        Returns:
        A Duration representing the cache TTL in milliseconds.
        Throws:
        IllegalStateException - if the value associated with CACHE_TTL_MS is null, negative, or cannot be parsed as a valid duration (accepts Number, String, or Duration values).
      • getCacheLatest

        public boolean getCacheLatest()
        Retrieves the cache latest property specified by the CACHE_LATEST configuration.

        This method attempts to retrieve the cache latest property from the configuration that was set using the CACHE_LATEST key. The cache latest property controls the caching behavior of schema lookups that use 'latest' or no version.

        Returns:
        A boolean indicating whether the cache latest property is enabled. Returns true if enabled, false otherwise.
        Throws:
        IllegalStateException - if the value associated with CACHE_LATEST cannot be parsed as a valid boolean.
      • getUseCachedOnError

        public boolean getUseCachedOnError()
        Retrieves the use cached on error property specified by the USE_CACHED_ON_ERROR configuration.

        This method attempts to retrieve the use cached on error property from the configuration that was set using the USE_CACHED_ON_ERROR key. The use cached on error property controls whether to use cached schemas when registry connection errors occur.

        Returns:
        A boolean indicating whether the use cached on error property is enabled. Returns true if enabled, false otherwise.
        Throws:
        IllegalStateException - if the value associated with USE_CACHED_ON_ERROR cannot be parsed as a valid boolean.
      • getRequestAttempts

        public long getRequestAttempts()
        Retrieves the number of attempts to make when communicating with the schema registry before giving up.

        This method retrieves the value associated with the REQUEST_ATTEMPTS key in the configuration.

        Returns:
        A long value representing the number of attempts to make.
        Throws:
        IllegalStateException - if the value associated with REQUEST_ATTEMPTS is null, not positive, or cannot be parsed as a valid long.
      • getRequestAttemptBackoff

        public Duration getRequestAttemptBackoff()
        Retrieves the backoff time in milliseconds between retry attempts when communicating with the schema registry.

        This method attempts to retrieve and convert the backoff time value from the configuration that was set using the REQUEST_ATTEMPT_BACKOFF_MS key. The backoff time determines the wait time between retry attempts when communicating with the schema registry.

        Returns:
        A Duration representing the backoff time in milliseconds.
        Throws:
        IllegalStateException - if the value associated with REQUEST_ATTEMPT_BACKOFF_MS is null, negative, or cannot be parsed as a valid duration (accepts Number, String, or Duration values).
      • getAutoRegisterArtifact

        public boolean getAutoRegisterArtifact()
        Retrieves the auto-register artifact setting specified by the AUTO_REGISTER_ARTIFACT configuration.

        This method retrieves the value associated with the AUTO_REGISTER_ARTIFACT key in the configuration. This property controls whether schemas should be automatically registered when they don't exist in the registry during serialization.

        Returns:
        A boolean indicating whether automatic schema registration is enabled. Returns true if enabled, false otherwise.
        Throws:
        IllegalStateException - if the value associated with AUTO_REGISTER_ARTIFACT cannot be parsed as a valid boolean.
      • getSchemaLocation

        public String getSchemaLocation()
        Gets the configured classpath resource path to the schema. This path can be used to load the schema resource from the classpath.
        Returns:
        the classpath resource path to the schema, or null if not configured