Route to different hosts based on another http api result

40 views
Skip to first unread message

Ho Felix

unread,
Jul 21, 2016, 6:07:44 AM7/21/16
to membrane-monitor
hi,

Just wonder if it is possible to implement an api checking in serviceProxy and the api result decides which target host to go.  

How can this be done in proxies.xml?



<serviceProxy>

<! --    if http://checkapi returns '1'  -->

<target host="host_success"/> 

<! --    else if http://checkapi returns '0'  -->

<target host="host_fail"/>

</serviceProxy>


Thanks in advance,
Felix

Thomas Bayer

unread,
Jul 21, 2016, 6:13:10 AM7/21/16
to membrane...@googlegroups.com

Hi Felix,

just use an Groovy interceptor, call the API and set the destinations list accordingly. Have a look at the code oft he ContentBasedRouter interceptor for reverece:

 

https://github.com/membrane/service-proxy/blob/master/core/src/main/java/com/predic8/membrane/core/interceptor/cbr/XPathCBRInterceptor.java

 

Look at line 73 & 74.

 

Cheers,

Thomas

 

Am 21.07.16, 12:06 schrieb "Ho Felix" <membrane...@googlegroups.com im Auftrag von felix...@gmail.com>:

--
You received this message because you are subscribed to the Google Groups "membrane-monitor" group.
To unsubscribe from this group and stop receiving emails from it, send an email to membrane-monit...@googlegroups.com.
To post to this group, send email to membrane...@googlegroups.com.
Visit this group at https://groups.google.com/group/membrane-monitor.
For more options, visit https://groups.google.com/d/optout.

Till Born

unread,
Jul 22, 2016, 7:31:06 AM7/22/16
to membrane-monitor
Hello Felix,
i just had a similar problem and i solved it like this:
<groovy>
[...]
      exc.getDestinations().clear();
      exc.getDestinations().add("http://yourTarget:port" + exc.getOriginalRequestUri());
      return CONTINUE;
</groovy>
[...]
This is how you set the destination of the exchange directly, just like Thomas hinted. You can then leave out the "target" in the service proxy.

Reply all
Reply to author
Forward
0 new messages