Announcement Announcement Module
Collapse
No announcement yet.
Failover with a cluster Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Failover with a cluster

    Hi,

    So currently i have three individual rabbitmq nodes hosted in different locations, with 6 producers and 3 consumers.

    The way the produces and consumers are configured at the moment is that each one connects to the node that is hosted in the same location.

    Ie
    1x node hosted in say london
    1x consumer in london
    2x producers in london

    and a similar setup in two other locations
    thus i build up a connection string based on where the producer/consumer is hosted like so
    Code:
    <rabbit:connection-factory id="connectionFactory" host="#{systemProperties.app_location}${rabbit.host}"port="${rabbit.port}" username="${rabbit.username}"	password="${rabbit.password}" />
    where app_location resolves to the first part of a host name (loc)
    and rabbit.host is the remainder (-randomplace-p1)
    to give loc-randomplace-p1 (this resolves to an ip from my host file)

    I use the following dependincies spring-rabbit 1.1.3.RELEASE, spring-integration-core 2.1.3.RELEASE and spring-integration-amqp 2.1.3.RELEASE

    however i would like to turn the 3 nodes (and possibly add more in the future) into a cluster so they appear conceptually as one node to both consumer and producer.

    now my questions are.
    1) Would the configuration to connect just be a list of the node names
    eg host="server1,server2,server3"
    2) Then when i connect to the cluster and the node i am connected to goes down, does amqp handdle the reconnect logic for me? i don't want to be in a situation where a node that a consumer is connected to goes down, it reconnects and starts consuming from a new node but sends ack's to the old node?

  • #2
    Hello!

    Let's start from here: http://static.springsource.org/sprin...qp.html#d4e152
    and this sample
    HTML Code:
    <rabbit:connection-factory id="connectionFactory" addresses="host1:5672,host2:5672" />
    HTH,
    Artem

    Comment


    • #3
      Originally posted by Cleric View Post
      Hello!

      Let's start from here: http://static.springsource.org/sprin...qp.html#d4e152
      and this sample
      HTML Code:
      <rabbit:connection-factory id="connectionFactory" addresses="host1:5672,host2:5672" />
      HTH,
      Artem
      Ok so i guess that answers the first question i can just list the ip's with the addresses property.

      Second question is still the same, if the node you connected to goes offline, will amqp automatically switch to the next available (oldest) node? or do i have to do i have to code that logic into the app?

      Basically can i just change the app to point to a cluster with out changing any of the logic to consume and produce messages and in the event of a node going down have amqp reconnect for me?

      Comment


      • #4
        will amqp automatically switch to the next available
        Yes, it does: com.rabbitmq.client.ConnectionFactory#newConnectio n
        Regarding failover on Broker, you should configure your queues as clustered:
        http://www.rabbitmq.com/ha.html

        And, yes, you don't do anything in your application: everything is just configurable!

        Comment


        • #5
          Just one clarification; the consumers will automatically fail over; on the sending side, you have to catch the exception and retry, at which time the connection will be established with the first available broker.

          Comment


          • #6
            Ok so if this is my current Sending code

            Message entity; //object to send passed into the function
            ObjectMapper mapper = new ObjectMapper();
            amqpTemplate.convertAndSend("messaging.exchange", "message.high", mapper.writeValueAsString(entity));

            I would just need a try catch around the convert and send?

            so something like

            try{
            amqpTemplate.convertAndSend("messaging.exchange", "message.high", mapper.writeValueAsString(entity));
            }
            catch (Exception e) //not sure what the exact exception would be??
            {
            //resend here?
            }

            should this maybe be in a loop that tries x number of times until a successful send is made?

            Comment


            • #7
              So, the RetryTemplate is coming to you: http://static.springsource.org/sprin...qp.html#d4e557

              Comment

              Working...
              X