Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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