Created
December 30, 2018 10:10
-
-
Save PradeepLoganathan/e98217ff5756b226a30f7d22e3a03ef4 to your computer and use it in GitHub Desktop.
Azure Event grid - Domain Event
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
public class CandidateEvents : ICandidateEvents | |
{ | |
string topicEndpoint; | |
string topicKey ; | |
string topicHostname ; | |
TopicCredentials topicCredentials ; | |
EventGridClient client; | |
public CandidateEvents() | |
{ | |
topicEndpoint = "https://yourtopicendpoint/api/events"; | |
topicKey = "yourtopickey"; | |
topicHostname = new Uri(topicEndpoint).Host; | |
topicCredentials = new TopicCredentials(topicKey); | |
client = new EventGridClient(topicCredentials); | |
} | |
public async Task CandidateCreatedEvent(Candidate candidate) | |
{ | |
List<EventGridEvent> eventsList = new List<EventGridEvent>(); | |
EventGridEvent ev = new EventGridEvent() | |
{ | |
Id = new Guid().ToString(), | |
Data = candidate, | |
EventTime = DateTime.Now, | |
EventType = "Somevent.CandidateCreated", | |
DataVersion = "1.0", | |
Subject = candidate.CandidateName.Identifier | |
}; | |
eventsList.Add(ev); | |
await client.PublishEventsAsync(topicHostname, eventsList ); | |
} | |
public Task CandidateUpdatedEvent(Candidate candidate) | |
{ | |
List<EventGridEvent> eventsList = new List<EventGridEvent>(); | |
EventGridEvent ev = new EventGridEvent() | |
{ | |
Id = new Guid().ToString(), | |
Data = candidate, | |
EventTime = DateTime.Now, | |
EventType = "Somevent.CandidateUpdated", | |
DataVersion = "1.0", | |
Subject = candidate.CandidateName.Identifier | |
}; | |
eventsList.Add(ev); | |
await client.PublishEventsAsync(topicHostname, eventsList ); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment