rabbitmq - Spring amqp not publishing message to the queue but to Exchange -


i trying test & benchmark spring-amqp rabbitmq multiple queues creating rabbit template each queue , using send message. message sent successful , can see message published in exchange don't see in queue. guessing it's minor setting can't figure out.

this applicationcontext.xml

<bean id="banchmarkconnectionfactory" class="org.springframework.amqp.rabbit.connection.cachingconnectionfactory">         <constructor-arg ref="benchmarkamqphost"/>         <property name="username" ref="benchmarkamqpuser"/>         <property name="password" ref="benchmarkamqppass"/>         <property name="virtualhost" ref="benchmarkamqpvhost"/>         <property name="channelcachesize" value="10"/> </bean> <rabbit:template id="benchmarkamqptemplate"         connection-factory="banchmarkconnectionfactory"         exchange="my_exchange"         queue="benchmarkqueue"         routing-key="benchmarkqueue" /> <rabbit:admin connection-factory="banchmarkconnectionfactory"/> <rabbit:queue name="benchmarkqueue" auto-delete="true" durable="false" auto-declare="true"/> 

this code uses benchmarkamqptemplate publish queue.

public class publishmessage {     @autowired     private rabbittemplate benchmarkamqptemplate;      protected void publish(string payload) {         benchmarkamqptemplate.setqueue("benchmarkqueue");         benchmarkamqptemplate.convertandsend("my_exchange", "benchmarkqueue", payload);      } } 

when used helloworld example did publish message in queue wondering if doing wrong. update able solve adding direct-exchange tag in context xml. full xml looks this:

    <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.xsdhttp://www.springframework.org/schema/rabbit http://www.springframework.org/schema/rabbit/spring-rabbit.xsd">  <bean id="banchmarkconnectionfactory" class="org.springframework.amqp.rabbit.connection.cachingconnectionfactory">             <constructor-arg ref="benchmarkamqphost"/>             <property name="username" ref="benchmarkamqpuser"/>             <property name="password" ref="benchmarkamqppass"/>             <property name="virtualhost" ref="benchmarkamqpvhost"/>             <property name="channelcachesize" value="10"/>     </bean>     <rabbit:template id="benchmarkamqptemplate"             connection-factory="banchmarkconnectionfactory"             exchange="my_exchange"             queue="benchmarkqueue"             routing-key="benchmarkqueue" />     <rabbit:admin connection-factory="banchmarkconnectionfactory"/>     <rabbit:queue name="benchmarkqueue" auto-delete="true" durable="false" auto-declare="true"/>     <rabbit:direct-exchange name="my_exchange">         <rabbit:bindings>             <rabbit:binding queue="benchmarkqueue" key="benchmarkqueue" />         </rabbit:bindings>     </rabbit:direct-exchange> </beans> 

sorry, looks misunderstood amqp protocol bit.

the message published exchange proper routingkey. publisher (rabbittemplate) doesn't need know queues @ all.

the queue part of receiver, subscriber queue.

there 1 more feature in between - binding. queue bound exchange under appropriate routingkey. 1 queue can bound several exchanges different routing keys. default queues bound default exchange ("") routingkeys equal names.

please, refer more info rabbitmq site.


Comments