Slickflow.net Open Source Workflow engine Basic Introduction (10)--mail poll asynchronous send module integration

Source: Internet
Author: User
Tags mailmessage server port

Preface: When the task data is generated, in order to get the task user to get the subject and content of the task in time, it is necessary to send the notification class message, while the e-mail and the SMS notification of the mobile phone is the more common message sending. This article is for the implementation of e-mail asynchronous sending module to do the example description.

1. Location of notifications sent by mail

Usually when the task data is generated, it is necessary to send an e-mail notification, the content of the message includes the Body and page address information, the task manager after receiving the mail, will promptly log on to the system for task processing, the benefits of sending e-mail notification is convenient and timely.

But e-mail is not a feature that all business customers need, it is not easy to tightly coupled in the engine flow, that is, the generation of task data binding. Therefore, when the system is built, the module integration mode is chosen, which is completely detached from the engine and becomes a separate module implementation. In order to familiarize users with the benefits of this development approach, the modular construction of complex systems is deliberately structured as follows:

2. Processing of polling messages sent

The data source for the mail notification is the Task table (wftasks), which handles the timely generation of backlog data by polling, and then sends the corresponding mail notification to each of the tasks to be done. The benefit of this approach is to avoid tight coupling with the engine's internal functions, allowing the engine to focus more on flow parsing and function expansion.

        <summary>        ///To-DOS email notification///</summary> public void Sendtaskemail (ilist< Processentity> processlist,            ilist<useremailentity> userlist)        {            var wfservice = new WorkflowService ();            var taskList = Wfservice.gettasklistemailunsent ();            if (taskList! = null && tasklist.count () > 0)            {                foreach (var task in taskList)                {                    Func<ta Skviewentity, Ilist<processentity>, Ilist<useremailentity>, task> func = Sendemailasync;                    Backgroundtaskrunner.fireandforgettaskasync (func, Task, processlist, userlist);}}}        

  

3. Asynchronous Mail Sending method

When the message is sent, it is necessary to connect to the SMTP server port and authenticate the mail user, so it is a time consuming and resource-intensive task sequence, which can avoid the performance impact on the main procedure processing by using the asynchronous method in the concrete implementation, and the asynchronous interface is as follows:

            Mail message            mailmessage mail = new MailMessage ();            Mail. Subject = Title;            Mail. BODY = body;            Mail. from = new MailAddress (sendemailaccount);      Sender Address            Mail. subjectencoding = Utf8encoding.utf8;            Mail. bodyencoding = Utf8encoding.utf8;            Mail. priority = Mailpriority.normal;            Mail. Isbodyhtml = true;            Mail. To.add (receiveemail);            Smtp. sendcompleted + = Sendcompletedcallback;            Await SMTP. Sendmailasync (mail);//Send mail

  

4. Hangfire Scheduled Tasks

The message polling time interval is every minute, taking into account the openness and compatibility of the platform, and does not use WINDOWSSERIVCE to achieve, but the use of Hangfire automatic job framework to integrate, the benefits of cross-platform applications directly to use. The code is exactly the same in. NET core products.

        <summary>        //E-mail poll send        ///</summary> private void addjoboftaskemailsending ()        {            var wfservice = new WorkflowService ();            var processlist = Wfservice.getprocesslistsimple ();            var msgservice = new Messageservice ();            var userlist = Msgservice.getuserlist ();            Recurringjob.addorupdate<messageservice> (s = S.sendtaskemail (Processlist, userlist),                Cron.Minutely );        }

5. Summary

The integration of the e-mail module is implemented as a functional requirement of the enterprise customer, which, from the technical framework, uses the polling mode independent function encapsulation, which is more suitable to extend the engine components from the outside, the benefit is to ensure the stability of the engine, but also as an option to let users freely choose.

Slickflow.net Open Source Workflow engine Basic Introduction (10)--mail poll asynchronous send module integration

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.