.Net Core Serverless first experience

What is Serverless

  Serverless today's software world is a relatively new topic. It does not have a generally accepted definition of authority, each person every business has a different interpretation of it may be, but Serverless It is in this case continues to fat development. But even so, there are some features Serverless still widely recognized:

  • Server hosting and fully managed process by the supplier
  • The load may be automatically retractable
  • According to the precise usage to billing, like water and electricity. (Utility computing)

  Nuggets reference, the original address: https://juejin.im/post/5c68fdbfe51d4539a569f259

 

Serverless Evolution

 

 

  There are several progressive milestone in the development process:

  • The large virtualization technology into a single physical machine VM VM resources.
  • The move to cloud computing cluster virtualization platform, only a simple operation and maintenance.
  • Each VM runs in accordance with the principle of minimizing the space cut into finer Docker containers.
  • Docker container-based building management without any operating environment, just write Serverless architecture core code.

  Quoted Ali cloud, the original address: https://help.aliyun.com/knowledge_detail/65565.html?spm=a2c4g.11186631.2.1.4f811bbeDYGmvp

 

Ali cloud Serverless - function calculation

  Event-driven computing function is fully managed computing services. Calculated using a function, you do not need to purchase and manage server infrastructure, just write and upload code. Function calculates ready for your computing resources, flexibly and reliably run tasks, and provide the log queries, performance monitoring and alarm functions.

With computing function, you can rapidly build any type of application and service, and only for the resources actually consumed mission paid.

  Quoted Ali cloud, the original address: https://help.aliyun.com/document_detail/52895.html?spm=a2c4g.11186623.6.541.23dc641aB3U3K0

 

Code written in .Net Core

  1. Create a new .net core console program, here named AliyunServerless.

  

 

 

  2. The reference function Ali cloud computing components Aliyun.Serverless.Core provided

  Install-Package Aliyun.Serverless.Core

  

 

  3. Preparation of classes and functions .Net Core calculated as a function of the requirements, where two classes and functions

  a. print execution log

    ///  <Summary> 
    /// print execution log
     ///  </ Summary> 
    public  class the LogHandler
    {
        public void Handle(Stream input, IFcContext context)
        {
            ILogger logger = context.Logger;
            logger.LogInformation($"Handle request: {context.RequestId}");
        }
    }

 

  b. IP Print Server

    ///  <Summary> 
    /// print server the IP
     ///  </ Summary> 
    public  class IpHandler
    {
        public void Handle(Stream input, IFcContext context)
        {
            ILogger logger = context.Logger;
            var ipHostInfo = Dns.GetHostEntry(Dns.GetHostName());
            logger.LogInformation($"Handle request: {context.RequestId}");

            foreach (var ipAddress in ipHostInfo.AddressList)
            {
                logger.LogInformation($"IP Address:{ipAddress}");
            }
        }
    }

 

  Description:

  

   For details, please refer to the original address: https://help.aliyun.com/document_detail/112379.html?spm=a2c4g.11174283.6.567.206852120XSx37

 

  4. publisher and a zip

  dotnet publish -c Release

   

 

Ali cloud computing configuration function

  1. Fee and quota free

  

 

  2. Select the function performed by region

  Entry address: https://fc.console.aliyun.com/fc/overview/cn-shenzhen

  

 

 

  3. Create a service and function

  a. Create function

  

 

 

  b. Select "Event function", then "Next"

  

 

  c. Configure function information

  

 

  among them:

  "Where the service" is a packet, you can fill in as needed.

  "Function Name" is the name, you can fill in as needed.

  "Operating environment" Select dotnetcore2.1.

  "Functions" according to the provisions fill in, template assembly is {} {} :: {namespace :: class name} {name} function here is:. AliyunServerless :: AliyunServerless.LogHandler :: Handle

  "Function performs memory" function performs the required memory.

  "Timeout" function execution time can not exceed the set.

  

  d. performing functions

  Click "Run", you can see the executive summary (execution time, memory usage, execution status, etc.) and the results:

  

 

  e. Create Trigger

  

 

  Here is "clocked flip-flop", expressions support Cron, scheduling the highest frequency of one minute does not support the second stage scheduler; except "clocked flip-flop", there are the following types of triggers:

  

   Interested friends can study on their own.

   After finished with triggers, functions will be timed trigger point because there is print the log, you need to configure the log to see, we did not configure the log, do not demonstrate triggered effects.

 

Extended Test

  Follow the steps to create a function to create a "print server IP" function, execution and tracking results are as follows:

  1. repeatedly (5 times different RequestId), IP server is not changed (both as 21.0.3.3), instructions assigned to the same server

  

  

  

  

 

  

 

  2. re-upload the package, the server IP will become, but with a constant IP server software package

  . A first re-upload:

  

 

  

 

  . B second re-upload:

  

  

 

  3. I choose execution area is "1 South China (Shenzhen)," but the server IP US IP; because no server information, the conclusion is for reference only

  

  

  

 

  4. Call statistics will be non-real time (normal), most of the business month should be sufficient quota free use

  

  

Source Address

  https://github.com/ErikXu/AliyunServerless

Guess you like

Origin www.cnblogs.com/Erik_Xu/p/11666872.html