Instantly share code, notes, and snippets.

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