Class PubsubIO.Write<T>
- All Implemented Interfaces:
Serializable
,HasDisplayData
- Enclosing class:
PubsubIO
- See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionclass
Writer to Pubsub which batches messages from bounded collections. -
Field Summary
Fields inherited from class org.apache.beam.sdk.transforms.PTransform
annotations, displayData, name, resourceHints
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionexpand
(PCollection<T> input) Override this method to specify how thisPTransform
should be expanded on the givenInputT
.void
populateDisplayData
(DisplayData.Builder builder) Register display data for the given transform or component.Publishes to the specified topic.to
(ValueProvider<String> topic) Liketopic()
but with aValueProvider
.to
(SerializableFunction<ValueInSingleWindow<T>, String> topicFunction) Provides a function to dynamically specify the target topic per message.void
validate
(PipelineOptions options) Called before running the Pipeline to verify this transform is fully and correctly specified.The default client to write to Pub/Sub is thePubsubJsonClient
, created by theinvalid reference
PubsubJsonClient.PubsubJsonClientFactory
withErrorHandler
(ErrorHandler<BadRecord, ?> badRecordErrorHandler) Writes any serialization failures out to the Error Handler.withIdAttribute
(String idAttribute) Writes to Pub/Sub, adding each record's unique identifier to the published messages in an attribute with the specified name.withMaxBatchBytesSize
(int maxBatchBytesSize) Writes to Pub/Sub are limited by 10mb in general.withMaxBatchSize
(int batchSize) Writes to Pub/Sub are batched to efficiently send data.Writes to Pub/Sub with each record's ordering key.withPubsubRootUrl
(String pubsubRootUrl) withTimestampAttribute
(String timestampAttribute) Writes to Pub/Sub and adds each record's timestamp to the published messages in an attribute with the specified name.Enable validation of the PubSub Write.Methods inherited from class org.apache.beam.sdk.transforms.PTransform
addAnnotation, compose, compose, getAdditionalInputs, getAnnotations, getDefaultOutputCoder, getDefaultOutputCoder, getDefaultOutputCoder, getKindString, getName, getResourceHints, setDisplayData, setResourceHints, toString, validate
-
Constructor Details
-
Write
public Write()
-
-
Method Details
-
to
Publishes to the specified topic.See
PubsubIO.PubsubTopic.fromPath(String)
for more details on the format of thetopic
string. -
to
Liketopic()
but with aValueProvider
. -
to
Provides a function to dynamically specify the target topic per message. Not compatible with any of the other to methods. Ifto(java.lang.String)
is called again specifying a topic, then this topicFunction will be ignored. -
withClientFactory
The default client to write to Pub/Sub is thePubsubJsonClient
, created by theinvalid reference
PubsubJsonClient.PubsubJsonClientFactory
PubsubClient.PubsubClientFactory
like theinvalid reference
PubsubGrpcClientFactory
-
withMaxBatchSize
Writes to Pub/Sub are batched to efficiently send data. The value of the attribute will be a number representing the number of Pub/Sub messages to queue before sending off the bulk request. For example, if given 1000 the write sink will wait until 1000 messages have been received, or the pipeline has finished, whichever is first.Pub/Sub has a limitation of 10mb per individual request/batch. This attribute was requested dynamic to allow larger Pub/Sub messages to be sent using this source. Thus allowing customizable batches and control of number of events before the 10mb size limit is hit.
-
withMaxBatchBytesSize
Writes to Pub/Sub are limited by 10mb in general. This attribute controls the maximum allowed bytes to be sent to Pub/Sub in a single batched message. -
withOrderingKey
Writes to Pub/Sub with each record's ordering key. A subscription with message ordering enabled will receive messages published in the same region with the same ordering key in the order in which they were received by the service. Note that the order in which Beam publishes records to the service remains unspecified.- See Also:
-
withTimestampAttribute
Writes to Pub/Sub and adds each record's timestamp to the published messages in an attribute with the specified name. The value of the attribute will be a number representing the number of milliseconds since the Unix epoch. For example, if using the Joda time classes,Instant(long)
can be used to parse this value.If the output from this sink is being read by another Beam pipeline, then
PubsubIO.Read.withTimestampAttribute(String)
can be used to ensure the other source reads these timestamps from the appropriate attribute. -
withIdAttribute
Writes to Pub/Sub, adding each record's unique identifier to the published messages in an attribute with the specified name. The value of the attribute is an opaque string.If the output from this sink is being read by another Beam pipeline, then
PubsubIO.Read.withIdAttribute(String)
can be used to ensure that* the other source reads these unique identifiers from the appropriate attribute. -
withPubsubRootUrl
-
withErrorHandler
Writes any serialization failures out to the Error Handler. SeeErrorHandler
for details on how to configure an Error Handler. Error Handlers are not well supported when writing to topics with schemas, and it is not recommended to configure an error handler if the target topic has a schema. -
withValidation
Enable validation of the PubSub Write. -
expand
Description copied from class:PTransform
Override this method to specify how thisPTransform
should be expanded on the givenInputT
.NOTE: This method should not be called directly. Instead apply the
PTransform
should be applied to theInputT
using theapply
method.Composite transforms, which are defined in terms of other transforms, should return the output of one of the composed transforms. Non-composite transforms, which do not apply any transforms internally, should return a new unbound output and register evaluators (via backend-specific registration methods).
- Specified by:
expand
in classPTransform<PCollection<T>,
PDone>
-
validate
Description copied from class:PTransform
Called before running the Pipeline to verify this transform is fully and correctly specified.By default, does nothing.
- Overrides:
validate
in classPTransform<PCollection<T>,
PDone>
-
populateDisplayData
Description copied from class:PTransform
Register display data for the given transform or component.populateDisplayData(DisplayData.Builder)
is invoked by Pipeline runners to collect display data viaDisplayData.from(HasDisplayData)
. Implementations may callsuper.populateDisplayData(builder)
in order to register display data in the current namespace, but should otherwise usesubcomponent.populateDisplayData(builder)
to use the namespace of the subcomponent.By default, does not register any display data. Implementors may override this method to provide their own display data.
- Specified by:
populateDisplayData
in interfaceHasDisplayData
- Overrides:
populateDisplayData
in classPTransform<PCollection<T>,
PDone> - Parameters:
builder
- The builder to populate with display data.- See Also:
-