Task Subscription API
The Task Subscription API allows for subscribing for different tasks. The process-engine-api adapter implementation then takes care of the delivery of the tasks matching the intended subscription.
@Component
@Slf4J
@RequiredArgsConstructor
public class TuskSubscriber {
private final TaskSubscriptionApi taskSubscriptionApi;
private final Map<TaskInformation, Map<String, ?>> userTasks = new ConcurrentHashMap<>();
@SneakyThrows
public void subscribe() {
taskSubscriptionApi.subscribeForTask(
new SubscribeForTaskCmd(
CommonRestrictions.builder().build(),
TaskType.USER, // user tasks only
null, // all of them
null, // all variables
(taskInfo, variables) -> {
if (!userTasks.containsKey(taskInfo)) { // don't replace existing tasks
log.info("[TASK LIST]: Received user task {} with meta {}", taskInfo.getTaskId(), taskInfo.getMeta());
userTasks.put(taskInfo, variables);
}
},
(taskId) -> {
log.info("[TASK LIST]: Removing task {}", taskId);
userTasks.keySet().stream().filter(info -> info.getTaskId().equals(taskId)).findFirst().ifPresent(userTasks::remove);
}
)
).get();
}
}