Workflow vs Activity

Hi all,

I was going through HelloActivity.java.

Line no. 68 mentions that “Activities are building blocks of any Temporal Workflow”.
If that is the case, why do we need to register Activities with the Worker as done in Line no. 157?
Isn’t registering the Workflow (Line no. 151) enough?

Can an Activity have an independent existence without a Workflow?

Thanks,
Joe

Hi @Joe_Antony

Technically you can have separate workers for workflows and activities,

Every time your workflow invokes an activity , like in line 106, the activity task is scheduled in a taskqueue in the server. By default, the activity is scheduled in a taskqueue with the same name as the workflow taskqueue (they have the same name but they are different taskqueues)

Note that you can set the activity taskqueue name in ActivityOptions.

    private final GreetingActivities activities =
        Workflow.newActivityStub(
            GreetingActivities.class,
            ActivityOptions.newBuilder()
                    .setTaskQueue("my-other-taskqueue")
                    .build());

On the other side you have your workers, the once that do the work.

In your worker configuration you have to set at least

Once the worker starts, it opens long poll connections to the server. If there are tasks in the queue the worker is polling from, the server will dispatch a task to the worker, so the worker can execute it.

By registering the activity implementation we are telling the worker what to do with the task (the code it has to execute). Otherwise it won’t know what to do and you will likely see this error in the worker.

I would recommend you to go through this course if you have time, which go through this and other concepts.

Other relevant resources:

Please feel free to reply back with questions if something is unclear.

Can an Activity have an independent existence without a Workflow?

Can not right now.

Antonio

2 Likes

Thanks a lot @antonio.perez !
Really appreciate the effort put into constructing the reply:)