Search in sources :

Example 1 with NotFoundException

use of com.google.api.gax.rpc.NotFoundException in project flink by apache.

the class PubsubHelper method deleteTopic.

public void deleteTopic(TopicName topicName) throws IOException {
    TopicAdminClient adminClient = getTopicAdminClient();
    try {
        adminClient.getTopic(topicName);
    } catch (NotFoundException e) {
        // Doesn't exist. Good.
        return;
    }
    // If it exists we delete all subscriptions and the topic itself.
    LOG.info("DeleteTopic {} first delete old subscriptions.", topicName);
    adminClient.listTopicSubscriptions(topicName).iterateAllAsProjectSubscriptionName().forEach(subscriptionAdminClient::deleteSubscription);
    LOG.info("DeleteTopic {}", topicName);
    adminClient.deleteTopic(topicName);
}
Also used : TopicAdminClient(com.google.cloud.pubsub.v1.TopicAdminClient) NotFoundException(com.google.api.gax.rpc.NotFoundException)

Example 2 with NotFoundException

use of com.google.api.gax.rpc.NotFoundException in project flink by apache.

the class PubsubHelper method deleteSubscription.

public void deleteSubscription(ProjectSubscriptionName subscriptionName) throws IOException {
    SubscriptionAdminClient adminClient = getSubscriptionAdminClient();
    try {
        adminClient.getSubscription(subscriptionName);
        // If it already exists we must first delete it.
        LOG.info("DeleteSubscription {}", subscriptionName);
        adminClient.deleteSubscription(subscriptionName);
    } catch (NotFoundException e) {
    // Doesn't exist. Good.
    }
}
Also used : SubscriptionAdminClient(com.google.cloud.pubsub.v1.SubscriptionAdminClient) NotFoundException(com.google.api.gax.rpc.NotFoundException)

Aggregations

NotFoundException (com.google.api.gax.rpc.NotFoundException)2 SubscriptionAdminClient (com.google.cloud.pubsub.v1.SubscriptionAdminClient)1 TopicAdminClient (com.google.cloud.pubsub.v1.TopicAdminClient)1