11# Instructions for PubsubLiteIO usage.
22
3- NOTE: Drain is not currently supported on PubsubLiteIO. Once Beam 2.29.0 is released, this will be supported
4- only when --experiments=use_runner_v2 is enabled. Please contact dataflow customer support to request adding projects
5- into the allowlist and launch the pipeline with --experiments=use_runner_v2.
3+ NOTE: Drain is not currently supported on ` PubsubLiteIO ` . Once Beam 2.29.0 is released, this will be supported
4+ only when ` --experiments=use_runner_v2 ` is enabled. Please contact dataflow customer support to request adding projects
5+ into the allowlist and launch the pipeline with ` --experiments=use_runner_v2 ` .
66
7- 1 . Add the following to your POM file to download the Pub/Sub Lite I/O.
7+ 1 . Add the following to your ` pom.xml ` file to download the Pub/Sub Lite I/O.
88``` xml
99<dependency >
10- <groupId >com.google.cloud.pubsublite </groupId >
10+ <groupId >com.google.cloud</groupId >
1111 <artifactId >pubsublite-beam-io</artifactId >
12- <version >0.11.0 </version >
12+ <version >0.13.1 </version >
1313</dependency >
1414```
15- 1 . Create a topic using ` gcloud pubsub lite-topics create `
15+ 1 . Create a topic using [ ` gcloud pubsub lite-topics create ` ] ( https://cloud.google.com/sdk/gcloud/reference/pubsub/lite-topics/create )
16161 . Write some messages using:
1717
1818 ``` java
1919 import com.google.cloud.pubsublite.beam.PubsubLiteIO ;
2020 import com.google.cloud.pubsublite.beam.PublisherOptions ;
2121 import com.google.cloud.pubsublite.proto.PubSubMessage ;
22+ import com.google.cloud.pubsublite.CloudZone ;
23+ import com.google.cloud.pubsublite.ProjectIdOrNumber ;
24+ import com.google.cloud.pubsublite.TopicName ;
25+ import com.google.cloud.pubsublite.TopicPath ;
2226
2327 ...
2428
25- private final static String ZONE = " us-central1-b" ;
29+ private final static String LOCATION = " us-central1-b" ;
2630 private final static Long PROJECT_NUM = 123L ;
2731
2832 ...
@@ -32,23 +36,26 @@ into the allowlist and launch the pipeline with --experiments=use_runner_v2.
3236 PublisherOptions . newBuilder()
3337 .setTopicPath(TopicPath . newBuilder()
3438 .setLocation(CloudZone . parse(ZONE ))
35- .setProject(ProjectNumber . of(PROJECT_NUM ))
39+ .setProject(ProjectIdOrNumber . of(PROJECT_NUM ))
3640 .setName(TopicName . of(" my-topic" ))
3741 .build())
3842 .build()));
3943 ```
40- 1. Create a subscription using `gcloud pubsub lite- subscriptions create`
44+ 1. Create a subscription using [ `gcloud pubsub lite- subscriptions create`](https : // cloud.google.com/sdk/gcloud/reference/pubsub/subscriptions/create)
41451. Read some messages using:
4246
4347 ```java
4448 import com.google.cloud.pubsublite.beam. PubsubLiteIO ;
4549 import com.google.cloud.pubsublite.beam. SubscriberOptions ;
4650 import com.google.cloud.pubsublite.proto. SequencedMessage ;
47- import com.google.cloud.pubsublite.* ;
51+ import com.google.cloud.pubsublite. CloudZone ;
52+ import com.google.cloud.pubsublite. ProjectIdOrNumber ;
53+ import com.google.cloud.pubsublite. SubscriptionName ;
54+ import com.google.cloud.pubsublite. SubscriptionPath ;
4855
4956 ...
5057
51- private final static String ZONE = " us-central1-b" ;
58+ private final static String LOCATION = " us-central1-b" ;
5259 private final static Long PROJECT_NUM = 123L ;
5360
5461 ...
@@ -57,9 +64,24 @@ into the allowlist and launch the pipeline with --experiments=use_runner_v2.
5764 PCollection<SequencedMessage > messages = pipeline. apply(" Read messages" , PubsubLiteIO . read(
5865 SubscriberOptions . newBuilder()
5966 .setSubscriptionPath(SubscriptionPath . newBuilder()
60- .setLocation(CloudZone . parse(ZONE ))
61- .setProject(ProjectNumber . of(PROJECT_NUM ))
67+ .setLocation(CloudZone . parse(LOCATION ))
68+ .setProject(ProjectIdOrNumber . of(PROJECT_NUM ))
6269 .setName(SubscriptionName . of(" my-sub" ))
6370 .build())
6471 .build()));
6572 ```
73+
74+ ### Known issues and workarounds
75+ 1. If you encounter `IllegalAccessError ` as shown below, place the Pub / Sub Lite
76+ I / O connector as the first dependency before all other Beam dependencies in
77+ your `pom. xml`.
78+
79+ > `java.lang. IllegalAccessError : failed to access class com .google.cloud.
80+ pubsublite.internal.wire.RoutingMetadata from class com .google.cloud.
81+ pubsublite.beam.SubscriberOptions (com.google.cloud.pubsublite.internal.
82+ wire.RoutingMetadata and com.google.cloud.pubsublite.beam.SubscriberOptions
83+ are in unnamed module of loader java.net.URLClassLoader @ff2266c)`
84+
85+ 1. Aggregate transforms after fixed windowing will not emit elements in the
86+ DirectRunner for Pub/Sub Lite I/O unless you explicitly fire after watermark
87+ triggers, or use processing-time triggers instead.
0 commit comments