我有一个简单的弹簧靴1.5.22 + amqp的示例,问题是 队列不是动态创建的,而是应该动态创建的。
@Component
class ReceiverComponent {
@RabbitListener(queues = 'spring-boot-queue-2')
public void receive_2(String content) {
System.out.println("[ReceiveMsg-2] receive msg: " + content);
}
@Component
class SenderComponent {
@Autowired
private AmqpAdmin amqpAdmin;
// The default implementation of this interface is RabbitTemplate, which
currently has only one implementation.
@Autowired
private AmqpTemplate amqpTemplate;
/**
* send message
*
* @param msgContent
*/
public void send_2(String msgContent) {
amqpTemplate.convertAndSend(RabbitConfig.SPRING_BOOT_EXCHANGE,
RabbitConfig.SPRING_BOOT_BIND_KEY, msgContent);
}
@Configuration
class RabbitConfig {
// Queue name
public final static String SPRING_BOOT_QUEUE = "spring-boot-queue-2";
// Switch name
public final static String SPRING_BOOT_EXCHANGE = "spring-boot-exchange-
2";
// Bound values
public static final String SPRING_BOOT_BIND_KEY = "spring-boot-bind-key-
2";
}
我遇到的错误是:
原因:com.rabbitmq.client.ShutdownSignalException:频道错误;协议方法:#method(reply-code = 404,Reply-text = NOT_FOUND-虚拟主机'/'中没有队列'spring-boot-queue-2',class-id = 50,method-id = 10)
它是否必须在Rabbitmq上执行某些操作? 安装的版本是3.7.13,我的数据是:
spring:
# Configure rabbitMQspring:
rabbitmq:
host: 127.0.0.1
port: 5672
username: guest
password: guest
答案 0 :(得分:1)
你能放吗:
@Bean
public Queue queue() {
return new Queue("spring-boot-queue-2'");
}
您的班级上用@Configuration
注释?