MQ配置调试
This commit is contained in:
parent
2782eb2cdc
commit
642713daeb
@ -0,0 +1,28 @@
|
|||||||
|
package com.qiuguo.iot.user.api.config;
|
||||||
|
|
||||||
|
import org.springframework.amqp.rabbit.connection.ConnectionFactory;
|
||||||
|
|
||||||
|
import org.springframework.amqp.rabbit.listener.SimpleMessageListenerContainer;
|
||||||
|
import org.springframework.context.annotation.Bean;
|
||||||
|
import org.springframework.context.annotation.Configuration;
|
||||||
|
import org.springframework.amqp.rabbit.config.SimpleRabbitListenerContainerFactory;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author simon
|
||||||
|
* @date 2023/9/26
|
||||||
|
* @description
|
||||||
|
**/
|
||||||
|
@Configuration
|
||||||
|
public class TopicRabbitListenerConfig {
|
||||||
|
@Bean
|
||||||
|
public SimpleRabbitListenerContainerFactory simpleRabbitListenerContainerFactory(ConnectionFactory connectionFactory) {
|
||||||
|
// 配置消息监听容器工厂
|
||||||
|
SimpleRabbitListenerContainerFactory factory = new SimpleRabbitListenerContainerFactory();
|
||||||
|
factory.setConnectionFactory(connectionFactory);
|
||||||
|
factory.setConcurrentConsumers(3); // 并发消费者数量
|
||||||
|
factory.setMaxConcurrentConsumers(10); // 最大并发消费者数量
|
||||||
|
factory.setPrefetchCount(1); // 每个消费者的消息预取数量
|
||||||
|
return factory;
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -18,7 +18,7 @@ import java.io.IOException;
|
|||||||
@Component
|
@Component
|
||||||
@Slf4j
|
@Slf4j
|
||||||
public class YunxiListener {
|
public class YunxiListener {
|
||||||
@RabbitListener(queues = YunxiRabbitConst.QUEUE_YUNXI)
|
@RabbitListener(queues = YunxiRabbitConst.QUEUE_YUNXI, containerFactory = "simpleRabbitListenerContainerFactory")
|
||||||
public void processYunxiQueue(Channel channel, Message message) throws IOException {
|
public void processYunxiQueue(Channel channel, Message message) throws IOException {
|
||||||
String messageContent = new String(message.getBody(), "UTF-8");
|
String messageContent = new String(message.getBody(), "UTF-8");
|
||||||
System.out.println("YunxiListener msg " + messageContent);
|
System.out.println("YunxiListener msg " + messageContent);
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user