0

如何通过外部客户端获取命名空间或任务队列(不想提供工作流 id)内所有工作流的搜索属性?我正在使用 Java SDK。

下面是工作流和添加搜索属性的示例代码。在代码中,WorkflowExecution 用于获取搜索属性,但工作流 id 必须作为输入参数。我正在寻找一种解决方案来获取命名空间的所有工作流和搜索属性,而无需提供工作流 ID。

WorkflowServiceStubs 服务 = WorkflowServiceStubs.newInstance();

WorkflowClientOptions clientOptios =
    WorkflowClientOptions.newBuilder().setNamespace("samples-namespace").build();

WorkflowClient client = WorkflowClient.newInstance(service, clientOptios);

WorkerFactory factory = WorkerFactory.newInstance(client);

Worker worker = factory.newWorker(TASK_QUEUE);
worker.registerWorkflowImplementationTypes(MyClass.MyWorkflowImpl.class);

worker.registerActivitiesImplementations(new MyClass.MyActivitiesImpl());

factory.start();

String workflowID = UUID.randomUUID().toString();

WorkflowOptions workflowOptions =
    WorkflowOptions.newBuilder()
        .setTaskQueue(TASK_QUEUE)
        .setWorkflowId(workflowID)
        .setSearchAttributes(generateSearchAttributes())
        .build();

HelloSearchAttributes.GreetingWorkflow workflow =
    client.newWorkflowStub(MyClass.MyWorkflowImpl.class, workflowOptions);

WorkflowExecution 执行 = WorkflowExecution.newBuilder().setWorkflowId(workflowID).build();

DescribeWorkflowExecutionRequest 请求 = DescribeWorkflowExecutionRequest.newBuilder() .setNamespace(client.getOptions().getNamespace()) .setExecution(execution) .build();

    DescribeWorkflowExecutionResponse resp =
        service.blockingStub().describeWorkflowExecution(request);

SearchAttributes searchAttributes = resp.getWorkflowExecutionInfo().getSearchAttributes();

4

1 回答 1

0

您想使用 ListWorkflowExecutions 操作来列出使用搜索属性的工作流。以下对我有用:

    WorkflowServiceStubs service = WorkflowServiceStubs.newInstance();

    ListWorkflowExecutionsResponse listResult =
        service
            .blockingStub()
            .listWorkflowExecutions(
                ListWorkflowExecutionsRequest.newBuilder()
                    .setNamespace("default")
                    .setQuery("CustomIntField=1")
                    .build());

于 2020-11-20T23:23:57.117 回答