Search code examples
springrabbitmqamqp

RabbitMQ high availability with Spring AMQP


I'm trying to configure a RabbitMQ cluster in Spring, so I followed the Spring AMQP docs (http://docs.spring.io/spring-amqp/reference/html/amqp.html), but I get an error when adding addresses:

<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:rabbit="http://www.springframework.org/schema/rabbit"
xsi:schemaLocation="http://www.springframework.org/schema/beans
                    http://www.springframework.org/schema/beans/spring-beans-3.1.xsd
                    http://www.springframework.org/schema/rabbit
                    http://www.springframework.org/schema/rabbit/spring-rabbit-1.0.xsd">

<rabbit:connection-factory id="connectionFactory" addresses="host1,host2" />

The dependencies I defined in gradle:

compile group: 'org.springframework.amqp', name: 'spring-amqp', version:'1.2.0.RELEASE'
compile group: 'org.springframework.amqp', name: 'spring-rabbit', version:'1.2.0.RELEASE'

Anyone has any idea why this is happening? Thanks!

Edit: The error I get is: cvc-complex-type.3.2.2: Attribute 'addresses' is not allowed to appear in element 'rabbit:connection-factory'. host1 & host2 are IPs of virtual machines.


Solution

  • This happens because you declared spring-rabbit XSD file in schemaLocation for version 1.0. Just change:

    http://www.springframework.org/schema/rabbit/spring-rabbit-1.0.xsd

    to

    http://www.springframework.org/schema/rabbit/spring-rabbit-1.2.xsd

    to match your spring-rabbit version, and it should work.