[ 
https://issues.apache.org/jira/browse/IGNITE-15572?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
 ]

Pavel Pereslegin updated IGNITE-15572:
--------------------------------------
    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.

Sample code for specifying "headers".
{code:java}
// Creating "execution context".
Map<String, Object> execCtx = Collections.singletonMap("user.id", 1);

// Binding "request headers" to proxy invocation handler.
IMyService svcProxy = ignite.services().serviceProxy("service1", 
IMyService.class, false, execCtx);

// Service method invocation.
svcProxy.multiply(2, 2);
svcProxy.multiply(3, 3);
svcProxy.multiply(4, 4);
...
{code}

Sample code for reading "headers".
{code:java}
class MyServiceImpl implements IMyService {
    @LoggerResource
    private IgniteLogger log;

    private ServiceContext ctx;

    @Override public void init(ServiceContext ctx) {
        this.ctx = ctx;
    }

    @Override public int multiply(int a, int b) {
        log.info(String.format("user=%d, oper=%s, a=%d, b=%d", 
ctx.attr("user.id"), "multiply", a, b));

        return a * b;
    }

    ...
}
{code}


  was:
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.

Sample code for specifying "headers".
{code:java}
// Creating "request headers".
Map<String, Object> execCtx = Collections.singletonMap("user.id", 1);

// Binding "request headers" to proxy invocation handler.
IMyService svcProxy = ignite.services().serviceProxy("service1", 
IMyService.class, false, execCtx);

// Service method invocation.
svcProxy.multiply(2, 2);
svcProxy.multiply(3, 3);
svcProxy.multiply(4, 4);
...
{code}

Sample code for reading "headers".
{code:java}
class MyServiceImpl implements IMyService {
    @LoggerResource
    private IgniteLogger log;

    private ServiceContext ctx;

    @Override public void init(ServiceContext ctx) {
        this.ctx = ctx;
    }

    @Override public int multiply(int a, int b) {
        log.info(String.format("user=%d, oper=%s, a=%d, b=%d", 
ctx.attr("user.id"), "multiply", a, b));

        return a * b;
    }

    ...
}
{code}



> Ability to set custom execution context for Ignite service.
> -----------------------------------------------------------
>
>                 Key: IGNITE-15572
>                 URL: https://issues.apache.org/jira/browse/IGNITE-15572
>             Project: Ignite
>          Issue Type: New Feature
>          Components: managed services
>            Reporter: Pavel Pereslegin
>            Assignee: Pavel Pereslegin
>            Priority: Major
>              Labels: ise
>
> 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.
> Sample code for specifying "headers".
> {code:java}
> // Creating "execution context".
> Map<String, Object> execCtx = Collections.singletonMap("user.id", 1);
> // Binding "request headers" to proxy invocation handler.
> IMyService svcProxy = ignite.services().serviceProxy("service1", 
> IMyService.class, false, execCtx);
> // Service method invocation.
> svcProxy.multiply(2, 2);
> svcProxy.multiply(3, 3);
> svcProxy.multiply(4, 4);
> ...
> {code}
> Sample code for reading "headers".
> {code:java}
> class MyServiceImpl implements IMyService {
>     @LoggerResource
>     private IgniteLogger log;
>     private ServiceContext ctx;
>     @Override public void init(ServiceContext ctx) {
>         this.ctx = ctx;
>     }
>     @Override public int multiply(int a, int b) {
>         log.info(String.format("user=%d, oper=%s, a=%d, b=%d", 
> ctx.attr("user.id"), "multiply", a, b));
>         return a * b;
>     }
>     ...
> }
> {code}



--
This message was sent by Atlassian Jira
(v8.3.4#803005)

Reply via email to