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

試著忘記壹切 提交于 2019-12-24 13:27:40

问题


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.


回答1:


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>



回答2:


There's no support for provisioning (declaring) plugin exchanges with Spring AMQP but you can send messages to any exchange type that is configured on the server.

Just add the exchange directly to rabbitmq and then send messages to it like you would to any exchange.

See the reference documentation for how to use Spring AMQP; it has links to samples etc.



来源:https://stackoverflow.com/questions/31141955/rabbitmq-consistent-hash-exchange-with-java-client-spring-rabbit

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!