-
Notifications
You must be signed in to change notification settings - Fork 95
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* samples: Payload Unwrapping * samples: Payload Unwrapping * samples: Payload Unwrapping * 🦉 Updates from OwlBot post-processor See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md --------- Co-authored-by: Owl Bot <gcf-owl-bot[bot]@users.noreply.github.com>
- Loading branch information
1 parent
09aff9c
commit 485970c
Showing
2 changed files
with
64 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
63 changes: 63 additions & 0 deletions
63
samples/snippets/src/main/java/pubsub/CreatePushNoWrapperSubscriptionExample.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
/* | ||
* Copyright 2016 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_create_push_no_wrapper_subscription] | ||
|
||
import com.google.cloud.pubsub.v1.SubscriptionAdminClient; | ||
import com.google.pubsub.v1.PushConfig; | ||
import com.google.pubsub.v1.PushConfig.NoWrapper; | ||
import com.google.pubsub.v1.Subscription; | ||
import com.google.pubsub.v1.SubscriptionName; | ||
import com.google.pubsub.v1.TopicName; | ||
import java.io.IOException; | ||
|
||
public class CreatePushNoWrapperSubscriptionExample { | ||
public static void main(String... args) throws Exception { | ||
// TODO(developer): Replace these variables before running the sample. | ||
String projectId = "your-project-id"; | ||
String subscriptionId = "your-subscription-id"; | ||
String topicId = "your-topic-id"; | ||
String pushEndpoint = "https://my-test-project.appspot.com/push"; | ||
|
||
createPushSubscriptionExample(projectId, subscriptionId, topicId, pushEndpoint); | ||
} | ||
|
||
public static void createPushSubscriptionExample( | ||
String projectId, String subscriptionId, String topicId, String pushEndpoint) | ||
throws IOException { | ||
try (SubscriptionAdminClient subscriptionAdminClient = SubscriptionAdminClient.create()) { | ||
TopicName topicName = TopicName.of(projectId, topicId); | ||
SubscriptionName subscriptionName = SubscriptionName.of(projectId, subscriptionId); | ||
NoWrapper noWrapper = | ||
NoWrapper.newBuilder() | ||
// Determines if message metadata is added to the HTTP headers of | ||
// the delivered message. | ||
.setWriteMetadata(true) | ||
.build(); | ||
PushConfig pushConfig = | ||
PushConfig.newBuilder().setPushEndpoint(pushEndpoint).setNoWrapper(noWrapper).build(); | ||
|
||
// Create a push subscription with default acknowledgement deadline of 10 seconds. | ||
// Messages not successfully acknowledged within 10 seconds will get resent by the server. | ||
Subscription subscription = | ||
subscriptionAdminClient.createSubscription(subscriptionName, topicName, pushConfig, 10); | ||
System.out.println("Created push subscription: " + subscription.getName()); | ||
} | ||
} | ||
} | ||
// [END pubsub_create_push_no_wrapper_subscription] |