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

org.entur.pubsub.base.EnturGooglePubSubUtils Maven / Gradle / Ivy

Go to download

Base configuration for Google PubSub clients, to be used for non-Camel clients. Camel-based clients should use camel-entur-google-pubsub instead.

There is a newer version: 5.2
Show newest version
package org.entur.pubsub.base;

import com.google.cloud.pubsub.v1.Subscriber;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * Utility class for PubSub operations.
 */
public final class EnturGooglePubSubUtils {

  private static final Logger LOGGER = LoggerFactory.getLogger(
    EnturGooglePubSubUtils.class
  );

  private EnturGooglePubSubUtils() {}

  /**
   * Close a subscriber and release the associated resources.
   * Wait (10s max) for the subscriber to shut down before returning.
   *
   * @param subscriber the subscriber to close.
   */
  public static void closeSubscriber(Subscriber subscriber) {
    String destinationName = subscriber.getSubscriptionNameString();
    LOGGER.trace("Stopping subscriber for {}", destinationName);
    try {
      subscriber.stopAsync().awaitTerminated(10, TimeUnit.SECONDS);
      LOGGER.trace("Stopped subscriber for {}", destinationName);
    } catch (TimeoutException e) {
      LOGGER.warn(
        "Timeout while trying to stop subscriber for {}",
        destinationName,
        e
      );
    } catch (IllegalStateException e) {
      LOGGER.warn(
        "Failed to stop subscriber for {}",
        destinationName,
        subscriber.failureCause()
      );
    }
  }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy