public class RequestResponseIO<RequestT,ResponseT> extends PTransform<PCollection<RequestT>,RequestResponseIO.Result<ResponseT>>
PTransform
for reading from and writing to Web APIs.
RequestResponseIO
is recommended for interacting with external systems that offer RPCs
that execute relatively quickly and do not offer advance features to make RPC execution
efficient.
For systems that offer features for more efficient reading, for example, tracking progress of RPCs, support for splitting RPCs (deduct two or more RPCs which when combined return the same result), consider using the Apache Beam's `Splittable DoFn` interface instead.
RequestResponseIO
minimally requires implementing the Caller
interface:
class MyCaller implements Caller<SomeRequest, SomeResponse> {
public SomeResponse call(SomeRequest request) throws UserCodeExecutionException {
// calls the API submitting SomeRequest payload and returning SomeResponse
}
}
Then provide RequestResponseIO
's #create
method your Caller
implementation.
PCollection<SomeRequest> requests = ...
Result result = requests.apply(RequestResponseIO.create(new MyCaller()));
result.getResponses().apply( ... );
result.getFailures().apply( ... );
Modifier and Type | Class and Description |
---|---|
static class |
RequestResponseIO.Result<ResponseT>
The
RequestResponseIO.Result of processing request PCollection into response PCollection
using custom Caller code. |
name, resourceHints
Modifier and Type | Method and Description |
---|---|
RequestResponseIO.Result<ResponseT> |
expand(PCollection<RequestT> input)
Override this method to specify how this
PTransform should be expanded on the given
InputT . |
static <RequestT,ResponseT> |
of(Caller<RequestT,ResponseT> caller) |
compose, compose, getAdditionalInputs, getDefaultOutputCoder, getDefaultOutputCoder, getDefaultOutputCoder, getKindString, getName, getResourceHints, populateDisplayData, setResourceHints, toString, validate, validate
public static <RequestT,ResponseT> RequestResponseIO<RequestT,ResponseT> of(Caller<RequestT,ResponseT> caller)
public RequestResponseIO.Result<ResponseT> expand(PCollection<RequestT> input)
PTransform
PTransform
should be expanded on the given
InputT
.
NOTE: This method should not be called directly. Instead apply the PTransform
should
be applied to the InputT
using the apply
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).
expand
in class PTransform<PCollection<RequestT>,RequestResponseIO.Result<ResponseT>>