Class RequestResponseIO<RequestT,ResponseT>

java.lang.Object
org.apache.beam.sdk.transforms.PTransform<PCollection<RequestT>,Result<ResponseT>>
org.apache.beam.io.requestresponse.RequestResponseIO<RequestT,ResponseT>
All Implemented Interfaces:
Serializable, HasDisplayData

public class RequestResponseIO<RequestT,ResponseT> extends PTransform<PCollection<RequestT>,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.

Basic Usage

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 of(org.apache.beam.io.requestresponse.Caller<RequestT, ResponseT>, org.apache.beam.sdk.coders.Coder<ResponseT>) method your Caller implementation.


 Coder<SomeResponse> responseCoder = ...
 PCollection<SomeRequest> requests = ...
 Result result = requests.apply(RequestResponseIO.of(new MyCaller(), responseCoder));
 result.getResponses().apply( ... );
 result.getFailures().apply( ... );
 
See Also: