Hi All,
i’m trying to fetch the task using fetchAndLock() but getting zero task.
I have two services which are spring boot camunda application(process-service) and one more is ExternalTask client spring boot application(notification-service).
The process-service is having running tasks and i’m trying to fetch those task with ExternalTask using fetchAndLock() but getting as zero task.
attached code snippet please suggest there is any way to fetch and lock the tasks.
@Inject
private ExternalTaskService externalTaskService;
@ExternalTaskSubscription("notificationTopic")
@Bean
public void sendEmailNotification() throws Exception {
List<LockedExternalTask> tasks = externalTaskService.fetchAndLock(5, "worker")
.topic("externalTaskTopic", 1000L).execute();
for (LockedExternalTask task : tasks) {
// Business logic for send mail
externalTaskService.complete(task.getId, worker);
I’m already done with your GitHub code flow and i’m able to proceed, but i want to fetch the tasks using fetchAndLock(),
why i’m getting zero task even having multiple process instances running in Camunda Platform 7 already.
Could you please help on this below flow, i need to use the fetchAndLock() method only to get the tasks.
public void sendEmailNotification() throws Exception {
List<LockedExternalTask> tasks = externalTaskService.fetchAndLock(5, "worker")
.topic("externalTaskTopic", 1000L).execute();
for (LockedExternalTask task : tasks) {
if you use the annotation @ExternalTaskSubscription in the spring-boot-application, you will get the task and the service in a lambda function:
@Bean
@ExternalTaskSubscription("creditScoreChecker")
public ExternalTaskHandler creditScoreCheckerHandler() {
return (externalTask, externalTaskService) -> {
// add your business logic here
externalTaskService.complete(externalTask);
};
}
I’m from the Purushotham’s team, what is the difference between both the approaches ? `Approach-1: @ExternalTaskSubscription(“collateral4EyeCheckTopic”) @Bean
public ExternalTaskHandler updateCollateral4EyeCheckResult() {
return (externalTask, externalTaskService) -> {
String status=externalTask.getVariable("4eyeCheckStatus");
LOG.info("<=========Collateral 4EyeCheck completed with status {} for task{}============>",status,externalTask.getId());
externalTaskService.complete(externalTask);
};
}andApproach-2 @ExternalTaskSubscription(“collateral4EyeCheckTopic”) @Bean
public void updateCollateral4EyeCheckResult1() {
List tasks = externalTaskService.fetchAndLock(10, “collateral-4eyeCheck-result-processor”)
.topic(“collateral4EyeCheckTopic”, 20000L)
.execute();
for (LockedExternalTask task : tasks) {
LOG.info("<=========task{} started============>",task.getId());
String approvalStatus = (String) task.getVariables().get(“4eyeCheckStatus”);
externalTaskService.complete(task.getId(),approvalStatus);
}
}`
Here, Approach-1 is working fine but while using Approach-2 it returns 0 task as explained by Purushotham in above thread.
This is the exact same issue that Ingo explained above, and is clear in the link that was supplied.
When the @ExternalTaskSubscription is used, it will AUTOMATICALLY fetch tasks.
Since the task is already collected, it cannot be collected again.