Use condition gateways
In a topology, you can add a pair of condition gateways to configure the execution logic. For example, you can specify that Task A is triggered when the specified conditions are met, and Task B is triggered when the conditions are not met. You can dynamically modify the conditions in the code to implement flexible task orchestration. This topic describes how to use a pair of condition gateways in a topology.
Procedure
Create tasks.
Create two or more simple tasks or cluster tasks and add custom condition parameter to use the tasks as sub-processes in a topology. In this example, simple tasks are created. For more information about how to create a simple task, see Create a scheduling task. Take note of the following parameter configuration:
Scheduling Type: You must select Event-based Trigger.
Communication Mode: You must select Callback.
Custom Parameters: You must add a custom parameter to specify a condition. The following figure shows an example.
You can also add a custom parameter in the local code. Example:@Override public ClientCommonResult handle(JobExecuteContext context) throws Exception{ context.putCustomParams("num",10); return ClientCommonResult.buildSuccessResult(); }NoteThe preceding example shows how to add a custom parameter in the code handler of a simple task. The parameter name used in the example is
num. You can customize parameter names based on your business requirements.
Edit the topology.
You can add a pair of condition gateways when you create or modify a topology. In this example, the sample topology is edited when it is being created. For more information, see Create a topology job. To edit the topology, perform the following steps:
Add a pair of condition gateways.
In the topology editing area, click the
icon, add a pair of condition gateways, and then click OK. Specify a condition.
Click the start condition gateway. In the Set Boundary Conditions dialog box, enter the custom parameter setting configured in Step 1, such as
num==10, and then click the
icon to save the condition.
Add tasks.
Add the simple or cluster tasks created in Step 1 on the two branches between the condition gateways.
If the condition is met, the task on the true branch is triggered.
If the condition is not met, the task on the false branch is triggered.
Click Submit.
On the Version Management tab, publish the topology of the current version.
Click Trigger Now in the upper-right corner to trigger this topology.
You can view the instances generated for the topology on the Scheduling Record tab.