Convert .NET Monolithic app to Microservices using AWS Microservice Extractor [Part 2]
Part 3: Testing, Deploy the new micro-services app on EKS & ECS (Under processing )
Agenda
1. Introduction
2. Launch visualization
3. AWS Microservice Extractor for?.NET AI-Powered Recommendations
4. Microservice extraction
5. Application refactoring
6. Conclusion
1. Introduction
we are already discussed the following points in Part 1
Now in this Part 2 we are going to discuss the ASP.NET Class visualization, AI-Powered Recommendations, Microservice extraction and Application refactoring.
2. Launch visualization
If the onboarding status changes to Success, you can open up the visualization either by pointing your mouse at View dependency graph in top green banner or from Applications list selecting Launch Visualization.
Microservice Extractor isolates and identifies the logically grouped components to be extracted as independent services, which are visible in the tab Visualization (Nodes dependencies). A link between nodes indicates a connection between them. Normally, nodes in the visualization are represented on Project level. Filters allow you to view certain project level or namespace level nodes. In addition, you may also double-click on specific nodes to navigate the namespace level or class level aggregations.
3. AWS Microservice Extractor for?.NET AI-Powered Recommendations
What are AI-powered recommendations?
The new AI-powered recommendations system relies on an ML model that inspects the source code of your own project. When the analysis by Microservice Extractor is done, your classes are organized within this tool into prospective candidates for microservices creation.
This improved feature is especially useful for those customers that do not have the required skills to update their applications. This is typically the situation for many companies that have applications with a long ‘shelf’ life in the market, where the original developers are no longer accessible or at times developed by third parties and it becomes challenging to upgrade.
Choosing the right recommendation option
The Microservice Extractor provides three extraction options: manual classification, heuristic assessment, and AI-based recommendations. These are a few of the methods that you can use to grouping your classes for microservices hence enabling you as the developer to select an approach which is flexible and effective at least depending on how comfortable one should get with special building blocks without relying 100 percent on classical ones. Crucially, this first choice of extraction does not restrict your ability to select a different approach through the user interface later on as you contemplate the emerging needs for these new microservices.
If you have a well-developed domain understanding of some application planned for refactoring, the manual classification suits best with the purpose to build such microservice that will serve it. This requires a deep understanding of the application class structure, and even how these classes are related to each other.
If you are familiar with the application at a lower level, but if know enough about how to strip out what is needed then it should be apparent as well from the source code using heuristic analysis where your logical starting points would lie. In this case of analysis, the points selected are classified according to the group that features classes by their name. For instance, in an MVC application a class of controller may act as the starting point at which one would start to pull out an order-related microservice.
On the other hand, in case you have limited or no knowledge about applications that are being modernized, then an AI-powered recommendations engine is very priceless. These recommendations move from the heuristic analysis since they clearly distinguish the entrance and exit points for the services. The microservice extractor application uses AI recommendation algorithms to scan every source file in an application and produce recommendations that one can use as the actual list of the candidates.
to use AI- powered recommendations you can click on Generate automated groups as below:
4. Microservice extraction
In this example, you will extract Inventory as a standalone service.
On the right section, you can find the Group details
Note that the Nodes list refers to the InventoryGroup class. This class will be released as a standalone service and exposed as a REST API after release. Check the list of Dependencies. All dependencies in this list will be listed or referenced in the extracted standalone service.
Extraction path
领英推荐
Extracted service codes
Please note that although our AWS Microservice Extractor, for.NET will make its efforts to ensure that the created service compiles there is no guarantee. You may still need to fix references or update NuGet packages in order to successfully compile the Web API project.
Change the port of Extracted service to be https://localhost:8081/ as below:
Please take a look, at the HomeController.cs, ShoppingCartController.cs and StoreController.cs files, in the Controllers folder. The local Inventory class calls have been modified to make remote API calls using the EndpointAdapter.
Modified application Code / web.config
In the line 11 please change the url and link it to the new extracted service [ https://localhost:8081 ] as below:
Modified application Code / web.config
5. Application refactoring
In the preceding sections, you were introduced to the capabilities of AWS Microservice Extractor for?.NET and how it can aid in extracting microservices from your existing?.NET monolithic applications. Although the subsequent section of this tutorial is not mandatory, it offers valuable insights as most of the tasks involved do not require the use of AWS Microservice Extractor. It is highly recommended to follow these steps if your objective is to successfully refactor the extracted service and integrate it with the remaining monolith through REST APIs.
Refactor the extracted service
To update the Microsoft.AspNet.WebApi.Client NuGet package, enter the following command in the Package Manager Console. This package will provide support for formatting and content negotiation for System.Net.Http.
Update-Package -reinstall Microsoft.AspNet.WebApi.Client
To optimize communication efficiency, it’s beneficial to transform the Entity Framework data entities from the Inventory class into simplified “plain old CLR objects” (POCOs), also referred to as Data Transfer Objects (DTOs), before transmitting them over the network.
//Remove
//return Ok(myInstance.GetBestSellers(count));
//ADD
return Ok(DTOHelper.GetDTOProductList(myInstance.GetBestSellers(count)));
2. in line 99
//Remove
// return Ok(myInstance.GetAllProductsInCategory(category));
//Add
return Ok(DTOHelper.GetDTOProductList(myInstance.GetAllProductsInCategory(category)));
3. In line 130
//Remove
//return Ok(myInstance.GetProductById(id));
//Add
return Ok(DTOHelper.GetDTOProduct(myInstance.GetProductById(id)));
Launch the Extracted service
Refactor the modified application code.
To update the Microsoft.AspNet.WebApi.Client NuGet package, enter the following command in the Package Manager Console. This package will provide support for formatting and content negotiation for System.Net.Http.
Update-Package -reinstall Microsoft.AspNet.WebApi.Client
// remove
//Inventory inventory;
//Add
IInventoryEndpoint inventory;
//Remove
//Inventory inventory;
//Add
IInventoryEndpoint inventory;
// GET: Store
Simply hit the F5 button to activate the application’s debug mode. Keep in mind that it may take a few minutes for the web app to fully load, and you may see a message saying “This site can’t be reached” in the meantime. If that occurs, just give it some time to start up completely. Once the application is up and running, you’ll be directed to the same home page you started with. However, take note that the categories displayed on the left side and the list of top-selling products at the bottom are now being fetched from the Inventory Web API through REST API requests.
The ASP.NET Application after refactoring
6. Conclusion
To sum it up, implementing the AWS Microservices Extractor for?.NET has splitted the monolithic application into two separate services that seamlessly communicate through REST APIs. This structural change not only amplifies scalability and adaptability, but also maintains a consistent end-user experience. Adopting microservices has been a game-changing move, enhancing efficiency and flexibility in the development and operation of the application.