我们可以通过在春季启动应用程序中添加客户端负载平衡
@Bean
@LoadBalanced
public RestTemplate restTemplate() {
final RestTemplate restTemplate = new RestTemplate();
return restTemplate;
}
这也将考虑微服务的解决方案。即通过URL来识别服务;http://service_name/api/v1/endpoint/"。
Spring集成中是否有类似的名称解析机制?
请参阅此ctor了解Spring Integration HTTP出站通道适配器:
/**
* Create a handler that will send requests to the provided URI using a provided RestTemplate
* @param uri The URI.
* @param restTemplate The rest template.
*/
public HttpRequestExecutingMessageHandler(String uri, RestTemplate restTemplate) {
因此,当您配置@ServiceActivator
(JavaDSL中的handle()
(时,只需注入负载平衡的RestTemplate
,一切都应该按预期工作。