From 294826879dce49e9c4ca5fea8608fadfb74c6f21 Mon Sep 17 00:00:00 2001 From: orabbit Date: Thu, 15 Jun 2023 15:58:48 -0400 Subject: [PATCH 1/4] samples: Payload Unwrapping --- ...reatePushNoWrapperSubscriptionExample.java | 61 +++++++++++++++++++ 1 file changed, 61 insertions(+) create mode 100644 samples/snippets/src/main/java/pubsub/CreatePushNoWrapperSubscriptionExample.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..422dba781 --- /dev/null +++ b/samples/snippets/src/main/java/pubsub/CreatePushNoWrapperSubscriptionExample.java @@ -0,0 +1,61 @@ +/* + * 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_unwrapped_push_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 CreatePushSubscriptionExample { + 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_unwrapped_push_subscription] From 4862935671423b757b7ec8b5d2bc9b3c83448faf Mon Sep 17 00:00:00 2001 From: orabbit Date: Thu, 15 Jun 2023 16:21:00 -0400 Subject: [PATCH 2/4] samples: Payload Unwrapping --- .../CreatePushNoWrapperSubscriptionExample.java | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/samples/snippets/src/main/java/pubsub/CreatePushNoWrapperSubscriptionExample.java b/samples/snippets/src/main/java/pubsub/CreatePushNoWrapperSubscriptionExample.java index 422dba781..b1a399095 100644 --- a/samples/snippets/src/main/java/pubsub/CreatePushNoWrapperSubscriptionExample.java +++ b/samples/snippets/src/main/java/pubsub/CreatePushNoWrapperSubscriptionExample.java @@ -16,7 +16,7 @@ package pubsub; -// [START pubsub_create_unwrapped_push_subscription] +// [START pubsub_create_push_no_wrapper_subscription] import com.google.cloud.pubsub.v1.SubscriptionAdminClient; import com.google.pubsub.v1.PushConfig; @@ -45,10 +45,15 @@ public static void createPushSubscriptionExample( SubscriptionName subscriptionName = SubscriptionName.of(projectId, subscriptionId); NoWrapper noWrapper = NoWrapper.newBuilder() - // Determines if message metadata is added to the HTTP headers of the delivered message. + // 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(); + 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. @@ -58,4 +63,4 @@ public static void createPushSubscriptionExample( } } } -// [END pubsub_create_unwrapped_push_subscription] +// [END pubsub_create_push_no_wrapper_subscription] From 5e005369559b0886abfe8f2d09a6e30a4952f610 Mon Sep 17 00:00:00 2001 From: orabbit Date: Thu, 15 Jun 2023 16:26:35 -0400 Subject: [PATCH 3/4] samples: Payload Unwrapping --- .../java/pubsub/CreatePushNoWrapperSubscriptionExample.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/samples/snippets/src/main/java/pubsub/CreatePushNoWrapperSubscriptionExample.java b/samples/snippets/src/main/java/pubsub/CreatePushNoWrapperSubscriptionExample.java index b1a399095..f72ca70a9 100644 --- a/samples/snippets/src/main/java/pubsub/CreatePushNoWrapperSubscriptionExample.java +++ b/samples/snippets/src/main/java/pubsub/CreatePushNoWrapperSubscriptionExample.java @@ -26,7 +26,7 @@ import com.google.pubsub.v1.TopicName; import java.io.IOException; -public class CreatePushSubscriptionExample { +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"; From c6bff1ebf99e3ef7b07cdacbd94ba92a76ce3f2e Mon Sep 17 00:00:00 2001 From: Owl Bot Date: Tue, 20 Jun 2023 17:48:28 +0000 Subject: [PATCH 4/4] =?UTF-8?q?=F0=9F=A6=89=20Updates=20from=20OwlBot=20po?= =?UTF-8?q?st-processor?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md --- README.md | 3 ++- .../CreatePushNoWrapperSubscriptionExample.java | 15 ++++++--------- 2 files changed, 8 insertions(+), 10 deletions(-) diff --git a/README.md b/README.md index 031914578..fd6b3a7c5 100644 --- a/README.md +++ b/README.md @@ -52,7 +52,7 @@ If you are using Maven without the BOM, add this to your dependencies: If you are using Gradle 5.x or later, add this to your dependencies: ```Groovy -implementation platform('com.google.cloud:libraries-bom:26.16.0') +implementation platform('com.google.cloud:libraries-bom:26.17.0') implementation 'com.google.cloud:google-cloud-pubsub' ``` @@ -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 index f72ca70a9..39e364ae6 100644 --- a/samples/snippets/src/main/java/pubsub/CreatePushNoWrapperSubscriptionExample.java +++ b/samples/snippets/src/main/java/pubsub/CreatePushNoWrapperSubscriptionExample.java @@ -44,16 +44,13 @@ public static void createPushSubscriptionExample( 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(); + 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(); + 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.