Exception when creating workflow Stub in Activity

Getting Exception: The following exception when I am trying to create workflow stub within an Activity.
I did start the workflow and Worker.

Please help…

java.lang.IllegalStateException: Null workflowId. Was workflow started?
at io.temporal.internal.sync.WorkflowStubImpl.checkStarted(WorkflowStubImpl.java:370)
at io.temporal.internal.sync.WorkflowStubImpl.signal(WorkflowStubImpl.java:88)
at io.temporal.internal.sync.WorkflowInvocationHandler$SyncWorkflowInvocationHandler.signalWorkflow(WorkflowInvocationHandler.java:297)
at io.temporal.internal.sync.WorkflowInvocationHandler$SyncWorkflowInvocationHandler.invoke(WorkflowInvocationHandler.java:274)
at io.temporal.internal.sync.WorkflowInvocationHandler.invoke(WorkflowInvocationHandler.java:178)
at com.sun.proxy.$Proxy12.setCustomActivityId(Unknown Source)
at io.workshop.c1intro.AccountActivitiesImpl.notify(AccountActivitiesImpl.java:53)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:566)


Activity Code:
public class AccountActivitiesImpl implements AccountActivities {

public static final WorkflowServiceStubs service = WorkflowServiceStubs.newInstance();
public static final WorkflowClient client = WorkflowClient.newInstance(service);
public static final String taskQueue = "myTaskQueue";

NotifyUserAccounts workflow;

@Override
public String notify(String accountId) throws Exception{

// try {
// // simulate some time…
// Thread.sleep(2 * 1000);
// } catch (Exception e) {
// e.printStackTrace();
// }

    workflow = client.newWorkflowStub(
            NotifyUserAccounts.class,
            WorkflowOptions.newBuilder()
                    .setWorkflowId(Activity.getExecutionContext().getInfo().getWorkflowId())
                    .setTaskQueue(taskQueue)
                    .build());



    workflow.setCustomActivityId("someName","someId");

    return "notified...";
}

}

Hello @Krishnendu_Kunti

can you try using the following overloaded method

       NotifyUserAccounts greetingWorkflow =
           client.newWorkflowStub(NotifyUserAccounts.class, workflowId);

You want to create a workflow stub with workflow options when the stub is used to start a workflow execution.

Also,
public String notify(String accountId) throws Exception{
signaling a workflow is an async operation, the client will never get the exception thrown by this method.

Antonio

Thank you Antonio , it did work :slightly_smiling_face:.

Can you please clarify the later statement, is it that Signal will be sent via a separate thread hence any exception encountered while sending the signal will not be caught in the activity Implementation method.

However such exception will be caught in in the signal method.

Thanks again
Krishnendu

@Krishnendu_Kunti signalWorkflow is a request that the server persists once it receives it. You will get an exception if the client can not connect to the server or the workflow execution does not exist …

The worker running the workflow execution (the one you are signaling), is continuously polling for task to execute. If it has pollers and slots available to execute workflowTasks, the worker will pull the task and deliver the signal to the workflow execution.

let me know if it helps

In your case, it looks like you are signaling the same workflow execution. What is your use case if I can ask?

Thanks,

Hi @antonio.perez

Thanks for the clarification. We have a scenario where we will be using same activity more than once , where we want to display the activity with different Name.

Say we have a DB table migrate activity with method migrate , instead of calling this migrate every time we would like to show it as migrate_table1, migrate_2… etc.

We plan to achieve it by saving the activity Id and Activity given name in custom search attribute. Since we cant update search attribute inside an activity we plan to sent the details to workflow before we start an activity.

Since we will send the name / id using Signal even before we stat the Activity the Workflow instance should be available.

Thank you
Krishnendu

Updating search attributes on each activity puts an additional load on ES and can limit scalability.

You can use DynamicActivity to implement an activity of any type and Workflow.newUntypedActivityStub.execute to invoke it.