Spring引导用于远程队列的Rabbitmq配置

时间:2017-04-18 11:59:20

标签: spring spring-boot rabbitmq spring-rabbitmq

我需要配置我的应用程序,以便从/向位于anoter服务器上的队列发送和使用消息。我在我的application.properties:

中有以下配置
spring.rabbitmq.host=amqp://cloudamqp.com/...
spring.rabbitmq.port=5672
spring.rabbitmq.username=jpkszgmu
spring.rabbitmq.password=***********************

在我的控制器中:

@Autowired
private RabbitTemplate rabbitTemplate;

@RequestMapping
public void send(@RequestParam String expediteur, @RequestParam String destinateur, @RequestParam String contenu){

    int i = 1;
    SMS s = new SMS("SMS00"+i, expediteur, destinateur, contenu);
    this.rabbitTemplate.convertAndSend(MeService.queueName, s);
}

和听众:

@RabbitListener(queues = queueName)
public void process(@Payload SMS s){
    System.out.println("SMS Recus: "+s.toString());
    r.send(s);
}

然而,我收到错误的说法 通过字段“兔子模板”表达的不满意的依赖性;嵌套异常是org.springframework.beans.factory.UnsatisfiedDependencyException ..

任何帮助?

完整跟踪错误

  

org.springframework.beans.factory.UnsatisfiedDependencyException:使用名称' meController创建bean时出错:通过字段' rabbitTemplate'表达的不满意依赖性嵌套异常是org.springframework.beans.factory.UnsatisfiedDependencyException:创建名称为' rabbitTemplate'的bean时出错在类路径资源中定义[org / springframework / boot / autoconfigure / amqp / RabbitAutoConfiguration $ RabbitTemplateConfiguration.class]:通过方法' rabbitTemplate'表达的不满意的依赖关系参数0;嵌套异常是org.springframework.beans.factory.BeanCreationException:创建名称为' rabbitConnectionFactory'的bean时出错在类路径资源中定义[org / springframework / boot / autoconfigure / amqp / RabbitAutoConfiguration $ RabbitConnectionFactoryCreator.class]:通过工厂方法的Bean实例化失败;嵌套异常是org.springframework.beans.BeanInstantiationException:无法实例化[org.springframework.amqp.rabbit.connection.CachingConnectionFactory]:工厂方法' rabbitConnectionFactory'抛出异常;嵌套异常是java.lang.NumberFormatException:对于输入字符串:" // jpkszgmu:1VfGR2I6AmJ7D8ySJU7PdFKJLf085wkI@penguin.rmq.cloudamqp.com/jpkszgmu:5672"

更新3

ERROR 8392 --- [cTaskExecutor-1] o.s.a.r.l.SimpleMessageListenerContainer:无法检查/重新声明自动删除队列。

