Package com.google.cloud.spring.pubsub
Class PubSubAdmin
java.lang.Object
com.google.cloud.spring.pubsub.PubSubAdmin
- All Implemented Interfaces:
AutoCloseable
Pub/Sub admin utility that creates new topics and subscriptions on Google Cloud Pub/Sub.
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected static final intprotected static final int -
Constructor Summary
ConstructorsConstructorDescriptionPubSubAdmin(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 TypeMethodDescriptionvoidclose()com.google.pubsub.v1.SubscriptioncreateSubscription(com.google.pubsub.v1.Subscription.Builder builder) Create a new subscription on Google Cloud Pub/Sub.com.google.pubsub.v1.SubscriptioncreateSubscription(String subscriptionName, String topicName) Create a new subscription on Google Cloud Pub/Sub.com.google.pubsub.v1.SubscriptioncreateSubscription(String subscriptionName, String topicName, Integer ackDeadline) Create a new subscription on Google Cloud Pub/Sub.com.google.pubsub.v1.SubscriptioncreateSubscription(String subscriptionName, String topicName, Integer ackDeadline, String pushEndpoint) Create a new subscription on Google Cloud Pub/Sub.com.google.pubsub.v1.SubscriptioncreateSubscription(String subscriptionName, String topicName, String pushEndpoint) Create a new subscription on Google Cloud Pub/Sub.com.google.pubsub.v1.TopiccreateTopic(String topicName) Create a new topic on Google Cloud Pub/Sub.voiddeleteSubscription(String subscriptionName) Delete a subscription from Google Cloud Pub/Sub.voiddeleteTopic(String topicName) Delete a topic from Google Cloud Pub/Sub.intGet the default ack deadline.com.google.pubsub.v1.SubscriptiongetSubscription(String subscriptionName) Get the configuration of a Google Cloud Pub/Sub subscription.com.google.pubsub.v1.TopicGet 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.voidsetDefaultAckDeadline(int defaultAckDeadline) Set the default acknowledgement deadline value.
-
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 usecredentialsProvider- 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 usetopicAdminClient- theTopicAdminClientto usesubscriptionAdminClient- theSubscriptionAdminClientto use
-
-
Method Details
-
createTopic
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 theprojects/[project_name]/topics/[topic_name]format- Returns:
- the created topic
-
getTopic
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 theprojects/[project_name]/topics/[topic_name]format- Returns:
- topic configuration or
nullif topic doesn't exist
-
deleteTopic
Delete a topic from Google Cloud Pub/Sub.- Parameters:
topicName- short topic name, e.g., "topicName", or the fully-qualified topic name in theprojects/[project_name]/topics/[topic_name]format
-
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 theprojects/[project_name]/subscriptions/[subscription_name]formattopicName- short topic name, e.g., "topicName", or the fully-qualified topic name in theprojects/[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 theprojects/[project_name]/subscriptions/[subscription_name]formattopicName- short topic name, e.g., "topicName", or the fully-qualified topic name in theprojects/[project_name]/topics/[topic_name]formatackDeadline- 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 theprojects/[project_name]/subscriptions/[subscription_name]formattopicName- short topic name, e.g., "topicName", or the fully-qualified topic name in theprojects/[project_name]/topics/[topic_name]formatpushEndpoint- 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 theprojects/[project_name]/subscriptions/[subscription_name]formattopicName- short topic name, e.g., "topicName", or the fully-qualified topic name in theprojects/[project_name]/topics/[topic_name]formatackDeadline- deadline in seconds before a message is resent, must be between 10 and 600 seconds. If not provided, set to default of 10 secondspushEndpoint- 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
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 theprojects/[project_name]/subscriptions/[subscription_name]format- Returns:
- subscription configuration or
nullif subscription doesn't exist
-
deleteSubscription
Delete a subscription from Google Cloud Pub/Sub.- Parameters:
subscriptionName- short subscription name, e.g., "subscriptionName", or the fully-qualified subscription name in theprojects/[project_name]/subscriptions/[subscription_name]format
-
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:
closein interfaceAutoCloseable
-