Java-SDK SpringBoot

Hi All,

Can anyone let me know how to implement more than one endpoint in temporal workflow both endpoints(one maybe POST and other maybe GET) having different workFlow ID using SpringBoot.

Can you give more info please, not sure I understand. You can create as many rest endpoints in your app and then use temporal sdk client apis to start/query workflow executions with any workflow id you need.

I have written this controller, in this controller i am able to access the post mapping but when i am testing the get mapping i am unable get any workflow and the error is the workflow started -

package com.example.temporal_employee_poc;

import io.temporal.client.WorkflowClient;
import io.temporal.client.WorkflowOptions;
import io.temporal.client.WorkflowStub;
import io.temporal.serviceclient.WorkflowServiceStubs;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.List;

@RestController
@RequestMapping(“/add”)
public class Controller {

@PostMapping
public ResponseEntity<List<Person>> addPerson(@RequestBody Person person) throws InterruptedException {
    WorkflowServiceStubs service = WorkflowServiceStubs.newLocalServiceStubs();
    WorkflowClient client = WorkflowClient.newInstance(service);
    final String WORKFLOW_ID = "addID";
    WorkflowOptions options = WorkflowOptions.newBuilder()
            .setWorkflowId(WORKFLOW_ID)
            .setTaskQueue(Shared.HELLO_WORLD_TASK_QUEUE)
            .build();
    EmployeeWorkflow workflow = client.newWorkflowStub(EmployeeWorkflow.class, options);
    List<Person> people = new ArrayList<>(workflow.addData(person));
    //System.out.println(workflow.fetchData());
    String workflowId = WorkflowStub.fromTyped(workflow).getExecution().getWorkflowId();
    return ResponseEntity.ok(people);
}

@GetMapping
public ResponseEntity<List<Person>> getPerson() {
    WorkflowServiceStubs service = WorkflowServiceStubs.newLocalServiceStubs();
    WorkflowClient client = WorkflowClient.newInstance(service);
    final String WORKFLOW_ID = "GetID";
    WorkflowOptions options = WorkflowOptions.newBuilder()
            .setWorkflowId(WORKFLOW_ID)
            .setTaskQueue(Shared.HELLO_WORLD_TASK_QUEUE)
            .build();
    EmployeeWorkflow workflow = client.newWorkflowStub(EmployeeWorkflow.class, options);
    List<Person> people = new ArrayList<>(workflow.fetchData());
    String workflowId = WorkflowStub.fromTyped(workflow).getExecution().getWorkflowId();
    return ResponseEntity.ok(people);
}

}

Don’t create ServiceStubs and WorkflowClient per request. They should be created once per process lifetime.

I think the logic problem is that you use different workflowId for executing and querying workflow. WorkflowId represented a specific workflow instance and it should be a business-level id. In your case, it should be some sort of customerId.

Also to query workflow you need to create a workflow stub by passing workflow id, not the options.

EmployeeWorkflow workflow = client.newWorkflowStub(EmployeeWorkflow.class, "personId");

i am not using sql, i am just using arraylist

can you share me any git repo or something which i can refer to solve this issue
or any git repo where multiple endpoints are being handled with springboot and java-sdk

We don’t have such a sample I think. Your problem is not related to endpoints of Springboot. I think there is a misunderstanding of WorkflowId semantic and how to use it.

can you please provide me a source where i can read more about this - WorkflowId semantic and how to use it.