Skip to content

Integration EventHubs Extension

Aryeh Citron edited this page Apr 21, 2026 · 11 revisions

Integration: Azure Event Hubs Extension

Track Azure Event Hubs operations in your test diagrams using the TestTrackingDiagrams.Extensions.EventHubs NuGet package. This extension wraps EventHubProducerClient and EventHubConsumerClient to intercept send/receive operations.

Installation

dotnet add package TestTrackingDiagrams.Extensions.EventHubs

Quick Start

using Azure.Messaging.EventHubs.Producer;
using TestTrackingDiagrams.Extensions.EventHubs;

var options = new EventHubsTrackingOptions
{
    ServiceName = "EventHubs",
    CallingServiceName = "OrdersApi",
    Verbosity = EventHubsTrackingVerbosity.Detailed,
    CurrentTestInfoFetcher = () => (TestContext.CurrentTestName, TestContext.CurrentTestId)
};

var innerClient = new EventHubProducerClient(connectionString, eventHubName);
var producer = new TrackingEventHubProducerClient(innerClient, options);

await producer.SendAsync(new[] { new EventData("order-created") });

How It Works

Azure Event Hubs uses AMQP internally and does not expose an HTTP DelegatingHandler pipeline. Like the Service Bus and Pub/Sub extensions, this extension uses the wrapper/decorator pattern — standalone classes that wrap the SDK client and intercept method calls.

The EventHubsTracker (central logging helper) handles all request/response logging with RequestResponseMetaType.Event for async messaging notation in PlantUML diagrams.

Supported Operations

Operation Enum Value Source
Send EventHubsOperation.Send Single event via SendAsync
SendBatch EventHubsOperation.SendBatch Multiple events via SendAsync
CreateBatch EventHubsOperation.CreateBatch CreateBatchAsync
ReadEvents EventHubsOperation.ReadEvents ReadEventsAsync
ReadEventsFromPartition EventHubsOperation.ReadEventsFromPartition ReadEventsFromPartitionAsync
GetPartitionIds EventHubsOperation.GetPartitionIds GetPartitionIdsAsync
GetEventHubProperties EventHubsOperation.GetEventHubProperties GetEventHubPropertiesAsync
GetPartitionProperties EventHubsOperation.GetPartitionProperties GetPartitionPropertiesAsync
StartProcessing EventHubsOperation.StartProcessing StartProcessingAsync
StopProcessing EventHubsOperation.StopProcessing StopProcessingAsync
ProcessEvent EventHubsOperation.ProcessEvent Event handler callback

Wrapper Classes

TrackingEventHubProducerClient

Wraps EventHubProducerClient:

  • SendAsync(IEnumerable<EventData>) — tracks single/batch sends
  • SendAsync(IEnumerable<EventData>, SendEventOptions) — tracks with partition key
  • SendAsync(EventDataBatch) — tracks batch sends
  • CreateBatchAsync() — delegates without tracking
  • CloseAsync() — delegates without tracking
  • Inner property for direct access to the underlying client

TrackingEventHubConsumerClient

Wraps EventHubConsumerClient:

  • ReadEventsAsync() — logs start, yields events, logs completion
  • ReadEventsFromPartitionAsync() — logs with partition ID
  • GetPartitionIdsAsync() — delegates directly
  • CloseAsync() — delegates without tracking
  • Inner property for direct access

Verbosity Levels

EventHubsTrackingVerbosity.Summarised

  • Label: Operation name (e.g. Send)
  • Content: Omitted
  • URI: eventhubs:///hub-name

EventHubsTrackingVerbosity.Detailed

  • Label: Contextual (e.g. Send → telemetry, Read ← telemetry[2])
  • Content: Event body included
  • URI: eventhubs:///hub-name/partition-id when applicable

EventHubsTrackingVerbosity.Raw

  • Label: Full details (e.g. Send hub=telemetry partition=1 count=3)
  • Content: Full event data
  • URI: eventhubs:///hub-name/partition-id

Configuration Options

new EventHubsTrackingOptions
{
    ServiceName = "EventHubs",
    CallingServiceName = "OrdersApi",
    Verbosity = EventHubsTrackingVerbosity.Detailed,
    CurrentTestInfoFetcher = () => (testName, testId),
}

ITrackingComponent

EventHubsTracker implements ITrackingComponent and auto-registers with TrackingComponentRegistry. This provides:

  • ComponentName: "EventHubsTracker ({ServiceName})"
  • WasInvoked: true after first operation
  • InvocationCount: Total operations tracked

URI Scheme

eventhubs:///telemetry          (hub-level operations)
eventhubs:///telemetry/2        (partition-specific operations)

See Also

Home


Demo


Getting Started

Common Tasks

Integration Guides

Extensions

Configuration

Features

Reference

Clone this wiki locally