Using TaskListener in remote engine model

Hi everyone,
We use remote engine server model and integrate it with our service with the engine via RestAPIs. We use external Tasks for service tasks to decouple services and to be able to scale up the system.
Now I want to use Task Listener feature for UserTasks but it seems it does not support external tasks and it has java class option. Is there any way to use TaskListener without using embedded engine model?

Thanks

I don’t believe there is a way to get that functionality with a remote engine, unfortunately.

Thanks for your reply,
So if I understand correctly, I have to use just an embedded model to use task listener and execution listener features.
Right?

You can also implement external task listeners in other languages as external tasks. I do this in Golang all the time:

client := camundaclientgo.NewClient("http://localhost:8080/engine-rest",
		Timeout:     time.Second * 20,
		ApiUser:     "demo",
		ApiPassword: "demo",
	})
logger := func(err error) {
		log.Error(err)
	}
asyncResponseTimeout := 5000
// get a process instance to work with
proc := processor.NewProcessor(client, &processor.ProcessorOptions{
	WorkerId:                  "MyWorkerID",
	LockDuration:              time.Second * 10,
	MaxTasks:                  10,
	MaxParallelTaskPerHandler: 100,
	LongPollingTimeout:        10 * time.Second,
	AsyncResponseTimeout:      &asyncResponseTimeout,
}, logger)
proc.AddHandler(
	&[]camundaclientgo.QueryFetchAndLockTopic{
		{TopicName: "YourTopic"},
	},
	func(ctx *processor.Context) error {
		return myFunction(ctx.Task.Variables, ctx)
	},
)

The function myFunction() will get called whenever a Task with the id “YourTopic” is created.

Hope that helps at least a little.

Best Regards,
dg

You can still use the external task implementations as @davidgs pointed out and you are most likely already doing. That’s for the main behaviour implementation of the task itself. If you need additional behaviour on lifecyle events of the task, there’s only the Java way do do that at the moment. There’s no “external” implementation type for those Execution/TaskListeners.

That doesn’t mean you can’t combine the two approaches: you could still use external task implementations and have Execution/TaskListeners configured on the model that execute Java code. This will work perfectly fine. But the listeners have to be implemented in Java and configured either on the model or attached automatically from a BpmnParseListener (which can be very useful for re-use)

1 Like

Thanks again,
I am already using Java in my application but I don’t embed the engine in my application. So I have a Camunda engine image and a java application image separately. I use Camunda external task libraries to implement external Tasks with defined topics in my BPMNs. But now I am a little confused about this Task Listener implementation. I think because my Camunda engine is separate from my application and doesn’t know about my Java application I can’t use its classes in BPMN in java class field for java delegate way. Am I wrong?
I will appreciate it if you could clarify it for me.

Thanks

Sorry if that confused you. You’re right, in your process engine application, you can only access classes that are part of that application. You can’t implement the TaskListeners in your application where you implement the external task workers, because that is a separate process and the classes are not available to the process engine. The engine expects to be able to execute the listeners on an application thread available to the engine.

So if you want to add TaskListeners to (some of) your user tasks, that would mean you would have to add the classes to the application that runs the process engine. Which means that you would have the process implementation split between two applications and if you need to make changes, you might have to update both.

@tiesebarrell Thanks for your clear and helpful answer.

1 Like