0

we can add client-side load balancing in spring boot applications by,

@Bean
    @LoadBalanced
    public RestTemplate restTemplate() {
        final RestTemplate restTemplate = new RestTemplate();
        return restTemplate;
    }

This will take care of the microservice resolution as well. ie. identifying service by the URL like "http://service_name/api/v1/endpoint/".

Is there any similar mechanism for name resolution in Spring integration?

Sanal M
  • 187
  • 4
  • 17
  • Have you tried to inject that `RestTemplate` into your Spring Integration HTTP Channel Adapters? It would be great to see more info where you'd like to have such a load balancing option. Perhaps we would need to introduce a generics `LoadBalancingRequestHandlerAdvice` alongside with an existing `RateLimiterRequestHandlerAdvice`, for example: https://docs.spring.io/spring-integration/docs/current/reference/html/messaging-endpoints.html#message-handler-advice-chain – Artem Bilan Apr 28 '21 at 13:55
  • Hi @ArtemBilan , How can I inject the RestTemplate to the HttpRequestExecutingMessageHandler? – Sanal M May 05 '21 at 13:10

1 Answers1

1

See this ctor for Spring Integration HTTP Outbound Channel Adapter:

/**
 * 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) {

So, when you configure a @ServiceActivator (handle() in Java DSL), you just inject your load-balanced RestTemplate and everything should work as expected.

Artem Bilan
  • 113,505
  • 11
  • 91
  • 118