title: Failover and KeepAlive in Spring Integration
body: <p>Similarly to the question asked at <a href="https://stackoverflow.com/questions/17597241/how-can-i-define-a-failover-spring-integration-gateway">How can I define a failover spring integration gateway?</a>
  I have to implement the failover feature, however my expactations are different.</p>
  
  <p>I have two brokers: primary and secondary and one service that is running on the same servers either in PRIMARY or BACKUP mode. Synchronization of internal data is performed using SYNC queue.</p>
  
  <p>Within the service I would like to implement following functionality with Spring Integration:</p>
  
  <ul>
  <li><p>Each 1Q, 2Q, 3Q, ..., 5Q queue has a receiver and 1SQ queue has a sender. Both receiver and sender operate with primary broker (already implemented in Spring using message gateway &amp; router for sender, and service activator for receiver). </p></li>
  <li><p>When a message from 1Q-5Q is received a new message is sent to 1SQ (this already works). In the same time the update of internal data is sent to SYNC queue. This way the interal data structures are synchronized in case of a failover. </p></li>
  <li><p>external module sends to the 1Q queue of the primary broker additional KeepAlive Message. If the message is not received after N secs. the new receiver and sender should be launched that operate with secondary broker. This way the receiver/sender take on the functionality of the primary broker.</p></li>
  </ul>
  
  <p><strong>Questions:</strong> </p>
  
  <p>Obviously round-robin strategy is not suitable. Also automatic selection of secondary server as in  <a href="https://stackoverflow.com/questions/17597241/how-can-i-define-a-failover-spring-integration-gateway">question</a> is not the way to go. That is why keepAlive message was chosen to detect whether the primary broker is down. Is it possible to have this functionality with Spring Integration? To be more precise:</p>
  
  <ol>
  <li>how to implement the switching between primary and secondary server for my senders/receivers when the keepAlive message is not received by the primary server?</li>
  <li>Is it possible to switch back to primary server when it is up&amp;running again?</li>
  </ol>