Reputation: 34
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.
Upvotes: 0
Views: 3867
Reputation: 174739
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?
Upvotes: 4