2
votes

In an application which is loading data in a batch process, how can Corda trigger many flows in parallel without tracking or observables?

On the RPC client there are only two methods (startFlowDynamic and startTrackedFlowDynamic) https://docs.corda.net/api/kotlin/corda/net.corda.core.messaging/-corda-r-p-c-ops/index.html

The goal is to avoid unnecessary overhead and run many flows in parallel. When tracked flows are used Corda deliver a warning about unused listeners: https://github.com/corda/corda/blob/release-V3.2/client/rpc/src/main/kotlin/net/corda/client/rpc/internal/RPCClientProxyHandler.kt#L143

1

1 Answers

3
votes

The warning that you're seeing when using startTrackedFlowDynamic is occurring because it returns several Observables that are not being used. As the warning says, you will need to manually close the unused ones by subscribing and then subscribing from them or use the helper method net.corda.client.rpc.UtilsKt#notUsed.

With regardings to running multiple flows in parallel then you can do something like this:

FlowHandle<Result> flowHandle1 = rpcProxy.startFlowDynamic(ExampleFlow.class, *flow parameters 1*);
FlowHandle<Result> flowHandle2 = rpcProxy.startFlowDynamic(ExampleFlow.class, *flow parameters 2*);
FlowHandle<Result> flowHandle3 = rpcProxy.startFlowDynamic(ExampleFlow.class, *flow parameters 3*);

Then you can wait for all of them to complete by simply waiting on each result Future object in turn:

Arrays.asList(flowHandle1, flowHandle2, flowHandle3).forEach(handle -> {
  handle.getReturnValue().get();
});