Creating dynamic target endpoint by tenant and external configuration

nejra
Participant II

Hi,

I am trying to create rules for different routes and target endpoints based on tenants, so that the code below can be replaced with something more dynamic. I have two questions here:

1. How can I read supported tenants and their target endpoints from external file (i.e. file from git or by calling some API)? Is custom code in JS the only way?

2. Is the only way to add route rules dynamically via JS?

    <RouteRule name="routeToTenant1">
        <Condition>(tenantId = "tenant1")</Condition>
        <TargetEndpoint>tenant1</TargetEndpoint>
    </RouteRule>
    <RouteRule name="routeToTenant2">
        <Condition>(tenantId = "tenant2")</Condition>
        <TargetEndpoint>tenant2</TargetEndpoint>
    </RouteRule>
Solved Solved
0 3 381
1 ACCEPTED SOLUTION

@Nejra Husak

1. How can I read supported tenants and their target endpoints from external file (i.e. file from git or by calling some API)? Is custom code in JS the only way?

You could use a service call out if you have an API that can give you the tenants and the target mappings

Custom java callout can also be used if its more complex and you cant get the required data through service callout or JS httpclient

2. Is the only way to add route rules dynamically via JS?

Route rule conditions are preset in the proxy endpoint. Similar to the xml you have posted, the tenantId values tenant1, tenant2 etc are constants and preset.

JS or assign Message policy can be used to set the value of tenantId that you retrieve from the external file/API

View solution in original post

3 REPLIES 3

@Nejra Husak

1. How can I read supported tenants and their target endpoints from external file (i.e. file from git or by calling some API)? Is custom code in JS the only way?

You could use a service call out if you have an API that can give you the tenants and the target mappings

Custom java callout can also be used if its more complex and you cant get the required data through service callout or JS httpclient

2. Is the only way to add route rules dynamically via JS?

Route rule conditions are preset in the proxy endpoint. Similar to the xml you have posted, the tenantId values tenant1, tenant2 etc are constants and preset.

JS or assign Message policy can be used to set the value of tenantId that you retrieve from the external file/API

Thanks for your answer!

@Nejra Husak

Both the routerules and the Target endpoints are preset. So how do you plan to generate a separate target endpoint configuration for each tenant?

Can you give some additional information -

1. What does the external service return? Just the tenant or tenant+backend url+other details

2. Whatdo you have configured in each target endpoint? Do you have a different backend url only or do you have some custom policies/logic that is different for each tenant?

If it's just the url, you can have a single routerule to route to one target endpoint and then handle setting the Target url dynamically using JS in the Target endpoint.