Run a Flow Using the Data Hub Java API

About this task

You can programmatically run a flow using the MarkLogic Data Hub Java API.


  1. In your build configuration file, declare the dependency on MarkLogic Data Hub Java API.
       dependencies {
       <dependency org='com.marklogic' name='marklogic-data-hub' rev='5.0.4'>
        <artifact name='$AID' ext='pom'></artifact>
  2. Copy the following code and customize it according to your needs.
    Note: runFlow allows you to run all the steps in the flow or only the steps you specify.
       package com.marklogic.hub.flow;
      import com.marklogic.hub.ApplicationConfig;
      import com.marklogic.hub.HubConfig;
      import org.springframework.beans.factory.annotation.Autowired;
      import org.springframework.boot.SpringApplication;
      import org.springframework.boot.WebApplicationType;
      import javax.annotation.PostConstruct;
      import java.util.Arrays;
      public class MyApp {
          // Get a HubConfig instance.
          HubConfig hubConfig;
          // Get a FlowRunner instance.
          FlowRunner fr;
          void runUserFlows() {
               * After Spring creates the HubConfig object and the project is initialized with
               * createProject(String), you can use setter methods to change the HubConfig properties
               * and then call the refreshProject() method which will load the HubConfig object with values
               * from (optionally overridden with gradle-{env}.properties) and the setters.
              // Runs the entire flow.
              RunFlowResponse testFlowResp = fr.runFlow("testFlow");
              // Runs only the specified steps.
              RunFlowResponse mapFlowResp = fr.runFlow("mapFlow", Arrays.asList("1","3"));
              // Wait for the flow to end.
          public static void main(String[] args) {
              // Start the Spring application.
              SpringApplication app = new SpringApplication(MyApp.class, ApplicationConfig.class);
  3. Run your code.