简体   繁体   English

如何使用微服务架构分离现有项目?

[英]How to Separate Existing Project using Micro Service Architecture?

I have created one project in asp.net MVC for banking sector. 我在asp.net MVC中为银行部门创建了一个项目。

At the time of development,We did not think about scaling.So we did not used any kind of modular architecture. 在开发时,我们没有考虑扩展。因此,我们没有使用任何模块化的体系结构。

But now I am facing lots of problem regarding deployment and development of new feature. 但是现在我在新功能的部署和开发方面面临很多问题。

If I develop any new feature then currently I have to release entire project as there is only one namespeace - projectmain.dll. 如果我开发任何新功能,那么当前我必须发布整个项目,因为只有一个namepeace-projectmain.dll。

Now I want to separate all controllers in seperate projects and I want to deploy it seperatly and using MicroService architecture I want to use this in main project. 现在,我想将所有控制器分离在单独的项目中,并想单独部署它,并使用MicroService体系结构,我想在主项目中使用它。

Note My Views are tightly coupled with controller. 注意“我的视图”与控制器紧密结合。

So How can I migrate this entire controllers in MicroService Architecture? 那么如何在MicroService Architecture中迁移整个控制器?

Project Structure Explanation 项目结构说明

"How to migrate to microservices" needs a very very long answer that can be a book. “如何迁移到微服务”需要一个非常长的答案,这可能是一本书。 I can however, give you some directions that could help you. 但是,我可以给您一些指导,以帮助您。

First of all, you could follow the DDD approach to help you to correctly identify the bounded context of your application. 首先,您可以遵循DDD方法来帮助您正确识别应用程序的有限上下文。 In an ideal situation, every domain should correspond to a bounded context. 在理想情况下,每个域都应对应一个有界上下文。 So you could split by bounded context. 因此,您可以按有限的上下文划分。 Every bounded context could have one or more microservices, but a microservice should not be larger than a bounded context. 每个有界上下文可以具有一个或多个微服务,但是微服务不应大于有界上下文。 From what I see, your controllers are already split by domain or at least by subdomain. 从我的角度来看,您的控制器已经按域或至少按子域划分了。 You could try to make a microservice for each controller and see how it goes; 您可以尝试为每个控制器创建一个微服务,并查看其运行情况。 it is possible to further split, ie by the Aggregate from the DDD (every Aggregate type could be a microservice). 可以进一步拆分,即通过DDD中的聚合(每种聚合类型都可以是微服务)。

Second, you should have separate projects for each microservice. 其次,每个微服务应该有单独的项目。 Ideally, if you want resilience and scalability, a microservice should not call other microservice during an external request. 理想情况下,如果您需要弹性和可伸缩性,则微服务不应在外部请求期间调用其他微服务。 This means that when a microservice receive a request from the clients, it should not call another microservice; 这意味着,当微服务收到来自客户端的请求时,它不应调用另一个微服务。 for this it should have all the needed data from the other microservices already to its local storage (using background tasks, with synchronous or asynchronous calls). 为此,它应该已经将所有其他微服务所需的数据都已经传输到其本地存储中(使用后台任务,以及同步或异步调用)。

Last but not least, each microservice should have its own database; 最后但并非最不重要的一点是,每个微服务都应该有自己的数据库; they should not share the same database or table. 它们不应共享相同的数据库或表。

In this situation, I guess one option would be to convert your controllers into a Web API with each action method returning JSON data instead of returning a view to render. 在这种情况下,我猜一个选择是将您的控制器转换为Web API,每种操作方法都返回JSON数据,而不是返回要渲染的视图。 This would now be treated as a separate back end which could be bundled as one micro service. 现在将其视为单独的后端,可以将其捆绑为一个微服务。 The next step would be to convert your razor views into a purely front end microservice (using a framework like angular or react) with 2 layers- 下一步是将您的剃刀视图转换为具有2层的纯前端微服务(使用诸如angular或react这样的框架)-

  1. A service layer responsible for making API calls that fetch the JSON data returned by your Web API 服务层,负责进行API调用,以获取Web API返回的JSON数据
  2. A component layer responsible for mapping the JSON data fetched by your service to your UI elements/forms 组件层,负责将服务获取的JSON数据映射到UI元素/表单

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM