Hi! I’m a new to camunda and I’m developing an app that uses camunda engine.
All calls can be executed only by Java API. Any requests to rest API are forbidden.
I use External Task in my flow and can any one explain what is exact role of workerId?
And for resolving external tasks I use scheduler that calls pollAndExecuteTask() every 20 secs. Is this way of resolving externals tasks is fine? Or are there any common patterns? Thanks in advance!
@Service
class PerfTrackerExternalWorker(
private val externalTaskService: ExternalTaskService,
) {
companion object : KLogging()
fun pollAndExecuteTask() {
val tasks = externalTaskService
.fetchAndLock(10, "workerId")
.topic("topic1", 60L * 1000L).execute()
for (task in tasks) {
try {
logger.info { task.topicName }
externalTaskService.complete(task.id, "workerId", mutableMapOf<String, Any>())
} catch (ex: Exception) {
logger.info { "Error" }
}
}
}
}
Hey @lookeme and welcome to the Forum!
Before answering your question about the external task pattern I wanted to ask why you do not rely on Java Delegates? - Especially since you do not want to use Camunda’s REST API. Keep in mind that the external task pattern usually relies on the REST API.
Now let’s chat about the wokerID
:
When your external task worker pulls tasks from the engine it will “register” over there. By doing so, you can transparently see which worker is currently executing a task and thats persisted as well.
Docu: Fetch and Lock External Tasks | docs.camunda.org
Next up: The 20 second interval seems to be set quite high. Due to this it can happen that you need to wait up to 20 seconds until your external task worker fetches the next bunch of tasks. If this is intended, that’s fine. Otherwise you can make use of a faster poll rate which increases in case the engine has no tasks.
Let me know if you have any further questions! 
1 Like
Hey! Thank you for your answer!
Regarding Java Delegates and External Task I don’t know witch one to use in my case.
External Task at first sight seems to me like a common pattern.
My goal is just to communicate with other services (in my case microservices). Send an event thru kafka or send http request. So if Service Task and Java Delegates works fine for this purpose I’m totally ok with that!
Regarding workerId is clear thank you!
The 20 sec interval is just an example so it’s of course configurable.
There is a subprocess that starts from Call Activity element.
Where each step is just interaction with external services (kafka or http).
Unfortunately I can’t upload a picture(