Class PubsubIO
- java.lang.Object
-
- org.apache.beam.sdk.io.gcp.pubsub.PubsubIO
-
public class PubsubIO extends java.lang.ObjectRead and WritePTransforms for Cloud Pub/Sub streams. These transforms create and consume unboundedPCollections.Using local emulator
In order to use local emulator for Pubsub you should use
PubsubOptions#setPubsubRootUrl(String)method to set host and port of your local emulator.Permissions
Permission requirements depend on the
PipelineRunnerthat is used to execute the Beam pipeline. Please refer to the documentation of correspondingPipelineRunnersfor more details.Updates to the I/O connector code
For any significant updates to this I/O connector, please consider involving corresponding code reviewers mentioned here.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classPubsubIO.PubsubSubscriptionClass representing a Cloud Pub/Sub Subscription.static classPubsubIO.PubsubTopicClass representing a Cloud Pub/Sub Topic.static classPubsubIO.Read<T>Implementation of read methods.static classPubsubIO.Write<T>Implementation of write methods.
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static PubsubIO.Read<org.apache.avro.generic.GenericRecord>readAvroGenericRecords(org.apache.avro.Schema avroSchema)Returns aPTransformthat continuously reads binary encoded Avro messages into the AvroGenericRecordtype.static <T> PubsubIO.Read<T>readAvros(java.lang.Class<T> clazz)Returns APTransformthat continuously reads binary encoded Avro messages of the given type from a Google Cloud Pub/Sub stream.static <T> PubsubIO.Read<T>readAvrosWithBeamSchema(java.lang.Class<T> clazz)Returns aPTransformthat continuously reads binary encoded Avro messages of the specific type.static PubsubIO.Read<PubsubMessage>readMessages()Returns APTransformthat continuously reads from a Google Cloud Pub/Sub stream.static PubsubIO.Read<PubsubMessage>readMessagesWithAttributes()Returns APTransformthat continuously reads from a Google Cloud Pub/Sub stream.static PubsubIO.Read<PubsubMessage>readMessagesWithAttributesAndMessageId()Returns APTransformthat continuously reads from a Google Cloud Pub/Sub stream.static PubsubIO.Read<PubsubMessage>readMessagesWithAttributesAndMessageIdAndOrderingKey()Returns APTransformthat continuously reads from a Google Cloud Pub/Sub stream.static <T> PubsubIO.Read<T>readMessagesWithCoderAndParseFn(org.apache.beam.sdk.coders.Coder<T> coder, org.apache.beam.sdk.transforms.SimpleFunction<PubsubMessage,T> parseFn)Returns APTransformthat continuously reads from a Google Cloud Pub/Sub stream, mapping eachPubsubMessageinto type T using the supplied parse function and coder.static PubsubIO.Read<PubsubMessage>readMessagesWithMessageId()Returns APTransformthat continuously reads from a Google Cloud Pub/Sub stream.static PubsubIO.Read<com.google.protobuf.DynamicMessage>readProtoDynamicMessages(com.google.protobuf.Descriptors.Descriptor descriptor)Similar toreadProtoDynamicMessages(ProtoDomain, String)but for when theDescriptors.Descriptoris already known.static PubsubIO.Read<com.google.protobuf.DynamicMessage>readProtoDynamicMessages(org.apache.beam.sdk.extensions.protobuf.ProtoDomain domain, java.lang.String fullMessageName)Returns aPTransformthat continuously reads binary encoded protobuf messages for the type specified byfullMessageName.static <T extends com.google.protobuf.Message>
PubsubIO.Read<T>readProtos(java.lang.Class<T> messageClass)Returns APTransformthat continuously reads binary encoded protobuf messages of the given type from a Google Cloud Pub/Sub stream.static PubsubIO.Read<java.lang.String>readStrings()Returns APTransformthat continuously reads UTF-8 encoded strings from a Google Cloud Pub/Sub stream.static <T> PubsubIO.Write<T>writeAvros(java.lang.Class<T> clazz)Returns APTransformthat writes binary encoded Avro messages of a given type to a Google Cloud Pub/Sub stream.static PubsubIO.Write<PubsubMessage>writeMessages()Returns APTransformthat writes to a Google Cloud Pub/Sub stream.static <T extends com.google.protobuf.Message>
PubsubIO.Write<T>writeProtos(java.lang.Class<T> messageClass)Returns APTransformthat writes binary encoded protobuf messages of a given type to a Google Cloud Pub/Sub stream.static PubsubIO.Write<java.lang.String>writeStrings()Returns APTransformthat writes UTF-8 encoded strings to a Google Cloud Pub/Sub stream.
-
-
-
Method Detail
-
readMessages
public static PubsubIO.Read<PubsubMessage> readMessages()
Returns APTransformthat continuously reads from a Google Cloud Pub/Sub stream. The messages will only contain apayload, but noattributes.
-
readMessagesWithMessageId
public static PubsubIO.Read<PubsubMessage> readMessagesWithMessageId()
Returns APTransformthat continuously reads from a Google Cloud Pub/Sub stream. The messages will only contain apayloadwith themessageIdfrom PubSub, but noattributes.
-
readMessagesWithAttributes
public static PubsubIO.Read<PubsubMessage> readMessagesWithAttributes()
Returns APTransformthat continuously reads from a Google Cloud Pub/Sub stream. The messages will contain both apayloadandattributes.
-
readMessagesWithAttributesAndMessageId
public static PubsubIO.Read<PubsubMessage> readMessagesWithAttributesAndMessageId()
Returns APTransformthat continuously reads from a Google Cloud Pub/Sub stream. The messages will contain both apayloadandattributes, along with themessageIdfrom PubSub.
-
readMessagesWithAttributesAndMessageIdAndOrderingKey
public static PubsubIO.Read<PubsubMessage> readMessagesWithAttributesAndMessageIdAndOrderingKey()
Returns APTransformthat continuously reads from a Google Cloud Pub/Sub stream. The messages will contain apayload,attributes, along with themessageIdand {PubsubMessage#getOrderingKey() orderingKey} from PubSub.
-
readStrings
public static PubsubIO.Read<java.lang.String> readStrings()
Returns APTransformthat continuously reads UTF-8 encoded strings from a Google Cloud Pub/Sub stream.
-
readProtos
public static <T extends com.google.protobuf.Message> PubsubIO.Read<T> readProtos(java.lang.Class<T> messageClass)
Returns APTransformthat continuously reads binary encoded protobuf messages of the given type from a Google Cloud Pub/Sub stream.
-
readProtoDynamicMessages
@Experimental(SCHEMAS) public static PubsubIO.Read<com.google.protobuf.DynamicMessage> readProtoDynamicMessages(org.apache.beam.sdk.extensions.protobuf.ProtoDomain domain, java.lang.String fullMessageName)
Returns aPTransformthat continuously reads binary encoded protobuf messages for the type specified byfullMessageName.This is primarily here for cases where the message type cannot be known at compile time. If it can be known, prefer
readProtos(Class), asDynamicMessagetends to perform worse than concrete types.Beam will infer a schema for the
DynamicMessageschema. Note that some proto schema features are not supported by all sinks.- Parameters:
domain- TheProtoDomainthat contains the target message and its dependencies.fullMessageName- The full name of the message for lookup indomain.
-
readProtoDynamicMessages
@Experimental(SCHEMAS) public static PubsubIO.Read<com.google.protobuf.DynamicMessage> readProtoDynamicMessages(com.google.protobuf.Descriptors.Descriptor descriptor)
Similar toreadProtoDynamicMessages(ProtoDomain, String)but for when theDescriptors.Descriptoris already known.
-
readAvros
public static <T> PubsubIO.Read<T> readAvros(java.lang.Class<T> clazz)
Returns APTransformthat continuously reads binary encoded Avro messages of the given type from a Google Cloud Pub/Sub stream.
-
readMessagesWithCoderAndParseFn
public static <T> PubsubIO.Read<T> readMessagesWithCoderAndParseFn(org.apache.beam.sdk.coders.Coder<T> coder, org.apache.beam.sdk.transforms.SimpleFunction<PubsubMessage,T> parseFn)
Returns APTransformthat continuously reads from a Google Cloud Pub/Sub stream, mapping eachPubsubMessageinto type T using the supplied parse function and coder.
-
readAvroGenericRecords
@Experimental(SCHEMAS) public static PubsubIO.Read<org.apache.avro.generic.GenericRecord> readAvroGenericRecords(org.apache.avro.Schema avroSchema)
Returns aPTransformthat continuously reads binary encoded Avro messages into the AvroGenericRecordtype.Beam will infer a schema for the Avro schema. This allows the output to be used by SQL and by the schema-transform library.
-
readAvrosWithBeamSchema
@Experimental(SCHEMAS) public static <T> PubsubIO.Read<T> readAvrosWithBeamSchema(java.lang.Class<T> clazz)
Returns aPTransformthat continuously reads binary encoded Avro messages of the specific type.Beam will infer a schema for the Avro schema. This allows the output to be used by SQL and by the schema-transform library.
-
writeMessages
public static PubsubIO.Write<PubsubMessage> writeMessages()
Returns APTransformthat writes to a Google Cloud Pub/Sub stream.
-
writeStrings
public static PubsubIO.Write<java.lang.String> writeStrings()
Returns APTransformthat writes UTF-8 encoded strings to a Google Cloud Pub/Sub stream.
-
writeProtos
public static <T extends com.google.protobuf.Message> PubsubIO.Write<T> writeProtos(java.lang.Class<T> messageClass)
Returns APTransformthat writes binary encoded protobuf messages of a given type to a Google Cloud Pub/Sub stream.
-
writeAvros
public static <T> PubsubIO.Write<T> writeAvros(java.lang.Class<T> clazz)
Returns APTransformthat writes binary encoded Avro messages of a given type to a Google Cloud Pub/Sub stream.
-
-