Last active
July 29, 2021 18:25
-
-
Save datahai/c264dca5a6a33b1b571c0bdfe6816f29 to your computer and use it in GitHub Desktop.
Trigger Azure Event Hub
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//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