Search in sources :

Example 26 with Topic

use of com.google.pubsub.v1.Topic in project google-cloud-java by GoogleCloudPlatform.

the class TopicAdminClientTest method deleteTopicTest.

@Test
@SuppressWarnings("all")
public void deleteTopicTest() {
    Empty expectedResponse = Empty.newBuilder().build();
    mockPublisher.addResponse(expectedResponse);
    TopicName topic = TopicName.create("[PROJECT]", "[TOPIC]");
    client.deleteTopic(topic);
    List<GeneratedMessageV3> actualRequests = mockPublisher.getRequests();
    Assert.assertEquals(1, actualRequests.size());
    DeleteTopicRequest actualRequest = (DeleteTopicRequest) actualRequests.get(0);
    Assert.assertEquals(topic, actualRequest.getTopicAsTopicName());
}
Also used : Empty(com.google.protobuf.Empty) DeleteTopicRequest(com.google.pubsub.v1.DeleteTopicRequest) GeneratedMessageV3(com.google.protobuf.GeneratedMessageV3) TopicName(com.google.pubsub.v1.TopicName) Test(org.junit.Test)

Example 27 with Topic

use of com.google.pubsub.v1.Topic in project google-cloud-java by GoogleCloudPlatform.

the class SubscriptionAdminClientTest method getSubscriptionTest.

@Test
@SuppressWarnings("all")
public void getSubscriptionTest() {
    SubscriptionName name = SubscriptionName.create("[PROJECT]", "[SUBSCRIPTION]");
    TopicNameOneof topic = TopicNameOneof.from(TopicName.create("[PROJECT]", "[TOPIC]"));
    int ackDeadlineSeconds = 2135351438;
    boolean retainAckedMessages = false;
    Subscription expectedResponse = Subscription.newBuilder().setNameWithSubscriptionName(name).setTopicWithTopicNameOneof(topic).setAckDeadlineSeconds(ackDeadlineSeconds).setRetainAckedMessages(retainAckedMessages).build();
    mockSubscriber.addResponse(expectedResponse);
    SubscriptionName subscription = SubscriptionName.create("[PROJECT]", "[SUBSCRIPTION]");
    Subscription actualResponse = client.getSubscription(subscription);
    Assert.assertEquals(expectedResponse, actualResponse);
    List<GeneratedMessageV3> actualRequests = mockSubscriber.getRequests();
    Assert.assertEquals(1, actualRequests.size());
    GetSubscriptionRequest actualRequest = (GetSubscriptionRequest) actualRequests.get(0);
    Assert.assertEquals(subscription, actualRequest.getSubscriptionAsSubscriptionName());
}
Also used : TopicNameOneof(com.google.pubsub.v1.TopicNameOneof) GetSubscriptionRequest(com.google.pubsub.v1.GetSubscriptionRequest) SubscriptionName(com.google.pubsub.v1.SubscriptionName) Subscription(com.google.pubsub.v1.Subscription) GeneratedMessageV3(com.google.protobuf.GeneratedMessageV3) Test(org.junit.Test)

Example 28 with Topic

use of com.google.pubsub.v1.Topic in project google-cloud-java by GoogleCloudPlatform.

the class TopicAdminClientSnippets method getTopic.

/** Example of getting a topic. */
public Topic getTopic(String topicId) throws Exception {
    // [START pubsub_get_topic]
    try (TopicAdminClient topicAdminClient = TopicAdminClient.create()) {
        TopicName topicName = TopicName.create(projectId, topicId);
        Topic topic = topicAdminClient.getTopic(topicName);
        return topic;
    }
// [END pubsub_get_topic]
}
Also used : TopicAdminClient(com.google.cloud.pubsub.spi.v1.TopicAdminClient) Topic(com.google.pubsub.v1.Topic) TopicName(com.google.pubsub.v1.TopicName)

Example 29 with Topic

use of com.google.pubsub.v1.Topic in project google-cloud-java by GoogleCloudPlatform.

the class TopicAdminClientSnippets method listTopics.

/** Example of listing topics.  */
public ListTopicsPagedResponse listTopics() throws Exception {
    // [START pubsub_list_topics]
    try (TopicAdminClient topicAdminClient = TopicAdminClient.create()) {
        ListTopicsRequest listTopicsRequest = ListTopicsRequest.newBuilder().setProjectWithProjectName(ProjectName.create(projectId)).build();
        ListTopicsPagedResponse response = topicAdminClient.listTopics(listTopicsRequest);
        Iterable<Topic> topics = response.iterateAll();
        for (Topic topic : topics) {
        // do something with the topic
        }
        return response;
    }
// [END pubsub_list_topics]
}
Also used : ListTopicsPagedResponse(com.google.cloud.pubsub.spi.v1.PagedResponseWrappers.ListTopicsPagedResponse) TopicAdminClient(com.google.cloud.pubsub.spi.v1.TopicAdminClient) ListTopicsRequest(com.google.pubsub.v1.ListTopicsRequest) Topic(com.google.pubsub.v1.Topic)

Example 30 with Topic

use of com.google.pubsub.v1.Topic 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)

Aggregations

TopicName (com.google.pubsub.v1.TopicName)26 Test (org.junit.Test)22 Topic (com.google.pubsub.v1.Topic)11 GeneratedMessageV3 (com.google.protobuf.GeneratedMessageV3)9 SubscriptionName (com.google.pubsub.v1.SubscriptionName)9 TopicAdminClient (com.google.cloud.pubsub.spi.v1.TopicAdminClient)7 ByteString (com.google.protobuf.ByteString)7 PubsubMessage (com.google.pubsub.v1.PubsubMessage)7 ApiException (com.google.api.gax.grpc.ApiException)6 StatusRuntimeException (io.grpc.StatusRuntimeException)6 Subscription (com.google.pubsub.v1.Subscription)5 ArrayList (java.util.ArrayList)5 ListTopicsPagedResponse (com.google.cloud.pubsub.spi.v1.PagedResponseWrappers.ListTopicsPagedResponse)3 Publisher (com.google.cloud.pubsub.spi.v1.Publisher)3 SubscriptionAdminClient (com.google.cloud.pubsub.spi.v1.SubscriptionAdminClient)3 DeleteTopicRequest (com.google.pubsub.v1.DeleteTopicRequest)3 ListTopicsRequest (com.google.pubsub.v1.ListTopicsRequest)3 PublishRequest (com.google.pubsub.v1.PublishRequest)3 PublishResponse (com.google.pubsub.v1.PublishResponse)3 AckReplyConsumer (com.google.cloud.pubsub.spi.v1.AckReplyConsumer)2