Forwarding based on DNS name

40 views
Skip to first unread message

arra...@gmail.com

unread,
Feb 22, 2017, 2:50:04 PM2/22/17
to membrane-monitor
We have two different DNS entries pointing to the same set of AWS endpoint - say abc.com and def.com. How should the configuration in proxies.xml look like in order to have the requests from abc.com routed to a different cluster in the backend? The "path" element only forwards by the url stub, and does not consider host names, right? Therefore in this case, the path cannot be used?

Till Born

unread,
Mar 20, 2017, 8:17:07 AM3/20/17
to membrane-monitor
Hello ramiah ariya,
sorry for the late response. If i understand you correctly you would like to decide the target of a service proxy dynamically based on the original Host header. You could take the following configuration as a basis for your undertaking
<spring:beans xmlns="http://membrane-soa.org/proxies/1/"
   xmlns:spring="http://www.springframework.org/schema/beans"
   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
   xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
                   http://membrane-soa.org/proxies/1/ http://membrane-soa.org/schemas/proxies-1.xsd">

   
<router>

     
<serviceProxy port="5559">
         
<groovy>
            String host = exc.getOriginalHostHeaderHost()
            String destination = null
            if("abc.com".equals(host))
            destination = "https://predic8.com"
            if("def.com".equals(host))
            destination = "https://google.com"
            if(destination == null)
            destination = "https://defaultDomain.com"

            exc.getDestinations().clear()
            exc.getDestinations().add(destination + exc.getOriginalRequestUri())

            CONTINUE
         
</groovy>
     
</serviceProxy>
   
</router>

</spring:beans>
This adds a groovy interceptor to a service proxy that does the following:
- get the original host header
- get the wanted destination based on this host value, or get a default destination
- configure the exchange target dynamically

With this you don't need a target node for this service proxy as the target is set by this groovy interceptor.
Wish you all the best,
Till

tim.b...@devopsmakers.com

unread,
May 18, 2017, 5:55:07 AM5/18/17
to membrane-monitor
This is pretty cool. I'm sure you could do something like this with a map too:
<spring:beans xmlns="http://membrane-soa.org/proxies/1/"
   xmlns:spring="http://www.springframework.org/schema/beans"
   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
   xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
                   http://membrane-soa.org/proxies/1/ http://membrane-soa.org/schemas/proxies-1.xsd">

   <router>

      <serviceProxy port="5559">
         <groovy>
            String host = exc.getOriginalHostHeaderHost()
            String destination = null
            def vhosts = [ abc.com:"https://predic8.com",
                           def.com:"https://google.com"]

            destination = vhosts.get(host, "https://defaultDomain.com")


            exc.getDestinations().clear()
            exc.getDestinations().add(destination + exc.getOriginalRequestUri())

            CONTINUE
         </groovy>
      </serviceProxy>
   </router>

</spring:beans>
Reply all
Reply to author
Forward
0 new messages