Objective
The first two ". NET core Practice series of SMS Service-SIKIRO.SMS.API service implementation", ". NET core Practice series of SMS Service-API SDK Implementation and testing" respectively, explained the API provides services and SDK invoke API implementation.
This article will continue to explain the service implementation of Sikiro.SMS.Bus, this implementation is based on the opening of the architecture design of the own scheduling task service, in the last article will be optimized for the schema, abandoned the scheduling task service using MQ instead.
Source Address: Github.com/skychensky/sikiro.sms
Function Flow Description
As shown, consumers subscribe to the consumer message, through the factory class to create a corresponding SMS carrier class, by calling the Send method to the SMS Operator service request, the results of the response to the persistent data status updates. If you encounter an exception halfway, roll back the data state and wait for the next scheduled task to be dispatched.
The following is a code example of Mainservice:
Public classMainservice:imicroservice {Private ReadOnlyIBus _bus; Private ReadOnlySMSService _smsservice; PublicMainservice (IBus bus, SMSService smsservice) {_bus=bus; _smsservice=SMSService; } Public voidStart () {Console.WriteLine ("I started"); _bus. Subscribe<SmsQueueModel> ("", msg = { Try{_smsservice.send (msg. Mapto<smsqueuemodel, smsmodel>()); } Catch(Exception e) {_smsservice.rollback (); E.writetofile (); } }); } Public voidStop () {Configserver.container?. Dispose (); Console.WriteLine ("I stopped"); } }
The following is a code example of SMSService:
Public voidSend (Smsmodel item) {Sms=item; varissuccess = _smsfactory.create (item. Type). Sendsms (item. Mobiles, item. Content, _configuration["Sms:signname"]); if(issuccess) Success (item. ID); ElseFail (item. ID); } Public voidRollBack () {RollBack (sms.id); } Public voidRollBack (stringID) {_mongoproxy.update<SmsModel> (A = a.ID = =ID, a=NewSmsmodel {Status =smsenums.smsstatus. Pending}); } Private voidSuccess (stringID) {_mongoproxy.update<SmsModel> (A = a.ID = =ID, a=NewSmsmodel {Status =smsenums.smsstatus. Success}); } Private voidFail (stringID) {_mongoproxy.update<SmsModel> (A = a.ID = =ID, a=NewSmsmodel {Status =smsenums.smsstatus. Failure}); }
Component Selection Hosting Framework
A friend who has developed Windows services on the. Net framework should be familiar with topshelf.
The advantages mainly reflect the following three points:
- Console-based applications
- Easy Commissioning
- Easy installation Deployment
Many people think that the emergence of the core, cross-platform plus command line advantages, can be easily deployed in the Linux daemon. Do you need a hosting framework?
However, not all companies use Linux systems as servers, just like our company. Now that you're using Windows Server, you should deploy him as a Windows service to make it easy to manage, and not wait for the core version of Topshelf. So I chose another hosting framework: PeterKottas.DotNetCore.WindowsService
PeterKottas.DotNetCore.WindowsService
Source Address: Github.com/peterkottas/dotnetcore.windowsservice
Although Topshelf is not as powerful as it is, it is generally satisfied with the general requirements and is used in a similar way to topshelf. The following are examples of use:
classProgram {Static voidMain (string[] args) {Servicerunner<mainservice>. Run (config ={config. Setserviceinfo (); Config. Service (ServiceConfig={SERVICECONFIG.USEAUTOFAC (); Serviceconfig.useservicefactory (); Serviceconfig.onstart (service, Extraparams)={service. Start (); }); Serviceconfig.onstop (Service={service. Stop (); }); Serviceconfig.onerror (Console.WriteLine); }); }); } }
The following is an example of an on-load command: "
dotnet Sikiro.SMS.BUS.dll Action:installdotnet Sikiro.SMS.BUS.dll action:uninstall
End
This is the content of this article, compared to the previous few content is relatively small, if you have a friend halfway to see the ". NET core Practice series of SMS Service-Architecture design" to look at the supplement, if there are any suggestions, you can comment back to me below.