I was looking for a more sophisticated workflow than Saga from AxonFramework -- which we are currently using -- and I found one in Netflix Conductor. Sadly, I have searched the Internet for a decent example but to no avail.
My question is, in Netflix Conductor, how might one define and create Task or WorkflowTask and most importantly, link a microservice to it? Here is a Netflix Conductor code from github:
WorkflowDef def = new WorkflowDef();
def.setName("test");
WorkflowTask t0 = new WorkflowTask();
t0.setName("t0");
t0.setType(Type.SIMPLE);
t0.setTaskReferenceName("t0");
WorkflowTask t1 = new WorkflowTask();
t1.setName("t1");
t1.setType(Type.SIMPLE);
t1.setTaskReferenceName("t1");
def.getTasks().add(t0);
def.getTasks().add(t1);
Pardon my confusion as I am new to Netflix Conductor.
Assuming the Micro service has a REST Endpoint over HTTP. In that case you've to use HttpTask which is a system task. Httptask makes a Http call and the response is available as task output. Pls refer to the below link: HttpTask
Pls remember to set the SchemaVersion as 2 for the WorkflowDef which contains HttpTask. You would also need a corresponding Task type registered.
(disclaimer: i haven't tried, i just looked at documentation...)
@Configuration
public class Configuration {
@Bean
public TaskClient taskClient(@Value("${conductor url}") String conductorServerURL) {
TaskClient taskClient = new TaskClient();
taskClient.setRootURI(conductorServerURL);
return taskClient;
}
@Bean
public TaskRunnerConfigurer taskRunnerConfigurer(
@Autowired final TaskClient taskClient,
@Autowired final List<Worker> workers) {
final TaskRunnerConfigurer taskRunnerConfigurer = new TaskRunnerConfigurer.Builder(taskClient, workers)
.withThreadCount(3)
.build();
taskRunnerConfigurer.init();
return taskRunnerConfigurer;
}
}
This workers will poll to tasks from conductor server
There are now a number of SDKs to connect your microservice worker to Conductor: https://github.com/conductor-sdk/
You can create a SIMPLE task in Conductor (using the API endpoint, and these parameters https://conductor.netflix.com/configuration/taskdef.html .
Workers poll your tasks in Conductor. When a task as work to be run, it assigns that to the worker. On completion the task takes the results from the workers back to the Conductor workflow.
Here's an worker in Go: https://github.com/conductor-sdk/conductor-examples/tree/main/go-samples
And a Java example: https://github.com/orkes-io/orkesworkers
Finally - there is now a free cloud playground for Netflix conductor at https://play.orkes.io
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.