Search code examples
rabbitmqspring-rabbit

rabbitmq-consistent-hash-exchange with java-client / spring-rabbit


I would like to use the capabilities of rabbitmq-consistent-hash-exchange from java client or preferably by using the spring abstraction spring-amqp. Unfortunately I failed to found an example that explain the java usage and reference a jar dependency to include, please advice.


Solution

  • There is no specific tag for "x-" exchanges. Use CustomExchange for it:

       <bean id="requestHashExchangeTest" class="org.springframework.amqp.core.CustomExchange">
            <constructor-arg name="name" value="test.hash.RequestExchange"/>
            <constructor-arg name="type" value="x-consistent-hash"/>
            <constructor-arg name="durable" value="true"/>
            <constructor-arg name="autoDelete" value="false"/>
            <property name="adminsThatShouldDeclare">
                <list>
                    <ref bean="rabbitAdminConnectionFactory" />
                </list>
            </property>
        </bean>
    
        <bean name="binding"  class="org.springframework.amqp.rabbit.config.BindingFactoryBean">
            <property name="exchange" value="test.random.RequestExchange" />
            <property name="destinationQueue" ref="request.queue" />
            <property name="shouldDeclare" value="true" />
            <property name="adminsThatShouldDeclare">
                <list>
                    <ref bean="rabbitAdminConnectionFactory" />
                </list>
            </property>
            <property name="routingKey" value="10" />
        </bean>