Microsoft Azure Event Grid Hybrid Connection Consumer sample for C#

This contains a C# sample to consume events from Azure Event Grid using an Azure relay hybrid connection listener.


This sample demonstrates how to process event grid events which are delivered to an Azure relay hybrid connection destination.

The above sample uses the Event Grid data plane SDK (Microsoft.Azure.EventGrid) and Azure Relay SDK (Microsoft.Azure.Relay).

Getting Started


  • .NET Core 2.0 or higher
  1. Create an Azure Event Grid topic: You will need to first create an Event Grid topic. The steps are described at Make a note of the topic details.
  2. Create an Azure Relay Hybrid connection. Make a note of the hybrid connection details.
  3. Create an event subscription on the topic(created in step#1) using hybrid connection as a destination (created in step#2) using following azure CLI commands
    # Replace with relay hybrid connection details
    # Replace with topic details
    eventsubscriptionname=<new event subscription name>
    az account set --subscription $relayazuresubscriptionid
    relayid=$(az resource show --name $relayname --resource-group $relayrg --resource-type Microsoft.Relay/namespaces --query id --output tsv)
    az account set --subscription $topicazuresubscriptionid
    az eventgrid event-subscription create \
      --topic-name $topicname \
      -g $topicresourcegroup \
      --name $eventsubscriptionname \
      --endpoint-type hybridconnection \
      --endpoint $hybridconnectionid


  • Visual Studio 2017 Version 15.5 or later.

Clone this repository onto your local machine. Compile the samples inside Visual Studio, the required Microsoft Azure Event Grid SDK components will automatically be downloaded from

Running the Sample

  1. The following are the steps to run the HybridConnectionConsumer sample and see events received on hybrid connection listener:

    a. Load HybridConnectionConsumer project in Visual Studio.

    b. In Program.cs, replace the and with the relay connection string and hybrid connection name that you created in pre-requisites.

    c. Run this application from Visual Studio to listen for Event Grid Events.

  2. Use Event Grid publisher sample( to publisher events to the topic that you created in pre-requisites.

  3. Verify that you received the events in the HybridConnectionConsumer console.


(Any additional resources or related projects)