A saga can be executed using the saga client API. The client has to be able to access the same cluster that the saga coordinator is running on.
The saga API has two methods:
submitSaga- submits a request to execute a saga.
getSagaResponse- asynchronously queries the result of saga execution. It returns a
FutureResultthat asynchronously completes with the result of the saga when the saga completes.
The Kafka implementation of this API publishes a saga request to the saga request topic in Kafka when
submitSaga is called,
and waits for a result to appear in the saga result topic to complete
To create an instance of the saga API, a saga client builder is available.
SagaAPI<A> sagaApi = SagaClientBuilder .create(propsBuilder -> propsBuilder.withBootstrapServers("kafka_broker:9092")) .withSerdes(serdes) .withClientId(clientId) .withScheduler(scheduler) .build();
withSerdesis to specify a SagaClientSerdes used to serialise the saga request and saga responses.
withClientIdis used to create a private topic to stream saga results to. This enables the client to listen to only the it made. Each client instance should have a unique client ID.