Uploaded image for project: 'JBoss Transaction Manager'
  1. JBoss Transaction Manager
  2. JBTM-3988

LraId doesn't propagate when using ManagedExecutor

XMLWordPrintable

    • Icon: Enhancement Enhancement
    • Resolution: Duplicate
    • Icon: Major Major
    • None
    • None
    • LRA
    • None

      When inside an LRA context, using a ManagedExecutor to submit work that does REST requests (using a MP RestClient), will result in requests that do not contain the LRA ID header.

      This is caused by the fact that there is no ThreadContextProvider available for propagating the LraId URI to the Current instance.

      I would like to propose adding a ThreadContextProvider implementation that contains something like the following:

          @Override
          public ThreadContextSnapshot currentContext(Map<String, String> props) {
              URI lraId = Current.peek();
              if (lraId == null) {
                  return  null;
              }
              
              long threadId = Thread.currentThread().threadId();
              
              return () -> {
                  long threadId2 = Thread.currentThread().threadId();
                  
                  if (threadId != threadId2) {
                      logger.log(FINE, () -> "Pushing " + lraId + " from thread " + threadId + " to " + threadId2);
                      
                      // Executed in new Thread
                      Current.push(lraId);
                  }
                  
                  return () -> {
                      long threadId3 = Thread.currentThread().threadId();
                      
                      if (threadId != threadId3 && threadId2 == threadId3) {
                          // Executed in new Thread
                          URI oldLra = Current.pop();
                          
                          logger.log(FINE, () -> "Popping " + oldLra + " obtained from thread " + threadId + " in " + threadId3);
                      }
                  };
                  
              };
          }
      

              Unassigned Unassigned
              arjan.tijms@gmail.com Arjan Tijms (Inactive)
              Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

                Created:
                Updated:
                Resolved: