Search code examples
javajwts4sdksap-cloud-sdk

How to access destination service which is behind RabbitMQ using S4 Cloud SDK Connectivity


We are using S4SDK to access destination service. it needs to work in multi-tenancy env. Normally if the app is a frontend app, the request context is triggered by user request. Accessing destination service with multi-tenancy is doable with approuter and XUAA. In our case, our application is behind RabbitMQ which is not trigger by a user request (e.g. REST API call). Currently we are using the class com.sap.cloud.sdk.cloudplatform.connectivity.DestinationAccessor from cloud SDK. we can retrieve a tenant id out of message (RabbitMQ/AMQP). The issue is that we cannot find a way to inject the tenant id or clone a JWT token into DestinationAccessor from S4SDK. We look for a way/guidance of how to achieve that. We expect this exchange/clone token is provided by the SDK.


Solution

  • You should be able to use the JwtBasedRequestContextExecutor for this purpose.

    new JwtBasedRequestContextExecutor()
        .withJwt(encodedJwt)
        .execute(() -> {
            // code using the SAP Cloud SDK
        });