use of com.google.cloud.pubsub.v1.SubscriptionAdminClient in project google-cloud-java by GoogleCloudPlatform.
the class UsePubSubEmulatorSnippet method main.
public static void main(String... args) throws IOException {
// [START pubsub_use_emulator]
String hostport = System.getenv("PUBSUB_EMULATOR_HOST");
ManagedChannel channel = ManagedChannelBuilder.forTarget(hostport).usePlaintext().build();
try {
TransportChannelProvider channelProvider = FixedTransportChannelProvider.create(GrpcTransportChannel.create(channel));
CredentialsProvider credentialsProvider = NoCredentialsProvider.create();
// Set the channel and credentials provider when creating a `TopicAdminClient`.
// Similarly for SubscriptionAdminClient
TopicAdminClient topicClient = TopicAdminClient.create(TopicAdminSettings.newBuilder().setTransportChannelProvider(channelProvider).setCredentialsProvider(credentialsProvider).build());
TopicName topicName = TopicName.of("my-project-id", "my-topic-id");
// Set the channel and credentials provider when creating a `Publisher`.
// Similarly for Subscriber
Publisher publisher = Publisher.newBuilder(topicName).setChannelProvider(channelProvider).setCredentialsProvider(credentialsProvider).build();
} finally {
channel.shutdown();
}
// [END pubsub_use_emulator]
}
use of com.google.cloud.pubsub.v1.SubscriptionAdminClient 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);
}
use of com.google.cloud.pubsub.v1.SubscriptionAdminClient 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.
}
}
Aggregations