PartitionKey in Stream Analytics and Event Hubs

Karl Gardner 85 Reputation points
2024-07-29T01:01:07.6533333+00:00

Hello,

I'm trying to learn more about event hub partitions. I'm running a simple .Net program to send 20 events to an Event Hub with 3 partitions. I then query the events with the input preview in stream analytics. The simple .Net program is following:

using Azure.Messaging.EventHubs;
using Azure.Messaging.EventHubs.Producer;

var connectionString = "Endpoint=sb://eventhubsnamespace321.servicebus.windows.net/;SharedAccessKeyName=RootManageSharedAccessKey;SharedAccessKey=";
var eventHubName = "";
var producer = new EventHubProducerClient(connectionString, eventHubName);

try
{
    var eventBatch = new List<EventData>();
    for (var counter = 0; counter < 20; ++counter)
    {
        var eventBody = new BinaryData($$"""{"numCars": {{new Random().Next(50)}}, "highway": {{counter%3}}}""");
        var eventData = new EventData(eventBody);
        eventBatch.Add(eventData);
    }
    await producer.SendAsync(eventBatch, new SendEventOptions() {PartitionKey = "highway"});
}
catch(Exception ex)
{
    Console.WriteLine($"exception occured {ex}");
}

As you can see the Event Hub name is "highway2. I'm sending two columns (in Json) of "numCars" and "highway". The "highway" is either 0, 1, or 2 for the three different partitions. I set the PartitionKey in the SendEventOptions. In Event Hubs I have 3 partitions:

User's image

Now, I connected the Stream analytics job to the Event Hub and only seeing one partition for the PartitionId:

User's image

Shouldn't the PartitionId be different for each highway since the PartitionKey is set to highway?

Thanks!

Azure Event Hubs
Azure Event Hubs
An Azure real-time data ingestion service.
605 questions
Azure Stream Analytics
Azure Stream Analytics
An Azure real-time analytics service designed for mission-critical workloads.
345 questions
{count} votes