|
|
@@ -1,61 +0,0 @@
|
|
|
-package com.sckw.robot.config;
|
|
|
-
|
|
|
-import com.sckw.robot.pojo.constant.RabbitConstant;
|
|
|
-import org.springframework.amqp.core.Binding;
|
|
|
-import org.springframework.amqp.core.BindingBuilder;
|
|
|
-import org.springframework.amqp.core.Queue;
|
|
|
-import org.springframework.amqp.core.TopicExchange;
|
|
|
-import org.springframework.amqp.rabbit.config.SimpleRabbitListenerContainerFactory;
|
|
|
-import org.springframework.amqp.rabbit.connection.ConnectionFactory;
|
|
|
-import org.springframework.amqp.support.converter.Jackson2JsonMessageConverter;
|
|
|
-import org.springframework.context.annotation.Bean;
|
|
|
-import org.springframework.context.annotation.Configuration;
|
|
|
-
|
|
|
-/**
|
|
|
- * @author xucaiqin
|
|
|
- * @date 2024-04-01 19:46:34
|
|
|
- */
|
|
|
-@Configuration
|
|
|
-public class RabbitConfig {
|
|
|
- /**
|
|
|
- * 数据处理交换机
|
|
|
- *
|
|
|
- * @return
|
|
|
- */
|
|
|
- @Bean
|
|
|
- public TopicExchange dataExchange() {
|
|
|
- return new TopicExchange(RabbitConstant.TOPIC_EXCHANGE_DATA, true, false);
|
|
|
- }
|
|
|
-
|
|
|
- @Bean
|
|
|
- public SimpleRabbitListenerContainerFactory rabbitFactory(ConnectionFactory connectionFactory) {
|
|
|
- SimpleRabbitListenerContainerFactory factory = new SimpleRabbitListenerContainerFactory();
|
|
|
- factory.setConnectionFactory(connectionFactory);
|
|
|
- //设置批量
|
|
|
- factory.setBatchListener(true);
|
|
|
- factory.setConsumerBatchEnabled(true);//设置BatchMessageListener生效
|
|
|
- factory.setBatchSize(500);//设置监听器一次批量处理的消息数量
|
|
|
- return factory;
|
|
|
- }
|
|
|
-
|
|
|
- @Bean
|
|
|
- public Queue queue() {
|
|
|
- return new Queue(RabbitConstant.QUEUE);
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
- @Bean
|
|
|
- public Binding binding(TopicExchange dataExchange, Queue queue) {
|
|
|
- Binding binding = BindingBuilder
|
|
|
- .bind(queue)
|
|
|
- .to(dataExchange)
|
|
|
- .with(RabbitConstant.ROUTER_KEY + queue.getName());
|
|
|
- binding.addArgument(RabbitConstant.AUTO_DELETE, true);
|
|
|
- return binding;
|
|
|
- }
|
|
|
- @Bean
|
|
|
- public Jackson2JsonMessageConverter jackson2JsonMessageConverter() {
|
|
|
- return new Jackson2JsonMessageConverter();
|
|
|
- }
|
|
|
-
|
|
|
-}
|