Azure functions 如何从node js中的azure函数向事件中心发送批处理数据?

Azure functions 如何从node js中的azure函数向事件中心发送批处理数据?,azure-functions,azure-eventhub,azure-functions-runtime,Azure Functions,Azure Eventhub,Azure Functions Runtime,我正在尝试从节点js上编写的azure函数向事件中心发送数据。 但是,当我发送对象数组而不发送时,会出现以下错误 No events found for 'NSEStockInput'. Start time: Monday, September 23, 2019, 6:56:00 PM End time: Monday, September 23, 2019, 6:59:00 PM Last time arrival: Monday, September 23, 2019, 6:59:08 P

我正在尝试从节点js上编写的azure函数向事件中心发送数据。 但是,当我发送对象数组而不发送时,会出现以下错误

No events found for 'NSEStockInput'.
Start time: Monday, September 23, 2019, 6:56:00 PM
End time: Monday, September 23, 2019, 6:59:00 PM
Last time arrival: Monday, September 23, 2019, 6:59:08 PM
Diagnostics: Source '<unknown_location>' had 1 occurrences of kind 'InputDeserializerError.InvalidData' between processing times '2019-09-23T13:29:10.4592579Z' and '2019-09-23T13:29:10.4592579Z'. Json input stream should either be an array of objects or line separated objects. Found token type: Null
这里是我写的代码

module.exports = async function (context, myTimer) {
    const {  EventHubClient, EventData, EventPosition, OnMessage, OnError, MessagingError } = require("@azure/event-hubs");
    const connectionString = connectionString
    var axios = require('axios')
    context.log('ssss')
    const client = EventHubClient.createFromConnectionString(connectionString);
    context.log('sssaaa')
    var response = await axios.get('https://nseindia.com/live_market/dynaContent/live_watch/stock_watch/nifty500StockWatch.json')
    await client.send(JSON.stringify(response['data']['data']))

    context.log('message sent')

};

如何解决此问题

我们可以在“eventHubSender”中找到错误消息

因此,此错误消息意味着输入数据不是对象类型,我们可以通过链接搜索“JSON.stringify()”方法的详细信息,并找到返回的是字符串。根据您提供的第一条错误消息

Json input stream should either be an array of objects or line separated objects"
所以我认为如果你想输入一个对象数组,你需要修改你的代码

await client.send(JSON.stringify(response['data']['data']))

更新:

以下是我的功能代码供您参考:

module.exports = async function (context, myTimer) {
    const {  EventHubClient, EventData, EventPosition, OnMessage, OnError, MessagingError } = require("@azure/event-hubs");
    const connectionString = "Endpoint=************"
    const eventHubsName = "hurytestentity"
    var axios = require('axios')

    const client = EventHubClient.createFromConnectionString(connectionString, eventHubsName);
    context.log('sssaaa')
    var response = await axios.get('https://nseindia.com/live_market/dynaContent/live_watch/stock_watch/nifty500StockWatch.json')
    await client.send(response['data']['data'])
    context.log('message sent')

};

上面的代码工作正常。

但是,当我使用wait client.send(response['data']['data'])时,在处理数据时,Azure stream analytics端出现错误。错误如下,诊断:源“”在处理时间“2019-09-24T06:21:53.0694279Z”和“2019-09-24T06:21:53.0694279Z”之间出现了1次“InputDeserializerError.InvalidData”类型的错误。Json输入流应该是对象数组或行分隔对象。找到了令牌类型:nullcananythis.Hi@sarank,我在回答中分享了我的函数代码,该函数运行良好。请看一看,这可能有助于解决您的问题。通过使用您拥有的代码,我可以将数据发送到事件中心,但我从azure stream analytics收到一个错误。错误如下:未找到“NSEStockInput”的事件。诊断:源“”在处理时间“2019-09-24T07:03:22.9492042Z”和“2019-09-24T07:03:22.9492042Z”之间出现了1次“InputDeserializerError.InvalidData”类型的事件。Json输入流应该是对象数组或行分隔对象。找到标记类型:Null
await client.send(response['data']['data'])
module.exports = async function (context, myTimer) {
    const {  EventHubClient, EventData, EventPosition, OnMessage, OnError, MessagingError } = require("@azure/event-hubs");
    const connectionString = "Endpoint=************"
    const eventHubsName = "hurytestentity"
    var axios = require('axios')

    const client = EventHubClient.createFromConnectionString(connectionString, eventHubsName);
    context.log('sssaaa')
    var response = await axios.get('https://nseindia.com/live_market/dynaContent/live_watch/stock_watch/nifty500StockWatch.json')
    await client.send(response['data']['data'])
    context.log('message sent')

};