0

I'm trying to send data to the event hub from the azure function written on node js. But I'm getting the following error when I send the array of objects without.

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

But when I'm JSON.stringify the data I'm getting error as

Exception: Error: data is required and it must be of type object.

Here the code that I have written

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')

};

How to resolve this issue

Vignesh Chandramohan
  • 1,306
  • 10
  • 15
saran k
  • 307
  • 2
  • 14

1 Answers1

0

We can find the error message in the source of "eventHubSender".

enter image description here

So this error message means the input data is not an object type, we can search for the details of "JSON.stringify()" method by this link and find the return is a string. And according to the first error message you provided

Json input stream should either be an array of objects or line separated objects"

So I think if you want to input an array of objects, you need to change your code from

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

to

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

Update:

Here is my function code for your reference:

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')

};

The code above works fine.

Hury Shen
  • 14,948
  • 1
  • 9
  • 18
  • But, when I use the await client.send(response['data']['data']) I get error from the Azure stream analytics side while processing the data. The error as follows, Diagnostics: Source '' had 1 occurrences of kind 'InputDeserializerError.InvalidData' between processing times '2019-09-24T06:21:53.0694279Z' and '2019-09-24T06:21:53.0694279Z'. Json input stream should either be an array of objects or line separated objects. Found token type: Null – saran k Sep 24 '19 at 06:28
  • can anyone help with this. – saran k Sep 24 '19 at 06:41
  • Hi @sarank, I shared my function code in my answer, the function works fine. Please take a look, it may help your issue. – Hury Shen Sep 24 '19 at 06:53
  • By using the code that you have I can able send data to the event hub, But I'm getting an error from azure stream analytics. The error as follows No events found for 'NSEStockInput'. Diagnostics: Source '' had 1 occurrences of kind 'InputDeserializerError.InvalidData' between processing times '2019-09-24T07:03:22.9492042Z' and '2019-09-24T07:03:22.9492042Z'. Json input stream should either be an array of objects or line separated objects. Found token type: Null – saran k Sep 24 '19 at 07:07