Passing signal to a running execution using Java SDK

I have a newbie question regarding signals using the Java SDK. I was HelloSignal example and was trying out the following:

  1. From Process A, start the workflow execution. Workflow completes the first Activity and waits for the signal.
    Code:
    WorkflowServiceStubs service = WorkflowServiceStubs.newInstance();
    WorkflowClient client = WorkflowClient.newInstance(service);
    WorkflowOptions options = WorkflowOptions.newBuilder()
        .setTaskQueue(Util.TASK_QUEUE)
        .setWorkflowExecutionTimeout(Duration.ofDays(1L))
        .setWorkflowId("welcome-email")
        .build();`

    ExpeditionWorkflow workflow = client.newWorkflowStub(ExpeditionWorkflow.class, options);
    WorkflowClient.start(workflow::execute);
    System.out.println("Successfully started");`
  1. From Process B, send a signal to the workflow execution started by process B:
    WorkflowServiceStubs service = WorkflowServiceStubs.newInstance();
    WorkflowClient client = WorkflowClient.newInstance(service);
    WorkflowOptions options = WorkflowOptions.newBuilder()
        .setTaskQueue(Util.TASK_QUEUE)
        .setWorkflowExecutionTimeout(Duration.ofDays(1L))
        .setWorkflowId("welcome-email")
        .build();
    DescribeWorkflowExecutionRequest e;
    ExpeditionWorkflow workflow = client.newWorkflowStub(ExpeditionWorkflow.class, options);
    String[] signal = {"WelcomeEmailPlacement", "Open"};
    workflow.placementReceived(signal);`

However, it looks like the workflow execution isn’t being set in process B and I’m getting the error Null workflowId. Was workflow started? coming in from WorkflowStubImpl . What am I missing here?

The stub created through the newWorkflowStub that takes WorkflowOptions should be used to start a workflow. After the workflow has started it can be used to send signals. To send a signal to an already started workflow use newWorkflowStub that takes the WorkflowID as a parameter:

    WorkflowServiceStubs service = WorkflowServiceStubs.newInstance();
    WorkflowClient client = WorkflowClient.newInstance(service);
    ExpeditionWorkflow workflow = client.newWorkflowStub(ExpeditionWorkflow.class, "welcome-email");
    String[] signal = {"WelcomeEmailPlacement", "Open"};
    workflow.placementReceived(signal);`

Ah my bad - That works now. Thanks so much for the quick help!