You can programmatically run a flow by using the MarkLogic Data Hub Java API in a Java application, such as an external orchestration tool or a custom web application.
The FlowRunner
class provides a runFlow
method which does not require project files in the local filesystem. This method accepts a single parameter of type FlowInputs
and is the preferred method for running flows programmatically.
Procedure
- In your build configuration file, declare the dependency on MarkLogic Data Hub Java API.
dependencies {
compile('com.marklogic:marklogic-data-hub:5.2.1')
}
<dependency>
<groupId>com.marklogic</groupId>
<artifactId>marklogic-data-hub</artifactId>
<version>5.2.1</version>
<type>pom</type>
</dependency>
<dependency org='com.marklogic' name='marklogic-data-hub' rev='5.2.1'>
<artifact name='$AID' ext='pom'></artifact>
</dependency>
- Copy the following code and customize it according to your needs.
package org.example;
import com.marklogic.hub.flow.FlowInputs;
import com.marklogic.hub.flow.FlowRunner;
import com.marklogic.hub.flow.RunFlowResponse;
import com.marklogic.hub.flow.impl.FlowRunnerImpl;
public class Main {
public static void main(String[] args) {
// Create a FlowRunner instance.
FlowRunner flowRunner = new FlowRunnerImpl("myHost", "myUser", "myPassword");
// Specify the flow to run.
FlowInputs inputs = new FlowInputs("my-flow-name");
// To run only a subset of the steps in the flow, uncomment the following line and specify the sequence numbers of the steps to run.
// inputs.setSteps(Arrays.asList("2,3,4"));
// Run the flow.
RunFlowResponse response = flowRunner.runFlow(inputs);
// Wait for the flow to end.
flowRunner.awaitCompletion();
// Display the response.
System.out.println("Response: " + response);
}
}
- Run your code.
Example
The dh-5-example project in GitHub includes the following example code files: