Uploaded image for project: 'Spring Framework'
  1. Spring Framework
  2. SPR-17298

Support for non-blocking event listener methods

    Details

    • Type: New Feature
    • Status: Open
    • Priority: Major
    • Resolution: Unresolved
    • Affects Version/s: None
    • Fix Version/s: 5.2 RC1
    • Component/s: Core, Reactive
    • Labels:
      None
    • Last commented by a User:
      true

      Description

      In a non-blocking application flow, it's desirable to prevent event listeners from blocking and yet have a notion of managed event completion (i.e. an event listener needs to interact with a remote system but must not block). Event listener methods could return future/async types so the event multicaster can synchronize on execution/initiate execution to use non-blocking event listeners in a reactive (or at least non-blocking) arrangement.

      Event listener methods could either return:

      • A future (in particular ListenableFuture, CompletableFuture, or CompletionStage, either Void, T, or Collection<T> component types)
      • A Publisher (or any other supported reactive type such as RxJava 2's Observable with Void or T component types).

      Example:

      @Component
      public class MyListener {
        
          @EventListener
          public Mono<Void> handleContextRefresh(ContextRefreshedEvent event) {
              ...
          }
      
          @EventListener
          public Flux<MyBusinessResponseEvent> handleBusinessEvent(MyBusinessEvent event) {
              ...
          }
      
          @EventListener
          public CompletableFuture<Void> handleBusinessEvent(MyOtherBusinessEvent event) {
              ...
          }
      }
      

       
      This feature could allow to implement functionality in event listeners in an non-blocking programming model to prevent blocking calls.

      Result handles should be used to attach at least some sort of exception handling to prevent exceptions from going unnoticed. For reactive types, the multicaster subscribes to the reactive type to materialize the outcome.

      Values emitted from a result handle (i.e. non-void returns like CompletableFuture<Void>, Publisher<Void>) could be emitted again as events.

      This ticket seems to relate to SPR-16481.

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                juergen.hoeller Juergen Hoeller
                Reporter:
                mp911de Mark Paluch
                Last updater:
                Spring Issuemaster
              • Votes:
                1 Vote for this issue
                Watchers:
                5 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Days since last comment:
                  26 weeks, 4 days ago