All Downloads are FREE. Search and download functionalities are using the official Maven repository.

io.quarkiverse.reactive.messaging.nats.jetstream.JetStreamConnectorCommonConfiguration Maven / Gradle / Ivy

There is a newer version: 3.17.0
Show newest version
package io.quarkiverse.reactive.messaging.nats.jetstream;

import java.util.Optional;
import org.eclipse.microprofile.config.Config;
import org.eclipse.microprofile.config.ConfigProvider;
import org.eclipse.microprofile.reactive.messaging.spi.ConnectorFactory;

/**
 * Extracts the common configuration for the {@code quarkus-jetstream} connector.
*/
 public class JetStreamConnectorCommonConfiguration {
  protected final Config config;

  /**
   * Creates a new JetStreamConnectorCommonConfiguration.
   */
  public JetStreamConnectorCommonConfiguration(Config config) {
    this.config = config;
  }

  /**
   * @return the connector configuration
   */
  public Config config() {
    return this.config;
  }

  /**
   * Retrieves the value stored for the given alias.
   * @param alias the attribute alias, must not be {@code null} or blank
   * @param type the targeted type
   * @param  the targeted type
   * @return the configuration value for the given alias, empty if not set
   */
  protected  Optional getFromAlias(String alias, Class type) {
    return ConfigProvider.getConfig().getOptionalValue(alias, type);
  }

  /**
   * Retrieves the value stored for the given alias. Returns the default value if not present.
   * @param alias the attribute alias, must not be {@code null} or blank
   * @param type the targeted type
   * @param defaultValue the default value
   * @param  the targeted type
   * @return the configuration value for the given alias, empty if not set
   */
  protected  T getFromAliasWithDefaultValue(String alias, Class type, T defaultValue) {
    return getFromAlias(alias, type).orElse(defaultValue);
  }

  /**
   * @return the channel name
   */
  public String getChannel() {
    return config.getValue(ConnectorFactory.CHANNEL_NAME_ATTRIBUTE, String.class);
  }

  /**
  * Gets the stream value from the configuration.
  * Attribute Name: stream
  * Description: The stream to subscribe or publish messages to
  * @return the stream
  */
  public Optional getStream() {
    return config.getOptionalValue("stream", String.class);
  }

  /**
  * Gets the subject value from the configuration.
  * Attribute Name: subject
  * Description: The subject to subscribe or publish messages to
  * @return the subject
  */
  public Optional getSubject() {
    return config.getOptionalValue("subject", String.class);
  }

  /**
  * Gets the trace-enabled value from the configuration.
  * Attribute Name: trace-enabled
  * Description: Enable traces for publisher or subscriber
  * Default Value: true
  * @return the trace-enabled
  */
  public Boolean getTraceEnabled() {
    return config.getOptionalValue("trace-enabled", Boolean.class)
     .orElse(Boolean.valueOf("true"));
  }

  public void validate() {
  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy