I am trying to configure Spring MVC & RabbitMQ in Java. I have the following Configuration File (servlet-context.xml).
<?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:mvc="http://www.springframework.org/schema/mvc" xmlns:context="http://www.springframework.org/schema/context" xmlns:rabbit="http://www.springframework.org/schema/rabbit" xsi:schemaLocation="http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd http://www.springframework.org/schema/rabbit http://www.springframework.org/schema/rabbit/spring-rabbit-1.0.xsd" default-autowire="byName"> <context:component-scan base-package="com.appirio.messaginghub"/> <mvc:annotation-driven/> <mvc:resources location="file:./src/main/resources/static/,classpath:/ static/" mapping="static/**"/> <context:property-placeholder/> <bean id="rabbitConnectionFactory" class="org.springframework.amqp.rabbit.connection.CachingConnectionFactory"> <!-- This constructor arg utilizes the RabbitFactoryUtil class shown in the java example above --> <constructor- arg><value>#{ T(com.appirio.messaginghub.RabbitFactoryUtil).getConnectionFactory()} </value></constructor-arg> </bean> <bean id="mylistener" class="com.appirio.messaginghub.MyMessageListener"/> <rabbit:queue id="sample-queue"/> <rabbit:fanout-exchange name="sample-exchange"> <rabbit:bindings> <rabbit:binding queue="sample-queue"/> </rabbit:bindings> </rabbit:fanout-exchange> <rabbit:admin connection-factory="rabbitConnectionFactory"/> <rabbit:listener-container> <rabbit:listener queues="sample-queue" ref="mylistener"/> </rabbit:listener-container> <bean id="template" class="org.springframework.amqp.rabbit.core.RabbitTemplate"> <property name="connectionFactory" ref="rabbitConnectionFactory"/> <property name="exchange" value="sample-exchange"/> <property name="queue" value="sample-queue"/> <property name="routingKey" value="sample-key"/> </bean> </beans> I am able to post a message successfully to RabbitMQ in my controller via this code: ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext("**/servlet-context.xml"); RabbitTemplate rabbitTemplate = ctx.getBean(RabbitTemplate.class); rabbitTemplate.send(new Message("sample message".getBytes("UTF-8"), new MessageProperties())); I have written a listener class as shown below: package com.appirio.messaginghub; import org.apache.log4j.Logger; import org.springframework.amqp.core.Message; import org.springframework.amqp.core.MessageListener; public class MyMessageListener implements MessageListener { @Override public void onMessage(Message message) { Logger barlogger = Logger.getLogger("someclass"); barlogger.info("onMessage is invoked"); } } And this class is referenced correctly in the servlet-context.xml Spring configuration file. ISSUE : The Listener is never getting called. Any hints on what I might be doing wrong. I see the following error log via heroku logs: 2012-04-16T17:44:23+00:00 app[web.1]: org.springframework.amqp.rabbit.listener.F atalListenerStartupException: Cannot prepare queue for listener. Either the queu e doesn't exist or the broker will not allow us to use it. 2012-04-16T17:44:23+00:00 app[web.1]: Caused by: java.io.IOException 2012-04-16T17:44:23+00:00 app[web.1]: at com.rabbitmq.client.impl.AMQChannel.w rap(AMQChannel.java:102) 2012-04-16T17:44:23+00:00 app[web.1]: at com.rabbitmq.client.impl.AMQChannel.e xnWrappingRpc(AMQChannel.java:126) 2012-04-16T17:44:23+00:00 app[web.1]: at com.rabbitmq.client.impl.ChannelN.que ueDeclarePassive(ChannelN.java:717) 2012-04-16T17:44:23+00:00 app[web.1]: at sun.reflect.NativeMethodAccessorImpl. invoke0(Native Method) 2012-04-16T17:44:23+00:00 app[web.1]: at java.lang.reflect.Method.invoke(Metho d.java:616) 2012-04-16T17:44:23+00:00 app[web.1]: at org.springframework.amqp.rabbit.conne ction.CachingConnectionFactory $CachedChannelInvocationHandler.invoke(CachingConn ectionFactory.java:298) 2012-04-16T17:44:23+00:00 app[web.1]: at org.springframework.amqp.rabbit.liste ner.BlockingQueueConsumer.start(BlockingQueueConsumer.java:188) 2012-04-16T17:44:23+00:00 app[web.1]: at $Proxy12.queueDeclarePassive(Unknown Source) 2012-04-16T17:44:23+00:00 app[web.1]: ... 2 more 2012-04-16T17:44:23+00:00 app[web.1]: at com.rabbitmq.utility.ValueOrException .getValue(ValueOrException.java:67) 2012-04-16T17:44:23+00:00 app[web.1]: at com.rabbitmq.client.impl.AMQChannel.p rivateRpc(AMQChannel.java:214) 2012-04-16T17:44:23+00:00 app[web.1]: at com.rabbitmq.client.impl.AMQChannel.e xnWrappingRpc(AMQChannel.java:120) 2012-04-16T17:44:23+00:00 app[web.1]: ... 11 more 2012-04-16T17:44:23+00:00 app[web.1]: Caused by: com.rabbitmq.client.ShutdownSig nalException: channel error; reason: {#method<channel.close>(reply- code=404, rep ly-text=NOT_FOUND - no queue '7de7b588-49cb-45db-8a06-4ae239898707' in vhost 'ig deesju', class-id=50, method-id=10), null, "[B@1fbbc779"} 2012-04-16T17:44:23+00:00 app[web.1]: at com.rabbitmq.client.impl.ChannelN.pro cessAsync(ChannelN.java:263) 2012-04-16T17:44:23+00:00 app[web.1]: WARN : org.springframework.amqp.rabbit.lis tener.SimpleMessageListenerContainer - Consumer raised exception, processing can restart if the connection factory supports it. Exception summary: org.springfra mework.amqp.AmqpIOException: java.io.IOException 2012-04-16T17:44:23+00:00 app[web.1]: ERROR: org.springframework.amqp.rabbit.lis tener.SimpleMessageListenerContainer - Consumer received fatal exception on star tup 2012-04-16T17:44:23+00:00 app[web.1]: at com.rabbitmq.client.impl.ChannelN.que ueDeclarePassive(ChannelN.java:61) 2012-04-16T17:44:23+00:00 app[web.1]: Caused by: com.rabbitmq.client.ShutdownSig nalException: channel error; reason: {#method<channel.close>(reply- code=404, rep ly-text=NOT_FOUND - no queue '7de7b588-49cb-45db-8a06-4ae239898707' in vhost 'ig deesju', class-id=50, method-id=10), null, "[B@1fbbc779"} 2012-04-16T17:44:23+00:00 app[web.1]: at org.springframework.amqp.rabbit.liste ner.SimpleMessageListenerContainer $AsyncMessageProcessingConsumer.run(SimpleMess ageListenerContainer.java:489) 2012-04-16T17:44:23+00:00 app[web.1]: at com.rabbitmq.client.impl.ChannelN.asy ncShutdown(ChannelN.java:423) 2012-04-16T17:44:23+00:00 app[web.1]: at org.springframework.amqp.rabbit.liste ner.BlockingQueueConsumer.start(BlockingQueueConsumer.java:192) 2012-04-16T17:44:23+00:00 app[web.1]: at sun.reflect.NativeMethodAccessorImpl. invoke(NativeMethodAccessorImpl.java:57) 2012-04-16T17:44:23+00:00 app[web.1]: at com.rabbitmq.utility.BlockingValueOrE xception.uninterruptibleGetValue(BlockingValueOrException.java:33) 2012-04-16T17:44:23+00:00 app[web.1]: at com.rabbitmq.client.impl.AMQChannel.h andleCompleteInboundCommand(AMQChannel.java:146) 2012-04-16T17:44:23+00:00 app[web.1]: at java.lang.Thread.run(Thread.java:636) 2012-04-16T17:44:23+00:00 app[web.1]: at sun.reflect.DelegatingMethodAccessorI mpl.invoke(DelegatingMethodAccessorImpl.java:43) 2012-04-16T17:44:23+00:00 app[web.1]: at com.rabbitmq.client.impl.AMQChannel$B lockingRpcContinuation.getReply(AMQChannel.java:341) 2012-04-16T17:44:23+00:00 app[web.1]: at com.rabbitmq.client.impl.AMQConnectio n$MainLoop.run(AMQConnection.java:482) 2012-04-16T17:44:23+00:00 app[web.1]: at com.rabbitmq.client.impl.AMQChannel.h andleFrame(AMQChannel.java:91) -- You received this message because you are subscribed to the Google Groups "Heroku" group. To post to this group, send email to [email protected]. To unsubscribe from this group, send email to [email protected]. For more options, visit this group at http://groups.google.com/group/heroku?hl=en.
