Search in sources :

Example 1 with PubsubLiteSink

use of org.apache.beam.sdk.io.gcp.pubsublite.internal.PubsubLiteSink in project beam by apache.

the class PubsubLiteIO method write.

/**
 * Write messages to Pub/Sub Lite.
 *
 * <pre>{@code
 * TopicPath topicPath =
 *         TopicPath.newBuilder()
 *             .setProjectNumber(projectNum)
 *             .setLocation(zone)
 *             .setName(topicName)
 *             .build();
 *
 * PCollection<Message> messages = ...;
 * messages.apply(PubsubLiteIO.write(
 *     PublisherOptions.newBuilder().setTopicPath(topicPath).build());
 *
 * }</pre>
 */
public static PTransform<PCollection<PubSubMessage>, PDone> write(PublisherOptions options) {
    return new PTransform<PCollection<PubSubMessage>, PDone>() {

        @Override
        public PDone expand(PCollection<PubSubMessage> input) {
            PubsubLiteSink sink = new PubsubLiteSink(options);
            input.apply("Write", ParDo.of(sink));
            return PDone.in(input.getPipeline());
        }
    };
}
Also used : PCollection(org.apache.beam.sdk.values.PCollection) PubsubLiteSink(org.apache.beam.sdk.io.gcp.pubsublite.internal.PubsubLiteSink) PubSubMessage(com.google.cloud.pubsublite.proto.PubSubMessage) PTransform(org.apache.beam.sdk.transforms.PTransform)

Aggregations

PubSubMessage (com.google.cloud.pubsublite.proto.PubSubMessage)1 PubsubLiteSink (org.apache.beam.sdk.io.gcp.pubsublite.internal.PubsubLiteSink)1 PTransform (org.apache.beam.sdk.transforms.PTransform)1 PCollection (org.apache.beam.sdk.values.PCollection)1