Search in sources :

Example 1 with UpdateSubscriptionRequest

use of com.google.pubsub.v1.UpdateSubscriptionRequest in project gapic-generator-java by googleapis.

the class SyncUpdateSubscription method syncUpdateSubscription.

public static void syncUpdateSubscription() throws Exception {
    // It may require modifications to work in your environment.
    try (SubscriptionAdminClient subscriptionAdminClient = SubscriptionAdminClient.create()) {
        UpdateSubscriptionRequest request = UpdateSubscriptionRequest.newBuilder().setSubscription(Subscription.newBuilder().build()).setUpdateMask(FieldMask.newBuilder().build()).build();
        Subscription response = subscriptionAdminClient.updateSubscription(request);
    }
}
Also used : UpdateSubscriptionRequest(com.google.pubsub.v1.UpdateSubscriptionRequest) SubscriptionAdminClient(com.google.cloud.pubsub.v1.SubscriptionAdminClient) Subscription(com.google.pubsub.v1.Subscription)

Example 2 with UpdateSubscriptionRequest

use of com.google.pubsub.v1.UpdateSubscriptionRequest in project native-image-support-java by GoogleCloudPlatform.

the class PubSubSampleApplication method updateSubscriptionDeadLetterTopic.

private static void updateSubscriptionDeadLetterTopic(String projectId, String subscriptionId, String topicId, String deadLetterTopicId) throws IOException {
    try (SubscriptionAdminClient subscriptionAdminClient = SubscriptionAdminClient.create()) {
        ProjectSubscriptionName subscriptionName = ProjectSubscriptionName.of(projectId, subscriptionId);
        TopicName topicName = TopicName.of(projectId, topicId);
        TopicName deadLetterTopicName = TopicName.of(projectId, deadLetterTopicId);
        DeadLetterPolicy deadLetterPolicy = DeadLetterPolicy.newBuilder().setDeadLetterTopic(deadLetterTopicName.toString()).setMaxDeliveryAttempts(20).build();
        Subscription subscription = Subscription.newBuilder().setName(subscriptionName.toString()).setTopic(topicName.toString()).setDeadLetterPolicy(deadLetterPolicy).build();
        FieldMask updateMask = FieldMask.newBuilder().addPaths("dead_letter_policy").build();
        UpdateSubscriptionRequest request = UpdateSubscriptionRequest.newBuilder().setSubscription(subscription).setUpdateMask(updateMask).build();
        Subscription response = subscriptionAdminClient.updateSubscription(request);
        System.out.println("Updated subscription " + response.getName());
    }
}
Also used : ProjectSubscriptionName(com.google.pubsub.v1.ProjectSubscriptionName) DeadLetterPolicy(com.google.pubsub.v1.DeadLetterPolicy) UpdateSubscriptionRequest(com.google.pubsub.v1.UpdateSubscriptionRequest) SubscriptionAdminClient(com.google.cloud.pubsub.v1.SubscriptionAdminClient) Subscription(com.google.pubsub.v1.Subscription) FieldMask(com.google.protobuf.FieldMask) TopicName(com.google.pubsub.v1.TopicName) ProjectTopicName(com.google.pubsub.v1.ProjectTopicName)

Example 3 with UpdateSubscriptionRequest

use of com.google.pubsub.v1.UpdateSubscriptionRequest in project java-pubsub by googleapis.

the class SubscriptionAdminClientTest method updateSubscriptionTest.

@Test
public void updateSubscriptionTest() throws Exception {
    Subscription expectedResponse = Subscription.newBuilder().setName(SubscriptionName.of("[PROJECT]", "[SUBSCRIPTION]").toString()).setTopic(TopicName.ofProjectTopicName("[PROJECT]", "[TOPIC]").toString()).setPushConfig(PushConfig.newBuilder().build()).setBigqueryConfig(BigQueryConfig.newBuilder().build()).setAckDeadlineSeconds(2135351438).setRetainAckedMessages(true).setMessageRetentionDuration(Duration.newBuilder().build()).putAllLabels(new HashMap<String, String>()).setEnableMessageOrdering(true).setExpirationPolicy(ExpirationPolicy.newBuilder().build()).setFilter("filter-1274492040").setDeadLetterPolicy(DeadLetterPolicy.newBuilder().build()).setRetryPolicy(RetryPolicy.newBuilder().build()).setDetached(true).setEnableExactlyOnceDelivery(true).setTopicMessageRetentionDuration(Duration.newBuilder().build()).build();
    mockSubscriber.addResponse(expectedResponse);
    UpdateSubscriptionRequest request = UpdateSubscriptionRequest.newBuilder().setSubscription(Subscription.newBuilder().build()).setUpdateMask(FieldMask.newBuilder().build()).build();
    Subscription actualResponse = client.updateSubscription(request);
    Assert.assertEquals(expectedResponse, actualResponse);
    List<AbstractMessage> actualRequests = mockSubscriber.getRequests();
    Assert.assertEquals(1, actualRequests.size());
    UpdateSubscriptionRequest actualRequest = ((UpdateSubscriptionRequest) actualRequests.get(0));
    Assert.assertEquals(request.getSubscription(), actualRequest.getSubscription());
    Assert.assertEquals(request.getUpdateMask(), actualRequest.getUpdateMask());
    Assert.assertTrue(channelProvider.isHeaderSent(ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), GaxGrpcProperties.getDefaultApiClientHeaderPattern()));
}
Also used : AbstractMessage(com.google.protobuf.AbstractMessage) UpdateSubscriptionRequest(com.google.pubsub.v1.UpdateSubscriptionRequest) HashMap(java.util.HashMap) Subscription(com.google.pubsub.v1.Subscription) Test(org.junit.Test)

