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:
Here is input details:
Here the message I get on Azure Stream Analytics Job when trying to upload a sample data from input:
Here is the result when I upload data from file (json file):
Does anyone has any idea how to solve it?
PS. Json is working fine.