/** * Returns A {@link PTransform} that continuously reads binary encoded protobuf messages of the * given type from a Google Cloud Pub/Sub stream. */ public static <T extends Message> Read<T> readProtos(Class<T> messageClass) { // TODO: Stop using ProtoCoder and instead parse the payload directly. // We should not be relying on the fact that ProtoCoder's wire format is identical to // the protobuf wire format, as the wire format is not part of a coder's API. ProtoCoder<T> coder = ProtoCoder.of(messageClass); return PubsubIO.<T>read().withCoderAndParseFn(coder, new ParsePayloadUsingCoder<>(coder)); }
/** * Returns A {@link PTransform} that continuously reads UTF-8 encoded strings from a Google Cloud * Pub/Sub stream. */ public static Read<String> readStrings() { return PubsubIO.<String>read() .withCoderAndParseFn(StringUtf8Coder.of(), new ParsePayloadAsUtf8()); }
/** * Returns A {@link PTransform} that continuously reads binary encoded Avro messages of the given * type from a Google Cloud Pub/Sub stream. */ public static <T> Read<T> readAvros(Class<T> clazz) { // TODO: Stop using AvroCoder and instead parse the payload directly. // We should not be relying on the fact that AvroCoder's wire format is identical to // the Avro wire format, as the wire format is not part of a coder's API. AvroCoder<T> coder = AvroCoder.of(clazz); return PubsubIO.<T>read().withCoderAndParseFn(coder, new ParsePayloadUsingCoder<>(coder)); }