gpt4 book ai didi

java - spring-amqp 不会使用 AmqpTemplate.convertAndSend() 插入消息

转载 作者:塔克拉玛干 更新时间:2023-11-02 19:21:04 26 4
gpt4 key购买 nike

这是一个小的 Spring 程序,它希望将一条消息插入到 rabbitmq 队列中:

public class Main {
public static void main(String [] args) throws IOException {
AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(QueueConfiguration.class);
AmqpTemplate template = context.getBean(AmqpTemplate.class);
template.convertAndSend("asdflk ...");
context.destroy();
}
}

ApplicationContext如下:

@Configuration
public class QueueConfiguration {

@Bean
public ConnectionFactory connectionFactory() {
return new CachingConnectionFactory("192.168.1.39");
}

@Bean
public RabbitTemplate rabbitTemplate() {
return new RabbitTemplate(connectionFactory());
}
}

当我检查服务器上队列的内容时,没有插入任何内容。我还尝试在 RabbitTemplate 上设置交换名称或队列名称,但服务器上仍然没有任何显示。

应用程序的日志没有显示任何错误,但会记录以下内容:

17:28:02.441 [main] DEBUG o.s.amqp.rabbit.core.RabbitTemplate - Executing callback on RabbitMQ Channel: Cached Rabbit Channel: AMQChannel(amqp://guest@192.168.1.39:5672/,1)
17:28:02.441 [main] DEBUG o.s.amqp.rabbit.core.RabbitTemplate - Publishing message on exchange [], routingKey = []

有什么问题吗?

最佳答案

我必须在调用 convertAndSend() 时将队列作为参数提供:

template.convertAndSend("hello2", "asdflk ...");

还在疑惑为什么spring-amqp不会抛出异常。当没有给出队列时,有人知道消息传递到哪里吗?

关于java - spring-amqp 不会使用 AmqpTemplate.convertAndSend() 插入消息,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29082044/

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