Class PubSubAdmin

java.lang.Object
com.google.cloud.spring.pubsub.PubSubAdmin
All Implemented Interfaces:
AutoCloseable

public class PubSubAdmin extends Object implements AutoCloseable
Pub/Sub admin utility that creates new topics and subscriptions on Google Cloud Pub/Sub.
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    protected static final int
     
    protected static final int
     
  • Constructor Summary

    Constructors
    Constructor
    Description
    PubSubAdmin(GcpProjectIdProvider projectIdProvider, com.google.api.gax.core.CredentialsProvider credentialsProvider)
    This constructor instantiates TopicAdminClient and SubscriptionAdminClient with all their defaults and the provided credentials provider.
    PubSubAdmin(GcpProjectIdProvider projectIdProvider, com.google.cloud.pubsub.v1.TopicAdminClient topicAdminClient, com.google.cloud.pubsub.v1.SubscriptionAdminClient subscriptionAdminClient)
    Instantiates PubSubAdmin with provided topic/subscription client.
  • Method Summary

    Modifier and Type
    Method
    Description
    void
     
    com.google.pubsub.v1.Subscription
    createSubscription(com.google.pubsub.v1.Subscription.Builder builder)
    Create a new subscription on Google Cloud Pub/Sub.
    com.google.pubsub.v1.Subscription
    createSubscription(String subscriptionName, String topicName)
    Create a new subscription on Google Cloud Pub/Sub.
    com.google.pubsub.v1.Subscription
    createSubscription(String subscriptionName, String topicName, Integer ackDeadline)
    Create a new subscription on Google Cloud Pub/Sub.
    com.google.pubsub.v1.Subscription
    createSubscription(String subscriptionName, String topicName, Integer ackDeadline, String pushEndpoint)
    Create a new subscription on Google Cloud Pub/Sub.
    com.google.pubsub.v1.Subscription
    createSubscription(String subscriptionName, String topicName, String pushEndpoint)
    Create a new subscription on Google Cloud Pub/Sub.
    com.google.pubsub.v1.Topic
    createTopic(String topicName)
    Create a new topic on Google Cloud Pub/Sub.
    void
    deleteSubscription(String subscriptionName)
    Delete a subscription from Google Cloud Pub/Sub.
    void
    deleteTopic(String topicName)
    Delete a topic from Google Cloud Pub/Sub.
    int
    Get the default ack deadline.
    com.google.pubsub.v1.Subscription
    getSubscription(String subscriptionName)
    Get the configuration of a Google Cloud Pub/Sub subscription.
    com.google.pubsub.v1.Topic
    getTopic(String topicName)
    Get the configuration of a Google Cloud Pub/Sub topic.
    List<com.google.pubsub.v1.Subscription>
    Return every subscription in a project.
    List<com.google.pubsub.v1.Topic>
    Return every topic in a project.
    void
    setDefaultAckDeadline(int defaultAckDeadline)
    Set the default acknowledgement deadline value.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • MIN_ACK_DEADLINE_SECONDS

      protected static final int MIN_ACK_DEADLINE_SECONDS
      See Also:
    • MAX_ACK_DEADLINE_SECONDS

      protected static final int MAX_ACK_DEADLINE_SECONDS
      See Also:
  • Constructor Details

    • PubSubAdmin

      public PubSubAdmin(GcpProjectIdProvider projectIdProvider, com.google.api.gax.core.CredentialsProvider credentialsProvider)
      This constructor instantiates TopicAdminClient and SubscriptionAdminClient with all their defaults and the provided credentials provider.
      Parameters:
      projectIdProvider - the project id provider to use
      credentialsProvider - the credentials provider to use
      Throws:
      PubSubException - thrown when there are errors in contacting Google Cloud Pub/Sub
    • PubSubAdmin

      public PubSubAdmin(GcpProjectIdProvider projectIdProvider, com.google.cloud.pubsub.v1.TopicAdminClient topicAdminClient, com.google.cloud.pubsub.v1.SubscriptionAdminClient subscriptionAdminClient)
      Instantiates PubSubAdmin with provided topic/subscription client.
      Parameters:
      projectIdProvider - the project id provider to use
      topicAdminClient - the TopicAdminClient to use
      subscriptionAdminClient - the SubscriptionAdminClient to use
  • Method Details

    • createTopic

      public com.google.pubsub.v1.Topic createTopic(String topicName)
      Create a new topic on Google Cloud Pub/Sub.
      Parameters:
      topicName - the name for the new topic within the current project, or the fully-qualified topic name in the projects/[project_name]/topics/[topic_name] format
      Returns:
      the created topic
    • getTopic

      public com.google.pubsub.v1.Topic getTopic(String topicName)
      Get the configuration of a Google Cloud Pub/Sub topic.
      Parameters:
      topicName - short topic name, e.g., "topicName", or the fully-qualified topic name in the projects/[project_name]/topics/[topic_name] format
      Returns:
      topic configuration or null if topic doesn't exist
    • deleteTopic

      public void deleteTopic(String topicName)
      Delete a topic from Google Cloud Pub/Sub.
      Parameters:
      topicName - short topic name, e.g., "topicName", or the fully-qualified topic name in the projects/[project_name]/topics/[topic_name] format
    • listTopics

      public List<com.google.pubsub.v1.Topic> listTopics()
      Return every topic in a project.

      If there are multiple pages, they will all be merged into the same result.

      Returns:
      a list of topics
    • createSubscription

      public com.google.pubsub.v1.Subscription createSubscription(String subscriptionName, String topicName)
      Create a new subscription on Google Cloud Pub/Sub.
      Parameters:
      subscriptionName - short subscription name, e.g., "subscriptionName", or the fully-qualified subscription name in the projects/[project_name]/subscriptions/[subscription_name] format
      topicName - short topic name, e.g., "topicName", or the fully-qualified topic name in the projects/[project_name]/topics/[topic_name] format
      Returns:
      the created subscription
    • createSubscription

      public com.google.pubsub.v1.Subscription createSubscription(String subscriptionName, String topicName, Integer ackDeadline)
      Create a new subscription on Google Cloud Pub/Sub.
      Parameters:
      subscriptionName - short subscription name, e.g., "subscriptionName", or the fully-qualified subscription name in the projects/[project_name]/subscriptions/[subscription_name] format
      topicName - short topic name, e.g., "topicName", or the fully-qualified topic name in the projects/[project_name]/topics/[topic_name] format
      ackDeadline - deadline in seconds before a message is resent, must be between 10 and 600 seconds. If not provided, set to default of 10 seconds
      Returns:
      the created subscription
    • createSubscription

      public com.google.pubsub.v1.Subscription createSubscription(String subscriptionName, String topicName, String pushEndpoint)
      Create a new subscription on Google Cloud Pub/Sub.
      Parameters:
      subscriptionName - short subscription name, e.g., "subscriptionName", or the fully-qualified subscription name in the projects/[project_name]/subscriptions/[subscription_name] format
      topicName - short topic name, e.g., "topicName", or the fully-qualified topic name in the projects/[project_name]/topics/[topic_name] format
      pushEndpoint - the URL of the service receiving the push messages. If not provided, uses message pulling by default
      Returns:
      the created subscription
    • createSubscription

      public com.google.pubsub.v1.Subscription createSubscription(String subscriptionName, String topicName, Integer ackDeadline, String pushEndpoint)
      Create a new subscription on Google Cloud Pub/Sub.
      Parameters:
      subscriptionName - short subscription name, e.g., "subscriptionName", or the fully-qualified subscription name in the projects/[project_name]/subscriptions/[subscription_name] format
      topicName - short topic name, e.g., "topicName", or the fully-qualified topic name in the projects/[project_name]/topics/[topic_name] format
      ackDeadline - deadline in seconds before a message is resent, must be between 10 and 600 seconds. If not provided, set to default of 10 seconds
      pushEndpoint - the URL of the service receiving the push messages. If not provided, uses message pulling by default
      Returns:
      the created subscription
    • createSubscription

      public com.google.pubsub.v1.Subscription createSubscription(com.google.pubsub.v1.Subscription.Builder builder)
      Create a new subscription on Google Cloud Pub/Sub.
      Parameters:
      builder - a Subscription.Builder straight from the client API library that exposes all available knobs and levers. The name and topic fields will be expanded to fully qualified names (i.e. "projects/my-project/topic/my-topic") if they are not already.
      Returns:
      the created subscription
    • getSubscription

      public com.google.pubsub.v1.Subscription getSubscription(String subscriptionName)
      Get the configuration of a Google Cloud Pub/Sub subscription.
      Parameters:
      subscriptionName - short subscription name, e.g., "subscriptionName", or the fully-qualified subscription name in the projects/[project_name]/subscriptions/[subscription_name] format
      Returns:
      subscription configuration or null if subscription doesn't exist
    • deleteSubscription

      public void deleteSubscription(String subscriptionName)
      Delete a subscription from Google Cloud Pub/Sub.
      Parameters:
      subscriptionName - short subscription name, e.g., "subscriptionName", or the fully-qualified subscription name in the projects/[project_name]/subscriptions/[subscription_name] format
    • listSubscriptions

      public List<com.google.pubsub.v1.Subscription> listSubscriptions()
      Return every subscription in a project.

      If there are multiple pages, they will all be merged into the same result.

      Returns:
      a list of subscriptions
    • getDefaultAckDeadline

      public int getDefaultAckDeadline()
      Get the default ack deadline.
      Returns:
      the default acknowledgement deadline value in seconds
    • setDefaultAckDeadline

      public void setDefaultAckDeadline(int defaultAckDeadline)
      Set the default acknowledgement deadline value.
      Parameters:
      defaultAckDeadline - default acknowledgement deadline value in seconds, must be between 10 and 600 seconds.
    • close

      public void close()
      Specified by:
      close in interface AutoCloseable