FlowStarterService

Use the FlowStarterService to start flows from Corda Services.

How to inject FlowStarterService

Use the @CordaInject mechanism to inject FlowStarterService into services.

Java

Define a property of type FlowStarterService and annotate with @CordaInject:

@CordaInject
public FlowStarterService flowStarterService;

Kotlin

Define a lateinit property of type FlowStarterService and annotate with @CordaInject:

@CordaInject
lateinit var flowStarterService: FlowStarterService

Using the API

The FlowStarterService provides a single method called startFlow, taking a Flow as a parameter.

When defining your Corda Service, you need to wait for the StateMachineStarted lifecycle event before starting flows. You can do this by implementing the onEvent method and waiting for an event of type StateMachineStarted.

Java example

import net.corda.v5.application.injection.CordaInject;
import net.corda.v5.application.services.CordaService;
import net.corda.v5.application.services.flows.FlowStarterService;
import net.corda.v5.application.services.lifecycle.ServiceLifecycleEvent;
import net.corda.v5.application.services.lifecycle.StateMachineStarted;
import org.jetbrains.annotations.NotNull;

public class FlowStarterExample implements CordaService {

    @CordaInject
    public FlowStarterService flowStarterService;

    @Override
    public void onEvent(@NotNull ServiceLifecycleEvent event) {
        if (event instanceof StateMachineStarted){
            flowStarterService.startFlow(new MyFlow());
        }
    }
}

Was this page helpful?

Thanks for your feedback!

Chat with us

Chat with us on our #docs channel on slack. You can also join a lot of other slack channels there and have access to 1-on-1 communication with members of the R3 team and the online community.

Propose documentation improvements directly

Help us to improve the docs by contributing directly. It's simple - just fork this repository and raise a PR of your own - R3's Technical Writers will review it and apply the relevant suggestions.

We're sorry this page wasn't helpful. Let us know how we can make it better!

Chat with us

Chat with us on our #docs channel on slack. You can also join a lot of other slack channels there and have access to 1-on-1 communication with members of the R3 team and the online community.

Create an issue

Create a new GitHub issue in this repository - submit technical feedback, draw attention to a potential documentation bug, or share ideas for improvement and general feedback.

Propose documentation improvements directly

Help us to improve the docs by contributing directly. It's simple - just fork this repository and raise a PR of your own - R3's Technical Writers will review it and apply the relevant suggestions.