gpt4 book ai didi

java - RabbitMQ 嵌入式代理未从 Spring Boot 应用程序启动

转载 作者:行者123 更新时间:2023-12-01 17:59:58 26 4
gpt4 key购买 nike

我无法在rabbitmq代理的“CustomerQ”队列中发送消息。我已经通过 Spring Boot 将rabbitmq代理配置为嵌入式服务器。

 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.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]

我将感谢您对此的帮助。

最佳答案

不存在“嵌入式​​ RabbitMQ 代理”这样的东西。

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

是什么让您相信 Boot 嵌入了代理?

关于java - RabbitMQ 嵌入式代理未从 Spring Boot 应用程序启动,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41783283/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com