Skip to content

Latest commit

 

History

History
61 lines (50 loc) · 2 KB

README.md

File metadata and controls

61 lines (50 loc) · 2 KB

Instructions for PubsubLiteIO usage.

  1. Add the following to your POM file to download the Pub/Sub Lite I/O.
<dependency>
   <groupId>com.google.cloud.pubsublite</groupId>
   <artifactId>pubsublite-beam-io</artifactId>
   <version>0.11.0</version>
</dependency>
  1. Create a topic using gcloud pubsub lite-topics create

  2. Write some messages using:

    import com.google.cloud.pubsublite.beam.PubsubLiteIO;
    import com.google.cloud.pubsublite.beam.PublisherOptions;
    import com.google.cloud.pubsublite.proto.PubSubMessage;
    
    ...
    
    private final static String ZONE = "us-central1-b";
    private final static Long PROJECT_NUM = 123L;
    
    ...
    
    PCollection<PubSubMessage> messages = ...;
    messages.apply("Write messages", PubsubLiteIO.write(
        PublisherOptions.newBuilder()
            .setTopicPath(TopicPath.newBuilder()
                .setLocation(CloudZone.parse(ZONE))
                .setProject(ProjectNumber.of(PROJECT_NUM))
                .setName(TopicName.of("my-topic"))
                .build())
            .build()));
  3. Create a subscription using gcloud pubsub lite-subscriptions create

  4. Read some messages using:

    import com.google.cloud.pubsublite.beam.PubsubLiteIO;
    import com.google.cloud.pubsublite.beam.SubscriberOptions;
    import com.google.cloud.pubsublite.proto.SequencedMessage;
    import com.google.cloud.pubsublite.*;
    
    ...
    
    private final static String ZONE = "us-central1-b";
    private final static Long PROJECT_NUM = 123L;
    
    ...
    
    Pipeline pipeline = ...;
    PCollection<SequencedMessage> messages = pipeline.apply("Read messages", PubsubLiteIO.read(
        SubscriberOptions.newBuilder()
            .setSubscriptionPath(SubscriptionPath.newBuilder()
                .setLocation(CloudZone.parse(ZONE))
                .setProject(ProjectNumber.of(PROJECT_NUM))
                .setName(SubscriptionName.of("my-sub"))
                .build())
            .build()));