Skip to content

Instantly share code, notes, and snippets.

@datahai
Last active July 29, 2021 18:25
Show Gist options
  • Save datahai/c264dca5a6a33b1b571c0bdfe6816f29 to your computer and use it in GitHub Desktop.
Save datahai/c264dca5a6a33b1b571c0bdfe6816f29 to your computer and use it in GitHub Desktop.
Trigger Azure Event Hub
//create the message structure
WebVisitMessage webvisitmessage = new WebVisitMessage
{
SessionID = SessionID,
EventType = "visitwebsite",
EventDateTime = dateincrement,
URL = URL,
Device = device
};
//serialize the JSON
string outputwebvisitmessage = JsonConvert.SerializeObject(webvisitmessage);
//send to the Azure Event Hub
await using (var producerClient = new EventHubProducerClient(connectionString, eventHubNameWebVisits))
{
using EventDataBatch eventBatch = await producerClient.CreateBatchAsync();
eventBatch.TryAdd(new EventData(Encoding.UTF8.GetBytes(outputwebvisitmessage)));
await producerClient.SendAsync(eventBatch);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment