OnStart

Since our microservice is an example, we use the OnStart message to trigger the sending of an email. In the real world, you would want to do this based upon an event or action occurrence. I will leave it up to you, the reader and developer, as you know what works best with your environment. Regardless of your approach, it's an easy enhancement to make:

public new bool OnStart([CanBeNull] HostControl host)
{
Start(host);
Subscribe();
EmailSendRequest m = new EmailSendRequest();
m.Subject = "Test";
m.To = "[email protected]";
m.From = "[email protected]";
m.Body = "This is a test of the email microservice system";
SendEmail(m);
return true;
}

In the preceding code, we call the base Start method, subscribe to our message system, and send an email. Please note, before I get any nasty emails, that the preceding email addresses are completely, totally, and irrevocably incorrect. Please don't paste the code and tell me the email isn't working. You will know who you are sending an email To and what you want the From to look like. These few lines of code are where you can make the greatest positive impact to your microservice.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset