Triggering a Function from a Legacy Application

In this section, we'll trigger an Azure Function from a console application. We'll integrate an existing command-line application with our new cloud architecture. To ensure it works correctly, you'll need to have the code repository downloaded. Let's begin by implementing the following steps:

  1. Open the project called PersonalFinanceCLIApp and take a look around.
This application is a command-line application that allows a user to submit a transaction, save it into a CSV, and then produce some stats about the transactions that have been logged with the app. This is obviously a very simple example of a legacy application, written in C# so that students are able to edit it, but the principles of what we will do apply to any general-purpose programming language with access to network interfaces.

Refer to the following screenshot:

Refer to the complete code placed at Code/Serverless-Architectures-with-Azure/Lesson 3/PersonalFinanceCLIApp/Program.cs.
Navigate to https://goo.gl/q79fPe to access the code.
  1. Add an HttpClient and your API key as static variables.

Get your API key by going to your function in the portal and clicking on the Keys tab.

Refer to the following screenshot:

Refer to the complete code placed at Code/Serverless-Architectures-with-Azure/Lesson 3/PersonalFinanceCLIApp/PersonalFinanceCLIApp.csproj.
Navigate to https://goo.gl/E88BMn to access the code.
  1. Create an async static function called BackupTransaction that takes a transaction object. In the function, copy and paste the code from our serverless client POST action. Refer to the following screenshot:
  1. Make a call to BackupTransactions and pass the transaction into it.
  2. Run the CLI app; it should be just as responsive as it was previously, because the asynchronous code is executing on a separate thread.

You have successfully written an application that backs transactions up to the Cosmos DB.

Thirdly, if you have a fairly well-architected application written in a programming language that your development team can cope with, then you can progressively shift functionality to serverless functions without breaking the application. This allows you to split the work up to replace the application entirely, and, once you have this data flowing through serverless functions, you can start extending this application into the rest of your serverless architecture.

This functionality will then be available for other services to use, which is particularly useful for intensive, business-specific calculations. It will also scale infinitely, allowing you to free up computing power from your client machines (this is very useful for code running on old servers, and so on).

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

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