You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

能否在Azure门户将Event Hub事件发送至Event Grid?配置方向存疑

Fixing Event Hub → Event Grid Event Flow Issues

Hey Josh, let's break down what's going wrong and get your events flowing in the right direction. It sounds like you had the subscription backwards (Event Hub listening to Event Grid instead of the other way around), and now you're seeing Event Hub message volume grow but no events making it to Event Grid or your Grid-monitoring Function. Let's fix this step by step.

First: Clarify the Right Architecture

You want Event Hub to send events to Event Grid—but there are two common scenarios here, so let's confirm which one you need:

  1. System Events from Event Hub: Things like "capture completed" or namespace resource changes (only supported on Premium/Dedicated Event Hub namespaces).
  2. Business Messages from Event Hub: Every message sent to your Event Hub gets forwarded to Event Grid (requires a middle layer like Azure Function, since Event Hub doesn't natively push individual messages to Event Grid).

Step 1: Clean Up the Wrong Subscription

First, delete that backwards subscription to avoid confusion:

  • Go to your Event Hub resource in the Azure Portal.
  • Navigate to Events > Event Grid (or wherever you created the subscription pointing Event Grid to Event Hub).
  • Find the incorrect subscription and delete it.

Step 2: Choose Your Solution Based on Your Scenario

Scenario 1: Forward Event Hub System Events to Event Grid

This works if you need alerts for system-level actions (like when a capture job finishes):

  1. Verify your namespace tier: Make sure your Event Hub namespace is Premium or Dedicated—Basic tier doesn't support Event Grid integration.
  2. Create the correct Event Grid subscription:
    • Go to your Event Hub namespace (not the individual Event Hub) in the Portal.
    • Left menu → Events > Event Grid.
    • Click + Event Subscription.
    • Name your subscription, keep the default Event Grid schema.
    • Under Event Types, select the system events you care about (e.g., Microsoft.EventHub.CaptureFileCreated).
    • For the Endpoint Type, choose your target (e.g., Azure Function) and select your Grid-monitoring Function as the endpoint.
  3. Test it: Trigger a system event (like running a capture job) and check if your Function receives it.

Scenario 2: Forward Every Event Hub Business Message to Event Grid

If you need individual messages from Event Hub to land in Event Grid, you'll need an Azure Function as a middleman:

  1. Create an Event Grid Topic (if you don't have one):
    • In the Portal, search for "Event Grid Topic" and create a new one. Note its endpoint and access key—you'll need these later.
  2. Create an Event Hub-triggered Azure Function:
    • Create a new Function App, then add a Function with the Event Hub Trigger template.
    • Configure it to listen to your target Event Hub (use the Event Hub connection string).
  3. Add code to forward messages to Event Grid:
    • Use the Event Grid SDK to publish each received message to your Event Grid Topic. Here's a quick C# example:
      using Azure.Messaging.EventGrid;
      using Microsoft.Azure.WebJobs;
      using Microsoft.Extensions.Logging;
      
      public static async Task Run([EventHubTrigger("your-event-hub-name", Connection = "EventHubConnectionString")] string[] messages, ILogger log)
      {
          // Replace with your Event Grid Topic endpoint and key
          var topicEndpoint = "https://your-topic-name.region.eventgrid.azure.net/api/events";
          var topicKey = "your-topic-access-key";
          
          var eventGridClient = new EventGridPublisherClient(new Uri(topicEndpoint), new AzureKeyCredential(topicKey));
          
          foreach (var message in messages)
          {
              var eventGridEvent = new EventGridEvent(
                  subject: "event-hub-business-message",
                  eventType: "com.yourorg.eventhub.message.received",
                  dataVersion: "1.0",
                  data: message);
              
              await eventGridClient.SendEventAsync(eventGridEvent);
              log.LogInformation($"Forwarded message to Event Grid: {message}");
          }
      }
      
    • Add your Event Hub connection string, Event Grid Topic endpoint, and key to the Function App's Configuration (Application Settings).
  4. Link Event Grid Topic to Your Monitoring Function:
    • Go to your Event Grid Topic in the Portal.
    • Click + Event Subscription.
    • Set the endpoint type to Azure Function and select your Grid-monitoring Function.
  5. Test it: Trigger your original Function that sends messages to Event Hub. Check the Event Hub-triggered Function's logs to confirm it's forwarding messages, then check your monitoring Function to see if it receives them.

Troubleshooting Checks

If things still aren't working:

  • Check permissions: Ensure your Event Hub-triggered Function has Listen access to the Event Hub, and has Send access to the Event Grid Topic.
  • Check metrics: In the Event Grid Topic or Subscription, look at metrics like Publish Success Events to see if events are being received.
  • Check Function logs: Use the Azure Portal's Monitor > Logs for your Functions to look for errors (e.g., authentication issues, missing configuration values).

内容的提问来源于stack exchange,提问作者Josh

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.19 08:05:41