Azure function eventHub typescript trigger is converting message to UTF-8 string and cause data missing

2025-01-27T17:58:05.19+00:00

I am using Event Hub to store protobuf serialized message,
Everything is fine, If I am using SDK library (python or JS library) to access Event hub.

But when I use Azure function Eventhub trigger (when there is new message on event hub, trigger a function app to do the processing)

the message passed into the handler is actually a UTF-8 converted "string", and it contains fallback characters.
Because there are missing information, There is no way to convert it back to original binary (to do further protobuf parsing).

Please let me know if there are any configurations that I can make the "message" param of handler to be binary (like Buffer).

Thanks.

app.eventHub(`eventhub_trigger`, {
  eventHubName: 'notification',
  connection: 'CONN_STR',
  cardinality: 'one',
  handler: async (message: unknown, context: InvocationContext): Promise<void> => {
    const value = message as string
    console.log("------------------------------")
    console.log(typeof message)
    console.log(value.length)
    console.log(Buffer.from(value, "latin1").toString("base64"))
    console.log(Array.from(value, char => char.charCodeAt(0)))
    // await processNotification(value)
  }
})

未受監視
未受監視
Microsoft 未監視的標記。
30 個問題
0 則留言 沒有留言
{count} 則投票

您的回答

問題作者可以將答案標示為「已接受的回答」,有助使用者知道此回答解決了作者的問題。