diff --git a/README.md b/README.md index 265fd5c5a..fd6b3a7c5 100644 --- a/README.md +++ b/README.md @@ -250,6 +250,7 @@ Samples are in the [`samples/`](https://github.com/googleapis/java-pubsub/tree/m | Create Big Query Subscription Example | [source code](https://github.com/googleapis/java-pubsub/blob/main/samples/snippets/src/main/java/pubsub/CreateBigQuerySubscriptionExample.java) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/java-pubsub&page=editor&open_in_editor=samples/snippets/src/main/java/pubsub/CreateBigQuerySubscriptionExample.java) | | Create Proto Schema Example | [source code](https://github.com/googleapis/java-pubsub/blob/main/samples/snippets/src/main/java/pubsub/CreateProtoSchemaExample.java) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/java-pubsub&page=editor&open_in_editor=samples/snippets/src/main/java/pubsub/CreateProtoSchemaExample.java) | | Create Pull Subscription Example | [source code](https://github.com/googleapis/java-pubsub/blob/main/samples/snippets/src/main/java/pubsub/CreatePullSubscriptionExample.java) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/java-pubsub&page=editor&open_in_editor=samples/snippets/src/main/java/pubsub/CreatePullSubscriptionExample.java) | +| Create Push No Wrapper Subscription Example | [source code](https://github.com/googleapis/java-pubsub/blob/main/samples/snippets/src/main/java/pubsub/CreatePushNoWrapperSubscriptionExample.java) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/java-pubsub&page=editor&open_in_editor=samples/snippets/src/main/java/pubsub/CreatePushNoWrapperSubscriptionExample.java) | | Create Push Subscription Example | [source code](https://github.com/googleapis/java-pubsub/blob/main/samples/snippets/src/main/java/pubsub/CreatePushSubscriptionExample.java) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/java-pubsub&page=editor&open_in_editor=samples/snippets/src/main/java/pubsub/CreatePushSubscriptionExample.java) | | Create Subscription With Dead Letter Policy Example | [source code](https://github.com/googleapis/java-pubsub/blob/main/samples/snippets/src/main/java/pubsub/CreateSubscriptionWithDeadLetterPolicyExample.java) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/java-pubsub&page=editor&open_in_editor=samples/snippets/src/main/java/pubsub/CreateSubscriptionWithDeadLetterPolicyExample.java) | | Create Subscription With Exactly Once Delivery | [source code](https://github.com/googleapis/java-pubsub/blob/main/samples/snippets/src/main/java/pubsub/CreateSubscriptionWithExactlyOnceDelivery.java) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/java-pubsub&page=editor&open_in_editor=samples/snippets/src/main/java/pubsub/CreateSubscriptionWithExactlyOnceDelivery.java) | diff --git a/samples/snippets/src/main/java/pubsub/CreatePushNoWrapperSubscriptionExample.java b/samples/snippets/src/main/java/pubsub/CreatePushNoWrapperSubscriptionExample.java new file mode 100644 index 000000000..39e364ae6 --- /dev/null +++ b/samples/snippets/src/main/java/pubsub/CreatePushNoWrapperSubscriptionExample.java @@ -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]