Moving Functionality from a Legacy Application to an Azure Function

In this section, we'll calculate the interesting facts about the users' transactions in an Azure Function. We'll offload intensive processing from a legacy application to a serverless function. To ensure it works correctly, we'll need to have the code repository downloaded. Let's begin by implementing the following steps:

  1. Create a new HttpTriggered function called CalculateTransactionsInformation. Set the access rights to Anonymous.
  2. Delete everything in the Run function template. Refer to the following screenshot:
Refer to the complete code placed at Code/Serverless-Architectures-with-Azure/Lesson 3/BeginningAzureServerlessArchitecture/CalculateTransactionsInformation.cs.
Navigate to https://goo.gl/WHTjEY to access the code.
  1. Deserialize the content of the message into a list of transactions; you can copy some of the code from LessonOne.cs. Refer to the following screenshot:
Refer to the complete code placed at Code/Serverless-Architectures-with-Azure/Lesson 3/BeginningAzureServerlessArchitecture/LessonOne.cs.
Navigate to https://goo.gl/o5zW1x to access the code.
  1. Cut and paste the LINQ statements from the CLI app. Refer to the following screenshot:
Refer to the complete code placed at Code/Serverless-Architectures-with-Azure/Lesson 3/BeginningAzureServerlessArchitecture/CalculateTransactionsInformation.cs.
Navigate to https://goo.gl/WHTjEY to access the code.
  1. Let's add a model to make it easier to transfer the results between the functions. Create a model called TransactionsInformationModel with three decimal properties: TotalTransactionsAmountMeanTransactionAmount, and LargestTransactionAmount. Refer to the following screenshot:
Refer to the complete code placed at Code/Serverless-Architectures-with-Azure/Lesson 3/BeginningAzureServerlessArchitecture/Models/TransactionsInformationModel.cs.
Navigate to https://goo.gl/3UCjeg to access the code.
  1. Now return an instance of the TransactionsInformationModel in the response content. Refer to the following screenshot:
Refer to the complete code placed at Code/Serverless-Architectures-with-Azure/Lesson 3/BeginningAzureServerlessArchitecture/CalculateTransactionsInformation.cs.
Navigate to https://goo.gl/7BjuhC to access the code.
  1. Return to the console application, in Program.cs. Add another function that takes a list of transactions and returns a TransactionsInformationModel called CalculateTransactionInformation. Refer to the following screenshot:

If Intellisense has an issue with this, click Build on the Function App project. Serialize the transactions into a string content, with code similar to before. There's no point in making this asynchronous, because the application depends on showing this before the message asking the user whether they want to add another transaction. So, add a .Result on to the end of every asynchronous method. Deserialize the response into the TransactionInformationModel.

Refer to the complete code placed at Code/Serverless-Architectures-with-Azure/Lesson 3/PersonalFinanceCLIApp/Program.cs.
Navigate to https://goo.gl/PqcU8u to access the code.
  1. Add a method call where the LINQ statements were, pass the result into var, and change the references in the Console.logs to point to the corresponding properties on that object. Refer to the following screenshot:
  1. Deploy your function to Azure and copy and paste the address of it into the HttpRequest.
  2. Test the app.

Statistical calculations have shifted from one application to a serverless function.

What if you either don't have access to the source code, or it is so delicate that the previous approaches are unfathomable? Well, another method for serverless integration is to target the database directly. Whether it's an application brought in or a delicate, internal application, applications will tend to have their very own databases, likely on-premises rather than cloud-based. Microsoft has a product called the On-premises data gateway that allows you to connect serverless functions to On-premises PostgreSQL, MySQL, Oracle, SQL, and Teradata databases, as well as MQ and BizTalk servers. You can then trigger serverless functions when records are added to some of these databases or messages are added to MQ. This product is relatively easy to set up, but obviously, setting up a miniature data center for you to try this out in the book would be a bit lengthy, so we won't be doing it.

Find out how to set up the On-premises data gateway at https://docs.microsoft.com/en-us/azure/logic-apps/logic-apps-gateway-connection.
..................Content has been hidden....................

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