How to achieve code-first routing based on http body? #1957
-
Hi, I read through the documentation (https://ocelot.readthedocs.io/en/latest/) but could not find out how to route the request to downstream service based on the content of the request within code. For example, we have a caller application A, which consumes a web service (asmx) that provides by API application B (that exposes the APIs as SOAP). Now we want to develop a new version to gradually substitute the APIs with a new application C. So we are planning to use Ocelot to do like this:
The and routing should be based on some biz logic (code-first, not based on static configuration file), and the biz logic would be: read the body of the SOAP content, based on some biz logic, it would determine to route to Application B or Application C. For example: <soapenv:Header>
<wsse:Security xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd"
xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd">
<wsse:Request wsu:Id="UsernameToken-zzzzzz">
<wsse:Username>test user</wsse:Username>
<wsse:Category Type="Foo">xxxxyy</wsse:Category>
<wsu:Created>2020-05-05T13:42:06.798Z</wsu:Created>
</wsse:Request >
</wsse:Security>
</soapenv:Header> The biz logic is to read the Category, if it is Foo then forward to Application B, otherwise forward to Application C. Can you please advise how to achieve this in Ocelot? Thanks. |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 1 reply
-
Did you tried implementing a custom |
Beta Was this translation helpful? Give feedback.
-
Business logic can be implemented inside of custom Delegating Handler. Finally, in your user scenario when you have to decide on request forwarding, custom Load balancer is more appropriate design. |
Beta Was this translation helpful? Give feedback.
Did you tried implementing a custom
ILoadBalancer
for this? You technically have access to a fullDownstreamContext
in there which you can use to route your requests appropriately.