于紫祥_1901
2021-01-14 be075862989b0792ba002764ecd44b04b8838218
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
package com.moral.config;
 
import com.moral.util.MessageConverter;
 
import org.springframework.amqp.core.*;
import org.springframework.amqp.rabbit.config.SimpleRabbitListenerContainerFactory;
import org.springframework.amqp.rabbit.connection.ConnectionFactory;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.context.annotation.Bean;
import org.springframework.stereotype.Component;
 
@Component
public class RabbitConfig {
 
    public static final String ORGANIZATION_DATA = "organization_data";
 
    private int concurrency = 10;
 
    @Bean
    public RabbitTemplate rabbitTemplate(ConnectionFactory connectionFactory) {
        RabbitTemplate template = new RabbitTemplate(connectionFactory);
        template.setMessageConverter(new MessageConverter());
        return template;
    }
 
    @Bean
    public SimpleRabbitListenerContainerFactory rabbitListenerContainerFactory(ConnectionFactory connectionFactory) {
        SimpleRabbitListenerContainerFactory factory = new SimpleRabbitListenerContainerFactory();
        factory.setConnectionFactory(connectionFactory);
        factory.setConcurrentConsumers(concurrency);
        factory.setMessageConverter(new MessageConverter());
        return factory;
    }
 
    @Bean
    public TopicExchange organization_data() {
        return new TopicExchange(ORGANIZATION_DATA, true, false);
    }
}