What should be the best approach/practise when creating Rest Template beans for multiple upstream calls from a microservice

huangapple go评论85阅读模式
英文:

What should be the best approach/practise when creating Rest Template beans for multiple upstream calls from a microservice

问题

目前,从我们基于Spring的微服务中,我们对各种其他微服务进行多次调用。我想了解如何最好地使用rest模板bean,我们应该为每个上游微服务创建单独的rest模板bean吗?还是应该只使用一个通用的rest模板?

当为每个微服务使用不同的rest模板时,我们是否可以获得像隔离这样的优势?这意味着如果一个服务延迟,它不会影响其他服务。

目前,我们对所有服务都使用相同的rest模板。

英文:

Currently from our Spring based microservice, we make multiple calls to various other microservices. I wanted to understand what is the best practise of using the rest template bean, should we create a separate rest template bean for each upstream microservice ? Or should we just use a common rest template for all of them ?

Could we gain advantages like isolation when using different rest template for each microservice ? meaning if 1 service is latent, it does not impact other services.

Currently we are using same rest template for all the services.

答案1

得分: 0

我更倾向于为每个服务配置单独的RestTemplate,以分别配置超时、错误处理程序和拦截器。当然,您可以继承一个通用的父类,并覆盖所需的部分。

此外,考虑使用Spring Cloud Feign Client,它可以轻松定义特定于服务和默认配置。

英文:

I would prefer to configure a separate RestTemplate for each service to configure timeouts, error handlers, and interceptors separately. Of course, you can inherit from a general parent and override what is needed.

Also, consider using Spring Cloud Feign Client which allows defining service-specific and default configurations in an easy way.

答案2

得分: 0

我通过在两个不同的微服务调用之间共享REST模板进行了一个小实验项目,并使其中一个呈现潜在状态。这并没有影响另一个微服务调用的性能。

最终,我创建了一个单独的连接池,用于每个上游调用,以确保始终有足够的连接数量供所有人使用。

英文:

I did a small experiment project by sharing the rest template between two different microservice calls and made one of them latent. It did not impact the performance of another microservice call.

I ended up creating a separate connection pool for each upstream call to make sure there are always enough number of connections for everyone.

huangapple
  • 本文由 发表于 2023年3月9日 14:13:10
  • 转载请务必保留本文链接:https://go.coder-hub.com/75680995.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定