Spring Framework
  1. Spring Framework
  2. SPR-8804

Support an asynchronous API for RestTemplate

    Details

    • Last commented by a User:
      true

      Description

      Asynchronous programming models are growing in popularity. To support this model of development it would be great if RestTemplate were enhanced to support an asynchronous model.

      JAX-RS's client api is currently slated to add an asynchronous mode.

      There are several Async Http client libraries.

      It would seem that soon would be the right time to add Async support for RestTemplate.

        Activity

        Hide
        Chris Beams added a comment -

        Thanks for the submission, Mike. I've added Juergen, Arjen and others as watchers on this issue and slated it for the 3.2 backlog. Agreed that 3.2 is likely the right time to consider such functionality; I'll be interested to see what other users have to say about this as well. Use cases would be helpful to ensure we're all on the same page.

        Show
        Chris Beams added a comment - Thanks for the submission, Mike. I've added Juergen, Arjen and others as watchers on this issue and slated it for the 3.2 backlog. Agreed that 3.2 is likely the right time to consider such functionality; I'll be interested to see what other users have to say about this as well. Use cases would be helpful to ensure we're all on the same page.
        Hide
        Lukas Krecan added a comment -

        We have similar need. Our use case is simple. We are creating an aggregated resource. We need to call several underlying REST APIs and when all of the results return, we merge them to return aggregated result. We want to execute all the requests in parallel. So the ideal API would be

        Future result1 = execute(...);
        Future result2 = execute(...);
        Future result3 = execute(...);
        
        merge(result1, result2, result3);
        
        Show
        Lukas Krecan added a comment - We have similar need. Our use case is simple. We are creating an aggregated resource. We need to call several underlying REST APIs and when all of the results return, we merge them to return aggregated result. We want to execute all the requests in parallel. So the ideal API would be Future result1 = execute(...); Future result2 = execute(...); Future result3 = execute(...); merge(result1, result2, result3);
        Hide
        Chris Beams added a comment -

        Added @Rossen as a watcher as well as he's currently investigating async options in 3.2

        Show
        Chris Beams added a comment - Added @Rossen as a watcher as well as he's currently investigating async options in 3.2
        Hide
        Lukas Krecan added a comment -

        I have written a quick prototype of AsyncRestTemplate https://github.com/lukas-krecan/spring-framework/commit/1f55c1b571f6c68810bf3d4582bb65da0fb4f5d8. Basically it wraps RestTemplate, executes the corresponding method using AsyncTaskExecutor and returns Future instead of the original return value. Please let me know what you think about it. If you are interested, I will fix the documentation, formating, tests and other stuff and will issue a pull request.

        Show
        Lukas Krecan added a comment - I have written a quick prototype of AsyncRestTemplate https://github.com/lukas-krecan/spring-framework/commit/1f55c1b571f6c68810bf3d4582bb65da0fb4f5d8 . Basically it wraps RestTemplate , executes the corresponding method using AsyncTaskExecutor and returns Future instead of the original return value. Please let me know what you think about it. If you are interested, I will fix the documentation, formating, tests and other stuff and will issue a pull request.
        Hide
        Rossen Stoyanchev added a comment -

        Yes, that will certainly be one part of the implementation. We'll also want to support HTTP libraries that provide non-blocking support like Appache HttpComponents HttpAsyncClient.

        Show
        Rossen Stoyanchev added a comment - Yes, that will certainly be one part of the implementation. We'll also want to support HTTP libraries that provide non-blocking support like Appache HttpComponents HttpAsyncClient.
        Hide
        Lukas Krecan added a comment -

        Do you have any update whether it will make it to Spring 4?

        Show
        Lukas Krecan added a comment - Do you have any update whether it will make it to Spring 4?
        Hide
        Arjen Poutsma added a comment -

        It will make it .

        Show
        Arjen Poutsma added a comment - It will make it .
        Hide
        Arjen Poutsma added a comment -
        Show
        Arjen Poutsma added a comment - Pull request at https://github.com/SpringSource/spring-framework/pull/336
        Hide
        Luciano Leggieri added a comment -

        Do you think it's worth to add support for https://github.com/AsyncHttpClient/async-http-client ? It's a popular framework for non-blocking connections.
        I have a first draft here: https://github.com/lukiano/async-http-client-spring

        Show
        Luciano Leggieri added a comment - Do you think it's worth to add support for https://github.com/AsyncHttpClient/async-http-client ? It's a popular framework for non-blocking connections. I have a first draft here: https://github.com/lukiano/async-http-client-spring

          People

          • Assignee:
            Arjen Poutsma
            Reporter:
            Mike Youngstrom
            Last updater:
            Luciano Leggieri
          • Votes:
            12 Vote for this issue
            Watchers:
            20 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:
              Days since last comment:
              26 weeks, 1 day ago