I had a sample that works for Spring AMQP 1.0.0.M1
I ported it to 1.0.0.M3. There are classes that had been removed. That's fine. I managed to adapt it with the new changes.
Using the 1.0.0.M1 sample project I'm able to send and receive messages. But with 1.0.0.M3, I can only send but I cannot receive.
I know that my 1.0.0.M3 app is able to send because running a receiver app (based on 1.0.0.M1) is able to receive that message.
So I think the problem is the configuration of the receiver or the listener for 1.0.0.M3
Here are the configs:
1.0.0.M1 Sample Project
Client.java
MessageSender.javaCode:package org.spring.amqp.client; import org.springframework.amqp.core.AmqpAdmin; import org.springframework.amqp.core.Queue; import org.springframework.context.ApplicationContext; import org.springframework.context.support.ClassPathXmlApplicationContext; public class Client { public static void main(String[] args) { ApplicationContext applicationContext = new ClassPathXmlApplicationContext("applicationContext.xml", Client.class); MessageSender sender = (MessageSender) applicationContext.getBean("messageSender"); sender.send("Hello Spring AMQP!"); } }
MessageHandler.javaCode:package org.spring.amqp.client; import javax.annotation.Resource; import org.apache.log4j.Logger; import org.springframework.amqp.core.AmqpTemplate; import org.springframework.amqp.rabbit.core.RabbitTemplate; public class MessageSender { protected Logger logger = Logger.getLogger("client"); @Resource(name="rabbitTemplate") private RabbitTemplate rabbitTemplate; public void send(String text) { rabbitTemplate.convertAndSend(text); logger.debug("Message sent: " + text); } }
applicationContext.xmlCode:package org.spring.amqp.client; import org.apache.log4j.Logger; import org.springframework.amqp.core.Message; import org.springframework.amqp.core.MessageListener; public class MessageHandler implements MessageListener { protected Logger logger = Logger.getLogger("client"); @Override public void onMessage(Message message) { logger.debug("Client: Message received!"); System.out.println("Received message: " + message); System.out.println("Text: " + new String(message.getBody())); } }
This assumes you have a queue name "hello"Code:<bean id="rabbitConnectionFactory" class="org.springframework.amqp.rabbit.connection.SingleConnectionFactory" p:username="guest" p:password="guest" p:port="5672"> <constructor-arg value="localhost" /> </bean> <bean id="rabbitTemplate" class="org.springframework.amqp.rabbit.core.RabbitTemplate" p:connectionFactory-ref="rabbitConnectionFactory" p:routingKey="hello"/> <bean id="messageSender" class="org.spring.amqp.client.MessageSender" /> <bean class="org.springframework.amqp.rabbit.listener.SimpleMessageListenerContainer" p:connectionFactory-ref="rabbitConnectionFactory" p:queueName="hello" p:messageListener-ref="messageListener" /> <bean id="messageListener" class="org.spring.amqp.client.MessageHandler" />
1.0.0.M3 Sample Project
Everything is the same. I just had to add the aopalliance.jar
Note:
There are no errors or exceptions. Setting the logger to DEBUG level doesn't show any odd output. It just shows that it's able to send. As mentioned earlier, a receiver based on 1.0.0.M1 is able to receive messages published by 1.0.0.M3
I'm using the latest RabbitMQ Server 2.3.1.


Reply With Quote