0

While creating event grid subscription and using eventhub as endpoint there is no way of specifying the partitionID to which all messages should be sent. Is it possible via Webhook? I found that it is possible via Rest API see here. It uses the following url. https://{serviceNamespace}.servicebus.windows.net/{eventHubPath}/publishers/{deviceId}/messages. I am trying to ingest those events to event hub. but what I want is those events to be ingested into a particular partition in event hub. Is it possible via Event subscription (probably by passing deviceid as parameter)? Or Is there any other way to configure event subscription to route those events to a particular partitionID in event hub.

I am using nodejs for writing serverless code and I am creating event grid subscription via azure portal.

P.S. I confirmed from Azure Support team this feature is not supported currently and one has to use Azure function to direct events to a particular partitionID.

himanshu219
  • 654
  • 7
  • 22

1 Answers1

1

the minimum integration is to use an EventGridTrigger function with an output binding to the EventHub, see the following implementation:

#r "Newtonsoft.Json"
#r "Microsoft.ServiceBus"

using System;
using System.Text;
using Newtonsoft.Json;
using Microsoft.ServiceBus.Messaging;

public static void Run(string eventGridEvent, ICollector<EventData> collector, TraceWriter log)
{
    log.Info(eventGridEvent);

    EventData ed = new EventData(new MemoryStream(Encoding.UTF8.GetBytes(eventGridEvent))) { PartitionKey="myPartition"};
    collector.Add(ed);
}

and the function.json file:

    {
      "bindings": [
      {
        "type": "eventGridTrigger",
        "name": "eventGridEvent",
        "direction": "in"
    },
    {
        "type": "eventHub",
        "name": "collector",
        "connection": "myEventHubConnectionString",
        "path": "myEventHubName",
        "direction": "out"
    }
  ],
  "disabled": false
 }

Also, you can use an HttpTrigger function, but the function needs to handle a validation message.

Roman Kiss
  • 7,925
  • 1
  • 8
  • 21