-
Notifications
You must be signed in to change notification settings - Fork 95
/
Copy pathRemoveDeadLetterPolicyExample.java
74 lines (61 loc) · 2.93 KB
/
RemoveDeadLetterPolicyExample.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
/*
* Copyright 2020 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package pubsub;
// [START pubsub_dead_letter_remove]
import com.google.cloud.pubsub.v1.SubscriptionAdminClient;
import com.google.protobuf.FieldMask;
import com.google.pubsub.v1.ProjectSubscriptionName;
import com.google.pubsub.v1.Subscription;
import com.google.pubsub.v1.TopicName;
import com.google.pubsub.v1.UpdateSubscriptionRequest;
public class RemoveDeadLetterPolicyExample {
public static void main(String... args) throws Exception {
// TODO(developer): Replace these variables before running the sample.
String projectId = "your-project-id";
// This is an existing subscription with dead letter policy.
String subscriptionId = "your-subscription-id";
// This is an existing topic that the subscription with dead letter policy is attached to.
String topicId = "your-topic-id";
RemoveDeadLetterPolicyExample.removeDeadLetterPolicyExample(projectId, subscriptionId, topicId);
}
public static void removeDeadLetterPolicyExample(
String projectId, String subscriptionId, String topicId) throws Exception {
try (SubscriptionAdminClient subscriptionAdminClient = SubscriptionAdminClient.create()) {
ProjectSubscriptionName subscriptionName =
ProjectSubscriptionName.of(projectId, subscriptionId);
TopicName topicName = TopicName.of(projectId, topicId);
// Construct the subscription you expect to have after the request. Here,
// values in the required fields (name, topic) help identify the subscription.
// No dead letter policy is supplied.
Subscription expectedSubscription =
Subscription.newBuilder()
.setName(subscriptionName.toString())
.setTopic(topicName.toString())
.build();
// Construct a field mask to indicate which field to update in the subscription.
FieldMask updateMask = FieldMask.newBuilder().addPaths("dead_letter_policy").build();
UpdateSubscriptionRequest request =
UpdateSubscriptionRequest.newBuilder()
.setSubscription(expectedSubscription)
.setUpdateMask(updateMask)
.build();
Subscription response = subscriptionAdminClient.updateSubscription(request);
// You should see an empty dead letter topic field inside the dead letter policy.
System.out.println("After: " + response.getAllFields());
}
}
}
// [END pubsub_dead_letter_remove]