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.

i would like my workers to startup during service init … and i have the following snippet

func initWorkers() {
	// Create the client object just once per process
	c, err := client.NewClient(client.Options{})
	if err != nil {
		log.Fatalln("unable to create Temporal client", err)
	}
	// This worker hosts both Worker and Activity functions
	w := worker.New(c, "KRONOS", worker.Options{})
	// Start listening to the Task Queue
	err = w.Start()
	if err != nil {
		log.Fatalln("unable to start Worker", err)
	}
}

#1. So the start is non-blocking and now my worker should be listenting to any workflows / activities started against its “KRONOS” queue. Is that correct?

#2. Am i able to view the workers in the temporal UI ? Seems i can only get there in the stacktrace of a workflow details … and just get " There are no Workers currently listening to the Task Queue"

#3. Here is a snippet of starting a workflow against the KRONOS queue

	options := client.StartWorkflowOptions{
		ID:        job.Name,
		TaskQueue: "KRONOS",
	}

	we, err := c.ExecuteWorkflow(ctx, options, ThisIsMyWorkflow, "HelloName")
	if err != nil {
		return nil, houston.UnknownError("failed to execute workflow ", err, false, nil)
	}

Does that seem about right? Keep getting this “Close Timeout” … so i may be doing something wrong

  1. I think in your case, the worker is not listening on a task queue as there are no activities and workflow types are registered with it. Use w.RegisterWorkflow and w.RegisterActivity to associate your activity and workflow implementations with the worker.
  2. Yes, the list of the connected workers should be visible in the Task Queue view. So “There are no Workers currently listening to the Task Queue” indicates that your worker is not really listening on that task queue.
  3. Looks good to me.

hi maxim,

thanks , so i guess whenever i start a worker i have to register workers and activities beforehand… i was thinking that i could have workers just on standby listening on their respective task queues and dynamically submit workflows, activites on the queue

kam

Would you explain the use case? Are you planning implementing activities and workflows dynamically?

Our microservices uses NATS and I was just thinking
I will could one microservices as a broker to termporal , this service will be subscribing to: - Start worker / Stop work etc

  • Register workflow
  • Register activity
  • start workflow / activity
    So i guess i don’t get much benefit out of that … might as well forget that and simply have each service do their own workflow/activity thing. Anyway i got it working and thanks for the help.

btw - we have a simple kind scheduler service but its very simplistic send a schedule with your “publish message” and that service simply publishes a message and looking for a workflow solution

In this answer I give my opinion why implementing activities and workflows directly is preferrable.

thanks for the link clears things up for me … cheers