0
votes

I trying to send messages to Azure Stream Analytics using Event Hub. On Azure, I clearly see the Event activity on monitor, but on Stream Analytics Job, I am just not able to test the input data.

I tried to test only a single file and it works my json file is ok. Below the C# code I am using to send the messages:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Configuration;
using System.IO;
using Newtonsoft.Json;
using Microsoft.Azure.EventHubs;

namespace contosorealtimeapplication

{

public class Program
{
    private static Microsoft.Azure.EventHubs.EventHubClient eventHubClient;
    private const string EventHubConnectionString = "Endpoint=sb://***************.servicebus.windows.net/;SharedAccessKeyName=***************;SharedAccessKey=***************";
    private const string EventHubName = "contosorealtime";

    public static void Main(string[] args)
    {
        MainAsync(args).GetAwaiter().GetResult();
    }

    private static async Task MainAsync(string[] args)
    {
        var connectionStringBuilder = new EventHubsConnectionStringBuilder(EventHubConnectionString)
        {
            EntityPath = EventHubName
        };

        eventHubClient = Microsoft.Azure.EventHubs.EventHubClient.CreateFromConnectionString(connectionStringBuilder.ToString());

        await SendMessagesToEventHub();
        await eventHubClient.CloseAsync();

        Console.WriteLine("Press ENTER to exit.");
        Console.ReadLine();
    }

    // Creates an event hub client and sends 100 messages to the event hub.
    private static async Task SendMessagesToEventHub()
    {
        //get JSON file configured on app-setting
        string localFolder = ConfigurationManager.AppSettings["sourcefolder"];
        string[] fileEntries = Directory.GetFiles(localFolder);
        string message = "";
        string serialisedString = "";

        foreach (string filePath in fileEntries)
        {

            try
            {
                serialisedString = JsonConvert.SerializeObject(filePath);
                message = $"Message {serialisedString}";
                Console.WriteLine($"Sending message: {message}");
                await eventHubClient.SendAsync(new Microsoft.Azure.EventHubs.EventData(Encoding.UTF8.GetBytes(serialisedString)));

            }
            catch (Exception exception)
            {
                Console.WriteLine($"{DateTime.Now} > Exception: {exception.Message}");
            }
        }
    }
}

}

I am 100% sure it is missing the partitionkey, but I could not find a way to pass it correctly.

I got this example from this: https://docs.microsoft.com/en-us/azure/event-hubs/event-hubs-dotnet-standard-getstarted-send

Below the Event Hub activity:

Event Hub Activity

Here is input details:

Input Configuration:

Here the message I get on Azure Stream Analytics Job when trying to upload a sample data from input:

Azure error message

Here is the result when I upload data from file (json file):

Result data from file

Does anyone has any idea how to solve it?

PS. Json is working fine.

1
Did you try following theses instructions to troubleshoot? docs.microsoft.com/en-us/azure/stream-analytics/… You can also goto the metrics blade and check the number of input eventsSid Ramadoss

1 Answers

0
votes

I assume you selected input data format as json. In your example code, you are sending string as event hub payload. ASA only supports array of objects or whitespace separated objects. If filename is the only field you are interested in, please send it as a json object - something like{ "fileName": "value"}