Search in sources :

Example 1 with Topic

use of com.google.pubsub.v1.Topic in project beam by apache.

the class PubsubGrpcClient method createSubscription.

@Override
public void createSubscription(TopicPath topic, SubscriptionPath subscription, int ackDeadlineSeconds) throws IOException {
    Subscription request = Subscription.newBuilder().setTopic(topic.getPath()).setName(subscription.getPath()).setAckDeadlineSeconds(ackDeadlineSeconds).build();
    // ignore Subscription result.
    subscriberStub().createSubscription(request);
}
Also used : Subscription(com.google.pubsub.v1.Subscription)

Example 2 with Topic

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

the class TopicAdminClientSnippets method getTopicPolicy.

/** Example of getting a topic policy. */
public Policy getTopicPolicy(String topicId) throws Exception {
    // [START pubsub_get_topic_policy]
    try (TopicAdminClient topicAdminClient = TopicAdminClient.create()) {
        TopicName topicName = TopicName.create(projectId, topicId);
        Policy policy = topicAdminClient.getIamPolicy(topicName.toString());
        if (policy == null) {
        // topic iam policy was not found
        }
        return policy;
    }
// [END pubsub_get_topic_policy]
}
Also used : Policy(com.google.iam.v1.Policy) TopicAdminClient(com.google.cloud.pubsub.spi.v1.TopicAdminClient) TopicName(com.google.pubsub.v1.TopicName)

Example 3 with Topic

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

the class TopicAdminClientSnippets method deleteTopic.

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

Example 4 with Topic

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

the class TopicAdminClientSnippets method testTopicPermissions.

/** Example of testing whether the caller has the provided permissions on a topic.
   * Only viewer, editor or admin/owner can view results of pubsub.topics.get  */
public TestIamPermissionsResponse testTopicPermissions(String topicId) throws Exception {
    // [START pubsub_test_topic_permissions]
    try (TopicAdminClient topicAdminClient = TopicAdminClient.create()) {
        List<String> permissions = new LinkedList<>();
        permissions.add("pubsub.topics.get");
        TopicName topicName = TopicName.create(projectId, topicId);
        TestIamPermissionsResponse testedPermissions = topicAdminClient.testIamPermissions(topicName.toString(), permissions);
        return testedPermissions;
    }
// [END pubsub_test_topic_permissions]
}
Also used : TopicAdminClient(com.google.cloud.pubsub.spi.v1.TopicAdminClient) TestIamPermissionsResponse(com.google.iam.v1.TestIamPermissionsResponse) LinkedList(java.util.LinkedList) TopicName(com.google.pubsub.v1.TopicName)

Example 5 with Topic

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

the class SubscriptionAdminClient method deleteSubscription.

// AUTO-GENERATED DOCUMENTATION AND METHOD
/**
   * Deletes an existing subscription. All messages retained in the subscription are immediately
   * dropped. Calls to `Pull` after deletion will return `NOT_FOUND`. After a subscription is
   * deleted, a new one may be created with the same name, but the new one has no association with
   * the old subscription or its topic unless the same topic is specified.
   *
   * <p>Sample code:
   *
   * <pre><code>
   * try (SubscriptionAdminClient subscriptionAdminClient = SubscriptionAdminClient.create()) {
   *   SubscriptionName subscription = SubscriptionName.create("[PROJECT]", "[SUBSCRIPTION]");
   *   subscriptionAdminClient.deleteSubscription(subscription);
   * }
   * </code></pre>
   *
   * @param subscription The subscription to delete. Format is
   *     `projects/{project}/subscriptions/{sub}`.
   * @throws com.google.api.gax.grpc.ApiException if the remote call fails
   */
public final void deleteSubscription(SubscriptionName subscription) {
    DeleteSubscriptionRequest request = DeleteSubscriptionRequest.newBuilder().setSubscriptionWithSubscriptionName(subscription).build();
    deleteSubscription(request);
}
Also used : DeleteSubscriptionRequest(com.google.pubsub.v1.DeleteSubscriptionRequest)

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