简体   繁体   English

微服务标准 Healthcheck 和 API 响应

[英]Microservices standard Healthcheck and API response

I am wondering about how should i implement certain things.我想知道我应该如何实现某些事情。 I am new to the Microservices architecture, but i think i understood how it works in a certain way.我是微服务架构的新手,但我想我理解它是如何以某种方式工作的。 But i am very confused in the shared code, and shared projects thing.但是我对共享代码和共享项目的事情感到非常困惑。

I am developing a new system which contains about 50 microservice including ApiGateWays as well.我正在开发一个新系统,其中包含大约 50 个微服务,包括 ApiGateWays。 I am working only in ASP.net Core我只在 ASP.net 核心工作

I want to standardize the requests and responses.我想标准化请求和响应。 I created a new project which contians only models, so no logic included, just a few interface and some classes.我创建了一个仅包含模型的新项目,因此不包含逻辑,只有几个接口和一些类。

Is it hurting the core principals of microservice architecture any ways?它是否以任何方式损害了微服务架构的核心原则? I know in a certain point it does, but i develop only in ASP.Net core, and it is a very basic no logic model collection, which standard in the whole system, so if i would create a node.js project then i would use the same model there as well.我知道在某些方面确实如此,但我只在 ASP.Net 核心中开发,它是一个非常基本的无逻辑 model 集合,这是整个系统的标准,所以如果我要创建一个 node.js 项目,那么我会使用同样的 model 也在那里。

The other thing is the HealthCheck middleware.另一件事是 HealthCheck 中间件。 I am thinking to create this in a shared project and i would just reference it from the microservices.我正在考虑在共享项目中创建它,我只会从微服务中引用它。 This would contain logic, so i am confused, i think that if i would copy and paste it to everywhere than it would not be better than creating a shared project for it.这将包含逻辑,所以我很困惑,我认为如果我将它复制并粘贴到任何地方,它不会比为它创建一个共享项目更好。 It must be a standard thing, so if i have to change it for some reason then i would have to change it every single microservice as well.它必须是标准的东西,所以如果我出于某种原因必须更改它,那么我也必须更改每个微服务。

What do you think about this?你怎么看待这件事? It is a good practice to do it?这是一个好习惯吗? I know this is not the best practice, i know if i would work in a team i won't try to use the HealthCheck in a shared project, because that would cause more issues than it would solve, because which team should develop that and so on...我知道这不是最佳实践,我知道如果我会在一个团队中工作,我不会尝试在共享项目中使用 HealthCheck,因为这会导致比它解决的问题更多的问题,因为应该由哪个团队开发它并且很快...

And the last thing, somebody can help me to understand this whole code sharing in microservices, if it is possible, i read a lot of articles about it, but everybody says that you can share, but you should avoid it.最后一点,有人可以帮助我理解微服务中的整个代码共享,如果可能的话,我读了很多关于它的文章,但每个人都说你可以共享,但你应该避免它。 Please help me if you have time for it, i think a lot of newbie how jumps into microservices, and developing alone has this confusion in his mind.如果你有时间请帮帮我,我想很多新手是如何跳入微服务的,而独自开发的人脑子里有这种困惑。

Thanks for your time and i hope this would help some newbie in Microservices, which has the same confusion in Sharing code between microservices感谢您的宝贵时间,我希望这对微服务中的一些新手有所帮助,他们在微服务之间共享代码方面存在同样的困惑

In the microservices world, there will still be a need for shared libraries.在微服务世界中,仍然需要共享库。 Healthchecks is one of them.健康检查就是其中之一。

On MSDN docs this is described in detail.在 MSDN 文档中对此进行了详细描述。

https://docs.microsoft.com/en-us/aspnet/core/host-and-deploy/health-checks?view=aspnetcore-3.1 https://docs.microsoft.com/en-us/aspnet/core/host-and-deploy/health-checks?view=aspnetcore-3.1

A healthchecks shared library would that use that code and provide ways for your micriservices to register healthcheck endpoints with a call of one extension method.健康检查共享库将使用该代码并为您的 microservices 提供通过调用一个扩展方法来注册健康检查端点的方法。

Also that way the endpoints registered would be the same for all microservices.同样,注册的端点对于所有微服务都是相同的。

Tell me if you need more info and I elaborate more.如果您需要更多信息,请告诉我,我会详细说明。

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

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