@RibbonClient和@LoadBalanced之间的区别 [英] Difference between @RibbonClient and @LoadBalanced

查看:2050
本文介绍了@RibbonClient和@LoadBalanced之间的区别的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我了解@LoadBalanced表示Rest模板应该基于使用Ribbon的客户端负载平衡,并检查Eureka服务器是否将服务名称解析为主机/端口.

I understand @LoadBalanced indicates the Rest template should be based on Client Side Load Balancing using Ribbon and checks Eureka server for resolving the service name to host/port.

@RibbonClient的用途是什么.

推荐答案

TL; DR :@LoadBalanced是标记注释& @RibbonClient用于配置.

TL;DR: @LoadBalanced is a marker annotation & @RibbonClient is used for configuration purposes.

用作标记注释,指示带注释的RestTemplate应该使用RibbonLoadBalancerClient与您的服务进行交互.

Used as a marker annotation indicating that the annotated RestTemplate should use a RibbonLoadBalancerClient for interacting with your service(s).

这又使您可以对传递给RestTemplate的URL使用逻辑标识符".这些逻辑标识符通常是服务的名称.例如:

In turn, this allows you to use "logical identifiers" for the URLs you pass to the RestTemplate. These logical identifiers are typically the name of a service. For example:

restTemplate.getForObject("http://some-service-name/user/{id}", String.class, 1);

其中some-service-name是逻辑标识符.

用于配置功能区客户端.

Used for configuring your Ribbon client(s).

需要@RibbonClient吗?

不!如果您正在使用服务发现,并且对所有默认的功能区设置都没问题,那么甚至不需要使用@RibbonClient批注.

No! If you're using Service Discovery and you're ok with all of the default Ribbon settings, you don't even need to use the @RibbonClient annotation.

我什么时候应该使用@RibbonClient?

When should I use @RibbonClient?

至少有两种情况需要使用@RibbonClient

There are at least two cases where you need to use @RibbonClient

  1. 您需要为特定的Ribbon用户端自定义功能区设置
  2. 您没有使用任何服务发现

自定义功能区设置:

Customizing your Ribbon settings:

定义一个@RibbonClient

@RibbonClient(name = "some-service", configuration = SomeServiceConfig.class)

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