This repository was archived by the owner on Aug 13, 2026. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 104
docs: Adding a GCS subscription example #1762
Merged
Merged
Changes from 3 commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
ed4e29a
docs: Adding a GCS subscription example
maitrimangal 4dbf9ce
removing the avro imoprt
maitrimangal 669718e
🦉 Updates from OwlBot post-processor
gcf-owl-bot[bot] 4a33f0c
adding optional GCS Configurations as well
maitrimangal 13b2326
Merge branch 'main' of https://github.com/googleapis/java-pubsub into…
maitrimangal f5bbd21
solving merge conflicts
maitrimangal 7809e1d
adding test case
maitrimangal f413be8
fixing lint
maitrimangal 166cb28
Merge branch 'main' of https://github.com/googleapis/java-pubsub into…
maitrimangal cfa80e0
Removing Testcase
maitrimangal c690f8a
Removing Testcase
maitrimangal 1408dc1
🦉 Updates from OwlBot post-processor
gcf-owl-bot[bot] 6ad1547
added max duration example
maitrimangal 90f8596
Merge branch 'main' of https://github.com/googleapis/java-pubsub into…
maitrimangal a2f3440
merge conflicts
maitrimangal fb7371b
merge conflicts
maitrimangal 89a03fb
🦉 Updates from OwlBot post-processor
gcf-owl-bot[bot] File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
61 changes: 61 additions & 0 deletions
61
samples/snippets/src/main/java/pubsub/CreateCloudStorageSubscriptionExample.java
This file contains hidden or 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,61 @@ | ||
| /* | ||
| * Copyright 2022 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_cloud_storage_subscription] | ||
| import com.google.cloud.pubsub.v1.SubscriptionAdminClient; | ||
| import com.google.pubsub.v1.CloudStorageConfig; | ||
| import com.google.pubsub.v1.ProjectSubscriptionName; | ||
| import com.google.pubsub.v1.ProjectTopicName; | ||
| import com.google.pubsub.v1.Subscription; | ||
| import java.io.IOException; | ||
|
|
||
| public class CreateCloudStorageSubscriptionExample { | ||
| public static void main(String... args) throws Exception { | ||
| // TODO(developer): Replace these variables before running the sample. | ||
| String projectId = "your-project-id"; | ||
| String topicId = "your-topic-id"; | ||
| String subscriptionId = "your-subscription-id"; | ||
| String bucket = "your-bucket"; | ||
|
|
||
| createCloudStorageSubscription(projectId, topicId, subscriptionId, bucket); | ||
| } | ||
|
|
||
| public static void createCloudStorageSubscription( | ||
| String projectId, String topicId, String subscriptionId, String bucket) throws IOException { | ||
| try (SubscriptionAdminClient subscriptionAdminClient = SubscriptionAdminClient.create()) { | ||
|
|
||
| ProjectTopicName topicName = ProjectTopicName.of(projectId, topicId); | ||
| ProjectSubscriptionName subscriptionName = | ||
| ProjectSubscriptionName.of(projectId, subscriptionId); | ||
|
|
||
| CloudStorageConfig cloudStorageConfig = | ||
| CloudStorageConfig.newBuilder().setBucket(bucket).build(); | ||
|
|
||
| Subscription subscription = | ||
| subscriptionAdminClient.createSubscription( | ||
| Subscription.newBuilder() | ||
| .setName(subscriptionName.toString()) | ||
| .setTopic(topicName.toString()) | ||
| .setCloudStorageConfig(cloudStorageConfig) | ||
| .build()); | ||
|
|
||
| System.out.println("Created a CloudStorage subscription: " + subscription.getAllFields()); | ||
| } | ||
| } | ||
| } | ||
| // [END pubsub_create_cloud_storage_subscription] | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.