0

I am unable to send message in "CustomerQ" queue of rabbitmq broker. I have configured rabbitmq broker as embedded server through spring boot.

 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

I am getting below error when code is trying to connect/put any message in queue Error:

Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Request processing failed; nested exception is org.springframework.messaging.MessagingException: java.net.ConnectException: Connection refused: connect; nested exception is org.springframework.amqp.AmqpConnectException: java.net.ConnectException: Connection refused: connect] with root cause

java.net.ConnectException: Connection refused: connect at java.net.DualStackPlainSocketImpl.waitForConnect(Native Method) ~[na:1.8.0_25] at 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] at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:188) ~[na:1.8.0_25] at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:172) ~[na:1.8.0_25] at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:392) ~[na:1.8.0_25] at java.net.Socket.connect(Socket.java:589) ~[na:1.8.0_25]

I will appreciate your help on this.

Gary Russell
  • 166,535
  • 14
  • 146
  • 179
JavaSat
  • 34
  • 2
  • 8

1 Answers1

4

There's no such thing as an "embedded RabbitMQ broker".

You have to install and start it separately. It is not written in Java, it's Erlang.

What leads you to believe Boot embeds a broker?

Gary Russell
  • 166,535
  • 14
  • 146
  • 179
  • Thanks Russell. I thought that spring boot supports RabbitMQ as well.My bad as I was not aware that it is written in java. I think spring boot supports embedded activemq broker as mentioned in below link: [link](http://docs.spring.io/spring-boot/docs/current/reference/html/boot-features-messaging.html). My code is working fine as I connected to rabbitmq external broker. – JavaSat Jan 21 '17 at 20:24