General Questions

Hello,

I was looking at the https://github.com/temporalio/hello-world-project-template-java example and also at the documentation in general, and I have some basic questions:

From the example:

  • One of them starts a workflow synchronously ( InitiateHelloWorld ) and executes a method, a workflow that is associated with a specific task queue
  • The other one ( HelloWorldWorker ) starts a worker listening to incoming task queue and it registers a workflow implementation and some activities, and it starts polling the task queue

Questions:

  • how do I actually signal the worker to start the workflow? To me, once I execute the worker code, that doesn’t seem to do anything in terms of execution, just set up, and association of worker with workflow. Would you first create a worker listening to a task queue, and then start the workflow either in a sync or async manner ? That seemed to have worked for me

  • from the docs, I see that a worker can be associated with millions of workflows listening on the same task queue, I was thinking to have a setup where 1 workflow has 1 worker associated with it and any instances of that workflow will be served by that worker… is that a good model, given that we would potentially have lots of workflows, thus lots of workers ?

  • what happens if we don’t start a worker manually? Does temporal automatically assign one to the workflow? From what I can see you HAVE to specify a worker for a workflow before you start it, because otherwise if you don’t have any workers listening on the task queue that you’re attempting to send a “start task” to, it wouldn’t know what worker to assign it to? Do I have a good understanding here?

  • a workflow method, from the docs, is essentially the method that gets called as the entry point in the workflow. Can you have multiple @workflowMethods ? What happens then ?

  • is there a way to query workflows and get the information available on the temporal-web side , via an API call or something similar (or through the SDK)? Not talking about the @queryMethod here, just about the general information that you would get on the temporal front-end. Would you just use the available objects and their getters ?

  • is there an example of starting the workflow asynchronously using the Java SDK ?

  • how do I actually signal the worker to start the workflow? To me, once I execute the worker code, that doesn’t seem to do anything in terms of execution, just set up, and association of worker with workflow. Would you first create a worker listening to a task queue, and then start the workflow either in a sync or async manner ? That seemed to have worked for me

You don’t explicitly. Worker listens on a task queue. When a task is received the correspondent workflow code is executed. But all of this is managed by the Temporal SDK. You can start workflows or workers in any order. As starting workflow just creates its state in the service and creates a task in the correspondent task queue. The task stays in a queue until picked up by a worker that can start much later.

from the docs, I see that a worker can be associated with millions of workflows listening on the same task queue, I was thinking to have a setup where 1 workflow has 1 worker associated with it and any instances of that workflow will be served by that worker… is that a good model, given that we would potentially have lots of workflows, thus lots of workers ?

There is no need to have a worker per workflow type. You can have many workflow types associated with the same worker. Only if you want to deploy different workflows in different processes then you create multiple workers each listening on its own task queue. Temporal has no problem supporting many task queues with many processes listening on the same task queue.

what happens if we don’t start a worker manually? Does temporal automatically assign one to the workflow? From what I can see you HAVE to specify a worker for a workflow before you start it, because otherwise if you don’t have any workers listening on the task queue that you’re attempting to send a “start task” to, it wouldn’t know what worker to assign it to? Do I have a good understanding here?

When a workflow is started its workflow task is put in a task queue specified through the workflow options. This doesn’t require any workers running. Workers are needed to process that task. When a worker is running it is getting tasks and processing them. Task queues are normal queues. So only one worker from many listening on the given task queue receives a given task.

a workflow method, from the docs, is essentially the method that gets called as the entry point in the workflow. Can you have multiple @workflowMethods ? What happens then ?

It is not allowed to specify multiple methods annotated with @WorkflowMethod. Worker.registerWorkflowType call with fail if you try to register a workflow that has multiple such methods.

Temporal Web and CLI use the public Temporal gRPC API.. You can call it directly from any language that supports gRPC if you wan to get the same information.

is there an example of starting the workflow asynchronously using the Java SDK ?

See Money Transfer Sample.