Example 4 with UpdateSubscriptionRequest

use of com.google.pubsub.v1.UpdateSubscriptionRequest in project java-pubsub by googleapis.

the class SubscriptionAdminClientTest method updateSubscriptionExceptionTest.

@Test
public void updateSubscriptionExceptionTest() throws Exception {
    StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT);
    mockSubscriber.addException(exception);
    try {
        UpdateSubscriptionRequest request = UpdateSubscriptionRequest.newBuilder().setSubscription(Subscription.newBuilder().build()).setUpdateMask(FieldMask.newBuilder().build()).build();
        client.updateSubscription(request);
        Assert.fail("No exception raised");
    } catch (InvalidArgumentException e) {
    // Expected exception.
    }
}
Also used : InvalidArgumentException(com.google.api.gax.rpc.InvalidArgumentException) UpdateSubscriptionRequest(com.google.pubsub.v1.UpdateSubscriptionRequest) StatusRuntimeException(io.grpc.StatusRuntimeException) Test(org.junit.Test)

Example 5 with UpdateSubscriptionRequest

use of com.google.pubsub.v1.UpdateSubscriptionRequest in project java-pubsub by googleapis.

the class NativeImagePubSubSample method updateSubscriptionDeadLetterTopic.

static void updateSubscriptionDeadLetterTopic(String projectId, String subscriptionId, String topicId, String deadLetterTopicId) throws IOException {
    try (SubscriptionAdminClient subscriptionAdminClient = SubscriptionAdminClient.create()) {
        ProjectSubscriptionName subscriptionName = ProjectSubscriptionName.of(projectId, subscriptionId);
        TopicName topicName = TopicName.of(projectId, topicId);
        TopicName deadLetterTopicName = TopicName.of(projectId, deadLetterTopicId);
        DeadLetterPolicy deadLetterPolicy = DeadLetterPolicy.newBuilder().setDeadLetterTopic(deadLetterTopicName.toString()).setMaxDeliveryAttempts(20).build();
        Subscription subscription = Subscription.newBuilder().setName(subscriptionName.toString()).setTopic(topicName.toString()).setDeadLetterPolicy(deadLetterPolicy).build();
        FieldMask updateMask = FieldMask.newBuilder().addPaths("dead_letter_policy").build();
        UpdateSubscriptionRequest request = UpdateSubscriptionRequest.newBuilder().setSubscription(subscription).setUpdateMask(updateMask).build();
        Subscription response = subscriptionAdminClient.updateSubscription(request);
        System.out.println("Updated subscription " + response.getName());
    }
}
Also used : ProjectSubscriptionName(com.google.pubsub.v1.ProjectSubscriptionName) DeadLetterPolicy(com.google.pubsub.v1.DeadLetterPolicy) UpdateSubscriptionRequest(com.google.pubsub.v1.UpdateSubscriptionRequest) SubscriptionAdminClient(com.google.cloud.pubsub.v1.SubscriptionAdminClient) Subscription(com.google.pubsub.v1.Subscription) FieldMask(com.google.protobuf.FieldMask) TopicName(com.google.pubsub.v1.TopicName) ProjectTopicName(com.google.pubsub.v1.ProjectTopicName)

Aggregations

UpdateSubscriptionRequest (com.google.pubsub.v1.UpdateSubscriptionRequest)10 Subscription (com.google.pubsub.v1.Subscription)8 SubscriptionAdminClient (com.google.cloud.pubsub.v1.SubscriptionAdminClient)6 FieldMask (com.google.protobuf.FieldMask)4 TopicName (com.google.pubsub.v1.TopicName)4 Test (org.junit.Test)4 DeadLetterPolicy (com.google.pubsub.v1.DeadLetterPolicy)3 ProjectSubscriptionName (com.google.pubsub.v1.ProjectSubscriptionName)3 InvalidArgumentException (com.google.api.gax.rpc.InvalidArgumentException)2 AbstractMessage (com.google.protobuf.AbstractMessage)2 ProjectTopicName (com.google.pubsub.v1.ProjectTopicName)2 StatusRuntimeException (io.grpc.StatusRuntimeException)2 HashMap (java.util.HashMap)2 SubscriptionName (com.google.pubsub.v1.SubscriptionName)1