org.springframework.amqp.AmqpIOException:java.io.IOException     在org.springframework.amqp.rabbit.support.RabbitExceptionTranslator.convertRabbitAccessException(RabbitExceptionTranslator.java:71)〜[spring-rabbit-1.7.1.RELEASE.jar:na]     在org.springframework.amqp.rabbit.connection.AbstractConnectionFactory.createBareConnection(AbstractConnectionFactory.java:367)〜[spring-rabbit-1.7.1.RELEASE.jar:na]     在org.springframework.amqp.rabbit.connection.CachingConnectionFactory.createConnection(CachingConnectionFactory.java:565)〜[spring-rabbit-1.7.1.RELEASE.jar:na]     在org.springframework.amqp.rabbit.core.RabbitTemplate.doExecute(RabbitTemplate.java:1430)〜[spring-rabbit-1.7.1.RELEASE.jar:na]     在org.springframework.amqp.rabbit.core.RabbitTemplate.execute(RabbitTemplate.java:1411)〜[spring-rabbit-1.7.1.RELEASE.jar:na]     在org.springframework.amqp.rabbit.core.RabbitTemplate.execute(RabbitTemplate.java:1387)〜[spring-rabbit-1.7.1.RELEASE.jar:na]     在org.springframework.amqp.rabbit.core.RabbitAdmin.getQueueProperties(RabbitAdmin.java:336)〜[spring-rabbit-1.7.1.RELEASE.jar:na]     在org.springframework.amqp.rabbit.listener.SimpleMessageListenerContainer.redeclareElementsIfNecessary(SimpleMessageListenerContainer.java:1135)[spring-rabbit-1.7.1.RELEASE.jar:na]     在org.springframework.amqp.rabbit.listener.SimpleMessageListenerContainer.access $ 1200(SimpleMessageListenerContainer.java:96)[spring-rabbit-1.7.1.RELEASE.jar:na]     在org.springframework.amqp.rabbit.listener.SimpleMessageListenerContainer $ AsyncMessageProcessingConsumer.run(SimpleMessageListenerContainer.java:1380)[spring-rabbit-1.7.1.RELEASE.jar:na]     在java.lang.Thread.run(Thread.java:745)[na:1.8.0_111] 引起:java.io.IOException:null     在com.rabbitmq.client.impl.AMQChannel.wrap(AMQChannel.java:105)〜[amqp-client-4.0.2.jar:4.0.2]     在com.rabbitmq.client.impl.AMQChannel.wrap(AMQChannel.java:101)〜[amqp-client-4.0.2.jar:4.0.2]     在com.rabbitmq.client.impl.AMQChannel.exnWrappingRpc(AMQChannel.java:123)〜[amqp-client-4.0.2.jar:4.0.2]     在com.rabbitmq.client.impl.AMQConnection.start(AMQConnection.java:381)〜[amqp-client-4.0.2.jar:4.0.2]     在com.rabbitmq.client.ConnectionFactory.newConnection(ConnectionFactory.java:909)〜[amqp-client-4.0.2.jar:4.0.2]     在com.rabbitmq.client.ConnectionFactory.newConnection(ConnectionFactory.java:859)〜[amqp-client-4.0.2.jar:4.0.2]     在com.rabbitmq.client.ConnectionFactory.newConnection(ConnectionFactory.java:799)〜[amqp-client-4.0.2.jar:4.0.2]     在org.springframework.amqp.rabbit.connection.AbstractConnectionFactory.createBareConnection(AbstractConnectionFactory.java:351)〜[spring-rabbit-1.7.1.RELEASE.jar:na]     ...省略了9个常用帧 引起:com.rabbitmq.client.ShutdownSignalException:连接错误     at com.rabbitmq.utility.ValueOrException.getValue(ValueOrException.java:66)〜[amqp-client-4.0.2.jar:4.0.2]     at com.rabbitmq.utility.BlockingValueOrException.uninterruptibleGetValue(BlockingValueOrException.java:32)〜[amqp-client-4.0.2.jar:4.0.2]     在com.rabbitmq.client.impl.AMQChannel $ BlockingRpcContinuation.getReply(AMQChannel.java:366)〜[amqp-client-4.0.2.jar:4.0.2]     在com.rabbitmq.client.impl.AMQChannel.privateRpc(AMQChannel.java:229)〜[amqp-client-4.0.2.jar:4.0.2]     在com.rabbitmq.client.impl.AMQChannel.exnWrappingRpc(AMQChannel.java:117)〜[amqp-client-4.0.2.jar:4.0.2]     ...省略了14个常见帧 引起:java.io.EOFException:null     at java.io.DataInputStream.readUnsignedByte(DataInputStream.java:290)~ [na:1.8.0_111]     at com.rabbitmq.client.impl.Frame.readFrom(Frame.java:91)〜[amqp-client-4.0.2.jar:4.0.2]     在com.rabbitmq.client.impl.SocketFrameHandler.readFrame(SocketFrameHandler.java:164)〜[amqp-client-4.0.2.jar:4.0.2]     在com.rabbitmq.client.impl.AMQConnection $ MainLoop.run(AMQConnection.java:571)〜[amqp-client-4.0.2.jar:4.0.2]     ...省略了1个常见帧

1 个答案:

答案 0 :(得分:1)

我认为删除RabbitMQ admin中的队列并再次重启应用程序它会重新创建具有正确属性的队列...通常,如果队列属性(自动删除,持久等)不匹配,我们将收到此错误。 ..