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);
}
}
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());
}
}
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()));
}
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.
}
}
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());
}
}
Aggregations