You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

使用Cadence HTTP API传递复杂对象作为工作流输入时遇到解码及字节数组长度异常问题求助

Cadence HTTP API传递复杂对象作为工作流输入时遇到解码及字节数组长度异常问题求助

大家好,我在使用Cadence HTTP API启动工作流的过程中遇到了两个关联的问题,折腾了好久没解决,想请教下社区的大佬们帮忙分析下问题出在哪。

首先先说明我的工作流定义和对应的输入结构体:

func MyWorkflow(ctx cadence.Context, input MyInput) error {
    // 这里是工作流的业务逻辑
}

type MyInput struct {
    SomeString string
    SomeInteger int
}

按照Cadence HTTP API官方文档的说明,我构造了如下的POST请求Payload来启动工作流:

{
    "domain": "sample-domain",
    "workflow_id": "sample-workflow-id",
    "execution_start_to_close_timeout": "61s",
    "task_start_to_close_timeout": "60s",
    "workflow_type": {
        "name": "sample-workflow-type"
    },
    "task_list": {
        "name": "sample-task-list"
    },
    "identity": "client-name-visible-in-history",
    "request_id": "8049B932-6C2F-415A-9BB2-241DCF4CFC9C",
    "input": {
        "data": "IkN1cmwhIg=="
    }
}

但发送请求后,工作流立即失败了,返回的错误信息如下:

{
    "reason": "cadenceInternal:Generic",
    "details": "unable to decode the workflow function input bytes with error: unable to decode argument: 0, *MyInput, with json error: EOF, function name: sample-workflow-type"
}

我自己分析了下,应该是Cadence无法将传入的字节数据解码成MyInput类型导致的错误。于是我尝试修改工作流的输入参数类型,改成了[]byte:

func MyWorkflow(ctx cadence.Context, input []byte) error {
    // 打印输入字节数组的长度,结果始终是0
    logger.Info("length of input", zap.Int("length", len(input)))
    return nil
}

可修改后又遇到了新问题:不管我在请求Payload里传入什么input.data值,工作流里打印出来的字节数组长度始终是0。

实在搞不懂哪里出问题了,麻烦各位帮忙看看我到底哪里操作错了?万分感谢!

备注:内容来源于stack exchange,提问作者Ajax9900

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.04.21 09:48:10