AsyncFlatMapFunction (samza-api 1.9.0-SNAPSHOT API) JavaScript is disabled on your browser. Skip navigation links Overview Package Class Tree Deprecated Index Help Prev Class Next Class Frames No Frames All Classes Summary:  Nested |  Field |  Constr |  Method Detail:  Field |  Constr |  Method org.apache.samza.operators.functions Interface AsyncFlatMapFunction<M,OM> Type Parameters: M - type of the input message OM - type of the transformed messages All Superinterfaces: ClosableFunction, InitableFunction, java.io.Serializable Functional Interface: This is a functional interface and can therefore be used as the assignment target for a lambda expression or method reference. @InterfaceStability.Unstable @FunctionalInterface public interface AsyncFlatMapFunction<M,OM> extends InitableFunction, ClosableFunction, java.io.Serializable Asynchronous variant of the FlatMapFunction used in tandem with MessageStream.flatMapAsync(AsyncFlatMapFunction) to transform a collection of 0 or more messages. Typically, AsyncFlatMapFunction is used for describing complex transformations that involve IO operations or remote calls. The following pseudo code demonstrates a sample implementation of AsyncFlatMapFunction that sends out an email and returns the status asynchronously. AsyncFlatMapFunction<Email, Status> asyncEmailSender = (Email message) -> { ... Request<Email> emailRequest = buildEmailRequest(message); Future<EmailResponse> emailResponseFuture = emailClient.sendRequest(emailRequest); // send email asynchronously ... return new CompletableFuture<>(emailResponseFuture) .thenApply(response -> fetchStatus(response); } The function needs to be thread safe in case of task.max.concurrency>1. It also needs to coordinate any shared state since happens-before is not guaranteed between the messages delivered to the function. Refer to MessageStream.flatMapAsync(AsyncFlatMapFunction) docs for more details on the modes and guarantees. For each invocation, the CompletionStage returned by the function should be completed successfully/exceptionally within task.callback.timeout.ms; failure to do so will result in SamzaException bringing down the application. Method Summary All Methods Instance Methods Abstract Methods  Modifier and Type Method and Description java.util.concurrent.CompletionStage<java.util.Collection<OM>> apply(M message) Transforms the provided message into a collection of 0 or more messages. Methods inherited from interface org.apache.samza.operators.functions.InitableFunction init Methods inherited from interface org.apache.samza.operators.functions.ClosableFunction close Method Detail apply java.util.concurrent.CompletionStage<java.util.Collection<OM>> apply(M message) Transforms the provided message into a collection of 0 or more messages. Parameters: message - the input message to be transformed Returns: a CompletionStage of a Collection of transformed messages Skip navigation links Overview Package Class Tree Deprecated Index Help Prev Class Next Class Frames No Frames All Classes Summary:  Nested |  Field |  Constr |  Method Detail:  Field |  Constr |  Method