Search in sources :

Example 11 with TopicAdminClient

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]
}
Also used : TopicAdminClient(com.google.cloud.pubsub.spi.v1.TopicAdminClient) Topic(com.google.pubsub.v1.Topic) TopicName(com.google.pubsub.v1.TopicName)

Example 12 with TopicAdminClient

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);
    }
}
Also used : TopicAdminClient(com.google.cloud.pubsub.spi.v1.TopicAdminClient) SubscriptionAdminClient(com.google.cloud.pubsub.spi.v1.SubscriptionAdminClient) SubscriptionName(com.google.pubsub.v1.SubscriptionName) TopicName(com.google.pubsub.v1.TopicName) Test(org.junit.Test)

Aggregations

TopicAdminClient (com.google.cloud.pubsub.spi.v1.TopicAdminClient)12 TopicName (com.google.pubsub.v1.TopicName)7 Topic (com.google.pubsub.v1.Topic)4 Policy (com.google.iam.v1.Policy)2 TestIamPermissionsResponse (com.google.iam.v1.TestIamPermissionsResponse)2 SubscriptionName (com.google.pubsub.v1.SubscriptionName)2 LinkedList (java.util.LinkedList)2 ListTopicSubscriptionsPagedResponse (com.google.cloud.pubsub.spi.v1.PagedResponseWrappers.ListTopicSubscriptionsPagedResponse)1 ListTopicsPagedResponse (com.google.cloud.pubsub.spi.v1.PagedResponseWrappers.ListTopicsPagedResponse)1 SubscriptionAdminClient (com.google.cloud.pubsub.spi.v1.SubscriptionAdminClient)1 Binding (com.google.iam.v1.Binding)1 ListTopicSubscriptionsRequest (com.google.pubsub.v1.ListTopicSubscriptionsRequest)1 ListTopicsRequest (com.google.pubsub.v1.ListTopicsRequest)1 CallOptions (io.grpc.CallOptions)1 Channel (io.grpc.Channel)1 ClientInterceptor (io.grpc.ClientInterceptor)1 SimpleForwardingClientCall (io.grpc.ForwardingClientCall.SimpleForwardingClientCall)1 ManagedChannel (io.grpc.ManagedChannel)1 Metadata (io.grpc.Metadata)1 MethodDescriptor (io.grpc.MethodDescriptor)1