gpt4 book ai didi

rabbitmq - 为什么 spring-amqp 消费者性能很慢?

转载 作者:行者123 更新时间:2023-12-04 00:41:03 25 4
gpt4 key购买 nike

我同时启动了生产者和消费者。 6 小时后,生产者将大约 6 千万条消息放入队列并在 6 小时后停止生产者,但消费者仍在连续运行,即使在运行 18 小时后仍有 4 千万条消息在队列中。谁能告诉我为什么消费者性能非常慢?

提前致谢!

@Bean
public SimpleMessageListenerContainer listenerContainer() {
SimpleMessageListenerContainer container = new SimpleMessageListenerContainer();
container.setConnectionFactory(connectionFactory());
container.setQueueNames(this.queueName);
container.setMessageListener(new MessageListenerAdapter(new TestMessageHandler(), new JsonMessageConverter()));
return container;
}
@Bean
public ConnectionFactory connectionFactory() {
CachingConnectionFactory connectionFactory = new CachingConnectionFactory(
"localhost");
connectionFactory.setUsername("guest");
connectionFactory.setPassword("guest");
return connectionFactory;
}

@Bean
public RabbitTemplate rabbitTemplate() {
RabbitTemplate template = new RabbitTemplate(connectionFactory());
template.setMessageConverter(new JsonMessageConverter());
template.setRoutingKey(this.queueName);
template.setQueue(this.queueName);
return template;
}

public class TestMessageHandler {
// receive messages
public void handleMessage(MessageBeanTest msgBean) {
// Storing bean data into CSV file
}
}

最佳答案

根据 Gary 的建议,您可以按如下方式设置它们。查看@RabbitListener

@Bean
public SimpleRabbitListenerContainerFactory listenerContainer( {
SimpleRabbitListenerContainerFactory factory = new SimpleRabbitListenerContainerFactory();
factory.setConnectionFactory(baseConfig.connectionFactory());
factory.setConcurrentConsumers(7); // choose a value
factory.setPrefetchCount(1); // how many messages per consumer at a time
factory.setMaxConcurrentConsumers(10); // choose a value
factory.setDefaultRequeueRejected(false); // if you want to deadletter
return factory;
}

关于rabbitmq - 为什么 spring-amqp 消费者性能很慢?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18732134/

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