You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@synapse.apache.org by Song Thuy Nguyen <pr...@biaqua.de> on 2010/03/05 10:14:07 UTC

how to implement a Custom Failover

Hello everyone,

 

I would like to implement a customized failover in synapse. 

For example :

 

###################the  synapse.xml to look like this####################################

 

<definitions xmlns="http://ws.apache.org/ns/synapse">

      <registry provider="org.apache.synapse.registry.url.SimpleURLRegistry">     

            <parameter name="root">file:./repository/conf/registry/</parameter>    

            <parameter name="cachableDuration">5000</parameter>

      </registry>

      <in>

            <send>

                  <class name="org.namespace.xyz.ExtendedFailover">

                        <endpoint key="failoverendpoint.xml">

                  </class>

            </send>

      </in>

 

      <out>

            <send/>

      </out>

</definitions>

 

#####################the failoverenpoint.xml shoud be like:#########################

<endpoint xmlns="http://ws.apache.org/ns/synapse">

      <failover>

            <endpoint name="add1ep">

                  <address uri="http://127.0.0.1:1/add1">

                        <suspendDurationOnFailure>0</suspendDurationOnFailure>

                  </address>

                        

            </endpoint>

            <endpoint name="add2ep">

                  <address uri="http://127.0.0.1:2/add2">

                        <suspendDurationOnFailure>0</suspendDurationOnFailure>

                  </address>

 

            </endpoint>

            <endpoint name="add3ep">

                  <address uri="http://127.0.0.1:3/add3">

                        <suspendDurationOnFailure>0</suspendDurationOnFailure>

                  </address>

 

            </endpoint>

      </failover>

</endpoint>

 

#####################################the ExtendedFailover.java##########################

package org.namespace.xyz;

 

import org.apache.synapse.endpoints.FailoverEndpoint;

 

public class ExtendedFailoverMediator extends FailoverEndpoint{

 

      //override and reuse some methods here

 

 

}

###########################################################################################

 

I want to implement an alternate failover behaviour: on every call to the service it will try the first endpoint (add1) ,if that one fails, it will try the second one(add2). This repeats with every later calls, even if the first endpoint failed in the previous call. There will be a code block that uses the existing setActive(boolean active, MessageContext synMessageContext)method to set the current active endpoint, this is controlled by another component outside of Synapse.

And I also would like to have the possibility to sort the list of endpoints and write it back to the xml file in the registry. Looking at the methods provided by the FailoverEndpoint class, it seems I can reuse many of the existing methods. But where do I start?

If the ExtendedFailover class mediator derives from FailoverEndpoint and I put the <class ….></class> expression around the endpoint defintion block (like in the example above) , will this block be automatically read by the ExtendedFailover-Mediator like the original FailoverEndpoint would do, so that I can access the list of endpoints with getEndpoints()? Or do I habe to provide the Factory and Serializer classes for Synpase to do so?

Please give me jumpstart to do this.

 

Thank you in advance!

 

Greetings

 

Thuy

 

 


RE: how to implement a Custom Failover

Posted by Song Thuy Nguyen <pr...@biaqua.de>.
I have implement a quick and dirty way to have it work how I want it. I have added one little line of code in the FailoverEndpoint, compile and replace the old FailoverEndpoint.class in the synapse-core-1.2.jar.

Now each time a message arrives in the in sequence to be sent to the failoverendpoint, the failoverendpoint will always start with the 1st element of the endpoints list. The endpoints list is stored in the registry and can be manipulated from the outside.

If anyone is interested to have your failover work this way too, I can give you the alternated java file.

 

Greetings

 

Song Thuy Nguyen


Re: how to implement a Custom Failover

Posted by Supun Kamburugamuva <su...@gmail.com>.
At the moment synapse doesn't support custom endpoints.

I guess what you can do is to write a custom send mediator that takes uses
your custom endpoint.

Thanks,
Supun..

On Fri, Mar 5, 2010 at 2:44 PM, Song Thuy Nguyen <pr...@biaqua.de>wrote:

>  Hello everyone,
>
>
>
> I would like to implement a customized failover in synapse.
>
> For example :
>
>
>
> ###################the  synapse.xml to look like
> this####################################
>
>
>
> <definitions xmlns=*"http://ws.apache.org/ns/synapse"*>
>
>       <registry provider=*
> "org.apache.synapse.registry.url.SimpleURLRegistry"*>
>
>             <parameter name=*"root"*>file:./repository/conf/registry/</
> parameter>
>
>             <parameter name=*"cachableDuration"*>5000</parameter>
>
>       </registry>
>
>       <in>
>
>             <send>
>
>                   <class name="org.namespace.xyz.ExtendedFailover">
>
>                         <endpoint key="failoverendpoint.xml">
>
>                   </class>
>
>             </send>
>
>       </in>
>
>
>
>       <out>
>
>             <send/>
>
>       </out>
>
> </definitions>
>
>
>
> #####################the failoverenpoint.xml shoud be
> like:#########################
>
> <endpoint xmlns=*"http://ws.apache.org/ns/synapse"*>
>
>       <failover>
>
>             <endpoint name=*"add1ep"*>
>
>                   <address uri=*"http://127.0.0.1:1/add1"*>
>
>                         <suspendDurationOnFailure>0</
> suspendDurationOnFailure>
>
>                   </address>
>
>
>
>             </endpoint>
>
>             <endpoint name=*"add2ep"*>
>
>                   <address uri=*"http://127.0.0.1:2/add2"*>
>
>                         <suspendDurationOnFailure>0</
> suspendDurationOnFailure>
>
>                   </address>
>
>
>
>             </endpoint>
>
>             <endpoint name=*"add3ep"*>
>
>                   <address uri=*"http://127.0.0.1:3/add3"*>
>
>                         <suspendDurationOnFailure>0</
> suspendDurationOnFailure>
>
>                   </address>
>
>
>
>             </endpoint>
>
>       </failover>
>
> </endpoint>
>
>
>
> #####################################the
> ExtendedFailover.java##########################
>
> package org.namespace.xyz;
>
> * *
>
> *import* org.apache.synapse.endpoints.FailoverEndpoint;
>
> * *
>
> *public* *class* ExtendedFailoverMediator *extends* FailoverEndpoint{
>
>
>
>       //override and reuse some methods here
>
>
>
>
>
> }
>
>
> ###########################################################################################
>
>
>
> I want to implement an alternate failover behaviour: on every call to the
> service it will try the first endpoint (add1) ,if that one fails, it will
> try the second one(add2). This repeats with every later calls, even if the
> first endpoint failed in the previous call. There will be a code block that
> uses the existing setActive(boolean active, MessageContext
> synMessageContext)method to set the current active endpoint, this is
> controlled by another component outside of Synapse.
>
> And I also would like to have the possibility to sort the list of endpoints
> and write it back to the xml file in the registry. Looking at the methods
> provided by the FailoverEndpoint class, it seems I can reuse many of the
> existing methods. But where do I start?
>
> If the ExtendedFailover class mediator derives from FailoverEndpoint and I
> put the <class ….></class> expression around the endpoint defintion block
> (like in the example above) , will this block be automatically read by the
> ExtendedFailover-Mediator like the original FailoverEndpoint would do, so
> that I can access the list of endpoints with getEndpoints()? Or do I habe to
> provide the Factory and Serializer classes for Synpase to do so?
>
> Please give me jumpstart to do this.
>
>
>
> Thank you in advance!
>
>
>
> Greetings
>
>
>
> Thuy
>
>
>
>
>



-- 
Software Engineer, WSO2 Inc
http://wso2.org
supunk.blogspot.com