Skip to content

Instantly share code, notes, and snippets.

@PradeepLoganathan
Created December 30, 2018 10:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save PradeepLoganathan/e98217ff5756b226a30f7d22e3a03ef4 to your computer and use it in GitHub Desktop.
Save PradeepLoganathan/e98217ff5756b226a30f7d22e3a03ef4 to your computer and use it in GitHub Desktop.
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