Encoding Data for grpc responde activity

I’m building a demo to pitch temporal to my company, this is from nodeJS, I created a grpc client and I’m able to receive tasks and process them, but when sending the reply I can’t figure out the correct encoding.

Worker complains
payload item 0: metadata is not set (type: wrapError, retryable: true): metadata is not set

And when I see the temporalUI the values look to be base64 encoded and not the json object I see when a go worker answers.

the UI shows:
ActivityTaskCompleted:

[
  "e0Vycjp1bGlubGFlOnRz.."
]

this is what I have

    return new Promise((resolve, reject) => {
        const payload = new Payload()

        const activityReturnString = JSON.stringify(activityReturn)
        const s = Buffer.from(activityReturnString).toString()

        var result = [];

        for (var i = 0; i < s.length; i += 2) {
            // result.push(parseInt(s.substring(i, i + 2), 16));
            result.push(s.charCodeAt(i))
        }

        payload.setData(Uint8Array.from(result))


        const payloads = new Payloads()
        payloads.addPayloads(payload)

        const request = new RespondActivityTaskCompletedRequest()
        request.setResult(payloads)
        request.setTaskToken(activityTaskToken)
        request.setIdentity('IdentityString')

        this.client.respondActivityTaskCompleted(request, (err) => {
            if (err) {
                reject(err)
                return
            }

            resolve(true)
        })
    })

I have tried encoding in base64, adding a metadata / data, but can’t return data.

ps. i’m aware there’s a new node SDK but I have tried (with no luck) to make it work, and I need to present this week and this is the only part that’s missing.

thanks in advance

Jose

Ok, I was able to figure out the encoding, now I can see what i’m sending on the UI as a string, now the error I’m getting is:

payload item 0: type: *sdk.WorkflowCoreReturn: type doesn't implement proto.Message (type: wrapError, retryable: true)

where WorkflowCoreReturn is the struct i’m expecting. I’m sending the same from javascript as JSON

And I also realized that message from my go worker sets a binary checksum and not JSON like I thought.

any thoughts?

Here is Java’s implementation of DataConverter for reference.

Thank you!, this is what I used and I’m sending a JSON string as result, but can’t receive it on the go worker

var result string
activityFuture := workflow.ExecuteActivity(ctx, a.Type, workflowInput)
err := activityFuture.Get(ctx, &result)

*string: type doesn't implement proto.Message

It looks like metadata is not set correctly if the Go DataConverter treats the payload as protobuf.

That was exactly the problem, you rock!!!

thanks

1 Like