Saturday, July 28, 2012

Route to an endpoint based on the time of the day - Using ESB

This can be achieved with the use of Switch Case Mediator. Following proxy service will route to an endpoint based on the time of the day.

<proxy xmlns="http://ws.apache.org/ns/synapse" name="Proxy1" transports="https,http" statistics="disable" trace="disable" startOnLoad="true">
   <target>
      <inSequence>
         <switch xmlns:ns="http://org.apache.synapse/xsd" xmlns:ns3="http://org.apache.synapse/xsd" source="get-property('SYSTEM_DATE', 'HH')">
            <case regex="10">
               <log level="custom">
                  <property name="system-time" expression="get-property('SYSTEM_DATE', 'HH')" />
               </log>
               <send>
                  <endpoint>
                     <address uri="http://localhost:8280/services/Version" format="get" />
                  </endpoint>
               </send>
            </case>
         </switch>
      </inSequence>
      <outSequence>
         <send />
      </outSequence>
      <endpoint>
         <address uri="http://localhost:8280/services/Version" />
      </endpoint>
   </target>
   <publishWSDL uri="http://localhost:8280/services/Version?wsdl" />
</proxy> 

No comments:

Post a Comment

Using Zotero for academic writing