use of com.google.cloud.pubsub.spi.v1.TopicAdminClient in project google-cloud-java by GoogleCloudPlatform.
the class TopicAdminClientSnippets method createTopic.
/** Example of creating a topic. */
public Topic createTopic(String topicId) throws Exception {
// [START pubsub_create_topic]
try (TopicAdminClient topicAdminClient = TopicAdminClient.create()) {
// projectId <= unique project identifier, eg. "my-project-id"
// topicId <= "my-topic-id"
TopicName topicName = TopicName.create(projectId, topicId);
Topic topic = topicAdminClient.createTopic(topicName);
return topic;
}
// [END pubsub_create_topic]
}
use of com.google.cloud.pubsub.spi.v1.TopicAdminClient in project google-cloud-java by GoogleCloudPlatform.
the class ITPubSubSnippets method testPublisherSubscriber.
@Test
public void testPublisherSubscriber() throws Exception {
TopicName topicName = TopicName.create(ServiceOptions.getDefaultProjectId(), formatForTest("test-topic"));
SubscriptionName subscriptionName = SubscriptionName.create(ServiceOptions.getDefaultProjectId(), formatForTest("test-subscription"));
try (TopicAdminClient publisherClient = TopicAdminClient.create();
SubscriptionAdminClient subscriberClient = SubscriptionAdminClient.create()) {
publisherClient.createTopic(topicName);
subscriberClient.createSubscription(subscriptionName, topicName, PushConfig.getDefaultInstance(), 0);
testPublisherSubscriberHelper(topicName, subscriptionName);
subscriberClient.deleteSubscription(subscriptionName);
publisherClient.deleteTopic(topicName);
}
}
Aggregations