RabbitMQ嵌入式代理不是从spring boot应用程序

时间:2017-01-21 19:02:28

标签: java spring-boot microservices spring-rabbitmq embedded-server

我无法在rabbitmq经纪人的“CustomerQ”队列中发送消息。我已经通过spring boot将rabbitmq broker配置为嵌入式服务器。

 package com.testlab.chapter2;

  import org.springframework.amqp.core.Queue;
  import org.springframework.amqp.rabbit.core.RabbitMessagingTemplate;
  import org.springframework.beans.factory.annotation.Autowired;
  import org.springframework.context.annotation.Bean;
  import org.springframework.context.annotation.Lazy;
  import org.springframework.stereotype.Component;



  @Component 
  @Lazy
 class Sender {

  RabbitMessagingTemplate template;

  @Autowired
  Sender(RabbitMessagingTemplate template){
    this.template = template;
  }

  @Bean
  Queue queue() {
    return new Queue("CustomerQ", false);
   }

   public void send(String message){
    System.out.println(template.getRabbitTemplate().getConnectionFactory());

    template.convertAndSend("CustomerQ", message);
    }
  }

 **application.properties file configuration:**

  spring.rabbitmq.host=localhost
  spring.rabbitmq.port=5672
  spring.rabbitmq.username=guest
  spring.rabbitmq.password=guest

当代码尝试连接/将任何消息放入队列时,我收到以下错误 的错误:

  

servlet [dispatcherServlet]的Servlet.service()与path []的上下文发生异常[请求处理失败;嵌套异常是org.springframework.messaging.MessagingException:java.net.ConnectException:连接被拒绝:连接;嵌套异常是org.springframework.amqp.AmqpConnectException:java.net.ConnectException:Connection refused:connect] with root cause

     

java.net.ConnectException:拒绝连接:连接       at java.net.DualStackPlainSocketImpl.waitForConnect(Native Method)〜[na:1.8.0_25]       在java.net.DualStackPlainSocketImpl.socketConnect(DualStackPlainSocketImpl.java:85)〜[na:1.8.0_25]       at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:345)〜[na:1.8.0_25]       at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:206)〜[na:1.8.0_25]       在java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:188)〜[na:1.8.0_25]       在java.net.PlainSocketImpl.connect(PlainSocketImpl.java:172)〜[na:1.8.0_25]       在java.net.SocksSocketImpl.connect(SocksSocketImpl.java:392)〜[na:1.8.0_25]       在java.net.Socket.connect(Socket.java:589)〜[na:1.8.0_25]

我将非常感谢你的帮助。

1 个答案:

答案 0 :(得分:3)

没有“嵌入式RabbitMQ经纪人”这样的东西。

您必须单独安装并启动它。它不是用Java编写的,而是Erlang。

是什么让你相信Boot嵌入了经纪人?