Uploaded image for project: 'Ignite'
  1. Ignite
  2. IGNITE-15572

Ability to set custom execution context for Ignite service.

    XMLWordPrintableJSON

Details

    • New Feature
    • Status: Resolved
    • Major
    • Resolution: Resolved
    • None
    • 2.13
    • managed services
    • Added a ServiceCallContext that allows implicitly pass additional parameters on every service call.
    • Release Notes Required

    Description

      In traditional microservices, we have the ability to set a custom execution context. For example, a REST service may obtain the session ID from the request. We can say that each client request, in this case, has a set of explicit and implicit parameters. One of the implicit parameters is a session identifier that can be passed to the service using request headers. It would be nice to have a similar feature in Ignite services.

      The basic idea behind the implementation:
      1. Allow the user to bind the "execution context" to the service proxy object.
      2. Pass this context as an additional implicit parameter each time the user service method is called.

      API proposal (outdated, actual Java API in IGNITE-15794).

      1. Using a custom annotation (ServiceRequestContextResource) and reading context attributes with a function.

      MyService proxy = ignite.services().serviceProxy("svc", ... Collections.singletonMap("login", "user1"));
      
      public class MyServiceImpl implements MyService {
          @ServiceRequestContextResource
          private Function<String, Object> ctxFunc;
      
          @Override public void serviceMethod() {
              String login = (String)ctxFunc.apply("login");
          }
          ...
      }

      2. Using a new method of the existing ServiceContext.

      MyService proxy = ignite.services().serviceProxy("svc", ... Collections.singletonMap("login", "user1"));
      
      public class MyServiceImpl implements MyService {
          private ServiceContext svcCtx;
      
          @Override public void init(ServiceContext svcCtx) {
              this.svcCtx = svcCtx;
          }
      
          @Override public void serviceMethod() {
              String user = svcCtx.attribute("login");
              // and/or
              String user = (String)svcCtx.attributes().get("login");
          }
          ... 
      }

      The next two options require wrapping Map<String, Object> into a new ServiceRequestContext class.

      3. Read context "wrapper" using special annotation and supplier.

      MyService proxy = ignite.services().serviceProxy("svc", ... new ServiceRequestContext("login", "user1"), 0);
      
      public class MyServiceImpl implements MyService {
          @ServiceRequestContextResource
          Supplier<ServiceRequestContext> ctxSupplier;
      	
          @Override public void serviceMethod() {
              String login = ctxSupplier.get().attribute("login");
          }
          ...
      }
      

      4. Using the special static method of the "wrapper" class.

      MyService proxy = ignite.services().serviceProxy("svc", ... new ServiceRequestContext("login", "user1"), 0);
      
      public class MyServiceImpl implements MyService {
          @Override public void serviceMethod() {		
              String login = ServiceRequestContext.current().attribute("login");
          }
          ...
      }
      

      Attachments

        Issue Links

          Activity

            People

              xtern Pavel Pereslegin
              xtern Pavel Pereslegin
              Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved:

                Time Tracking

                  Estimated:
                  Original Estimate - Not Specified
                  Not Specified
                  Remaining:
                  Remaining Estimate - 0h
                  0h
                  Logged:
                  Time Spent - 3h 40m
                  3h 40m