Skip to content

Commit 3ce824c

Browse files
docs: Adding a GCS subscription example (googleapis#1762)
* docs: Adding a GCS subscription example * removing the avro imoprt * 🦉 Updates from OwlBot post-processor See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md * adding optional GCS Configurations as well * adding test case * fixing lint * Removing Testcase * Removing Testcase * 🦉 Updates from OwlBot post-processor See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md * added max duration example * merge conflicts * 🦉 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>
1 parent 4d1d37d commit 3ce824c

File tree

5 files changed

+93
-0
lines changed

5 files changed

+93
-0
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -248,6 +248,7 @@ Samples are in the [`samples/`](https://github.com/googleapis/java-pubsub/tree/m
248248
| Commit Proto Schema Example | [source code](https://github.com/googleapis/java-pubsub/blob/main/samples/snippets/src/main/java/pubsub/CommitProtoSchemaExample.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/CommitProtoSchemaExample.java) |
249249
| Create Avro Schema Example | [source code](https://github.com/googleapis/java-pubsub/blob/main/samples/snippets/src/main/java/pubsub/CreateAvroSchemaExample.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/CreateAvroSchemaExample.java) |
250250
| 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) |
251+
| Create Cloud Storage Subscription Example | [source code](https://github.com/googleapis/java-pubsub/blob/main/samples/snippets/src/main/java/pubsub/CreateCloudStorageSubscriptionExample.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/CreateCloudStorageSubscriptionExample.java) |
251252
| 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) |
252253
| 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) |
253254
| 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) |

samples/install-without-bom/pom.xml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,11 @@
8888
<artifactId>google-cloud-bigquery</artifactId>
8989
<version>2.34.0</version>
9090
</dependency>
91+
<dependency>
92+
<groupId>com.google.cloud</groupId>
93+
<artifactId>google-cloud-storage</artifactId>
94+
<version>2.28.0</version>
95+
</dependency>
9196
</dependencies>
9297

9398
<!-- compile and run all snippet tests -->

samples/snapshot/pom.xml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,11 @@
8787
<artifactId>google-cloud-bigquery</artifactId>
8888
<version>2.34.0</version>
8989
</dependency>
90+
<dependency>
91+
<groupId>com.google.cloud</groupId>
92+
<artifactId>google-cloud-storage</artifactId>
93+
<version>2.28.0</version>
94+
</dependency>
9095
</dependencies>
9196

9297
<!-- compile and run all snippet tests -->

samples/snippets/pom.xml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,10 @@
6363
<groupId>com.google.cloud</groupId>
6464
<artifactId>google-cloud-bigquery</artifactId>
6565
</dependency>
66+
<dependency>
67+
<groupId>com.google.cloud</groupId>
68+
<artifactId>google-cloud-storage</artifactId>
69+
</dependency>
6670
<dependency>
6771
<groupId>org.apache.avro</groupId>
6872
<artifactId>avro</artifactId>
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
/*
2+
* Copyright 2022 Google LLC
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package pubsub;
18+
19+
// [START pubsub_create_cloud_storage_subscription]
20+
import com.google.cloud.pubsub.v1.SubscriptionAdminClient;
21+
import com.google.protobuf.Duration;
22+
import com.google.pubsub.v1.CloudStorageConfig;
23+
import com.google.pubsub.v1.ProjectSubscriptionName;
24+
import com.google.pubsub.v1.ProjectTopicName;
25+
import com.google.pubsub.v1.Subscription;
26+
import java.io.IOException;
27+
28+
public class CreateCloudStorageSubscriptionExample {
29+
public static void main(String... args) throws Exception {
30+
// TODO(developer): Replace these variables before running the sample.
31+
String projectId = "your-project-id";
32+
String topicId = "your-topic-id";
33+
String subscriptionId = "your-subscription-id";
34+
String bucket = "your-bucket";
35+
String filenamePrefix = "log_events_";
36+
String filenameSuffix = ".text";
37+
Duration maxDuration = Duration.newBuilder().setSeconds(300).build();
38+
39+
createCloudStorageSubscription(
40+
projectId, topicId, subscriptionId, bucket, filenamePrefix, filenameSuffix, maxDuration);
41+
}
42+
43+
public static void createCloudStorageSubscription(
44+
String projectId,
45+
String topicId,
46+
String subscriptionId,
47+
String bucket,
48+
String filenamePrefix,
49+
String filenameSuffix,
50+
Duration maxDuration)
51+
throws IOException {
52+
try (SubscriptionAdminClient subscriptionAdminClient = SubscriptionAdminClient.create()) {
53+
54+
ProjectTopicName topicName = ProjectTopicName.of(projectId, topicId);
55+
ProjectSubscriptionName subscriptionName =
56+
ProjectSubscriptionName.of(projectId, subscriptionId);
57+
58+
CloudStorageConfig cloudStorageConfig =
59+
CloudStorageConfig.newBuilder()
60+
.setBucket(bucket)
61+
.setFilenamePrefix(filenamePrefix)
62+
.setFilenameSuffix(filenameSuffix)
63+
.setMaxDuration(maxDuration)
64+
.build();
65+
66+
Subscription subscription =
67+
subscriptionAdminClient.createSubscription(
68+
Subscription.newBuilder()
69+
.setName(subscriptionName.toString())
70+
.setTopic(topicName.toString())
71+
.setCloudStorageConfig(cloudStorageConfig)
72+
.build());
73+
74+
System.out.println("Created a CloudStorage subscription: " + subscription.getAllFields());
75+
}
76+
}
77+
}
78+
// [END pubsub_create_cloud_storage_subscription]

0 commit comments

Comments
 (0)