[rabbitmq-discuss] RabbitMQ and Spring
Arno Puschmann
arno.puschmann at acodeas.de
Tue Jul 26 08:27:13 BST 2011
Hi,
I'm trying to use RabbitMQ in a Spring Application. I have installed RabbitMQ Server 2.5.1 and using Spring 3.0.5.
I have the following Bean-Configuration
<bean id="rabbitConnFactory" class="org.springframework.amqp.rabbit.connection.SingleConnectionFactory">
<property name="host" value="localhost" />
<property name="username" value="guest" />
<property name="password" value="guest" />
<property name="virtualHost" value="/" />
<property name="port" value="5672" />
</bean>
<bean id="admin" class="org.springframework.amqp.rabbit.core.RabbitAdmin">
<constructor-arg ref="rabbitConnFactory" />
</bean>
<bean id="template" class="org.springframework.amqp.rabbit.core.RabbitTemplate">
<property name="connectionFactory" ref="rabbitConnFactory" />
<property name="routingKey" value="test.queue"/>
<property name="queue" value="junitqueue"/>
<property name="messageConverter" ref="messageConverter" />
</bean>
<bean id="messageListener" class="de.ami.ws.Queue.Receiver" />
Finally I want to access to my RabbitMQ-Server. So I Autowired my Properties and call
template.convertAndSend(object);
but after this there is no message on the queue and the no exception is thrown.
Trying the same with this Code then it works.
Connection connection = rabbitConnFactory.createConnection();
Channel channel = connection.createChannel(true);
channel.exchangeDeclare(EXCHANGE_NAME, "direct", true);
channel.queueDeclare(QUEUE_NAME, true, false, false, null);
channel.queueBind(QUEUE_NAME, EXCHANGE_NAME, ROUTING_KEY);
ByteArrayOutputStream baos = new ByteArrayOutputStream();
ObjectOutputStream oos;
oos = new ObjectOutputStream(baos);
oos.writeObject(object);
oos.close();
byte[] ByteMessage = baos.toByteArray();
channel.basicPublish(EXCHANGE_NAME, ROUTING_KEY, null, ByteMessage);
channel.close();
connection.close();
But this is not a solution for a Spring Application.
By the way i get a Exception if I try to use the Spring-AMQP-Cient-Version 2.5.1 im my pom.xml.
java.lang.IllegalAccessError: tried to access method com.rabbitmq.client.impl.AMQBasicProperties.<init>()V from class org.springframework.amqp.rabbit.support.RabbitUtils
at org.springframework.amqp.rabbit.support.RabbitUtils.extractBasicProperties(RabbitUtils.java:195)
at org.springframework.amqp.rabbit.core.RabbitTemplate.doSend(RabbitTemplate.java:332)
at org.springframework.amqp.rabbit.core.RabbitTemplate.access$000(RabbitTemplate.java:51)
at org.springframework.amqp.rabbit.core.RabbitTemplate$1.doInRabbit(RabbitTemplate.java:141)
at org.springframework.amqp.rabbit.core.RabbitTemplate.execute(RabbitTemplate.java:297)
at org.springframework.amqp.rabbit.core.RabbitTemplate.send(RabbitTemplate.java:139)
at org.springframework.amqp.rabbit.core.RabbitTemplate.convertAndSend(RabbitTemplate.java:156)
at org.springframework.amqp.rabbit.core.RabbitTemplate.convertAndSend(RabbitTemplate.java:148)
Have anybody some Experience or a solution?
Thanks.
Arno Puschmann
More information about the rabbitmq-discuss
mailing list