KafkaConsumerConfig.java
2.02 KB
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
package cn.com.glsx.kafka.config;
import cn.com.glsx.kafka.queue.consumer.BaseStationConsumer;
import cn.com.glsx.kafka.queue.consumer.GpsAndBsConsumer;
import cn.com.glsx.kafka.queue.consumer.GpsConsumer;
import kafka.consumer.ConsumerConfig;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import javax.annotation.Resource;
/**
* @author fengzhi
* @time 2020/12/9
* @function kafka的消费者配置
*/
@Configuration
public class KafkaConsumerConfig {
@Resource(name = "ddboxConsumerConfig")
private ConsumerConfig ddboxConsumerConfig;
@Resource(name = "gpsConsumerConfig")
private ConsumerConfig gpsConsumerConfig;
@Value("${consumer.nThreads}")
private Integer nThreads;
@Bean(initMethod = "init", destroyMethod = "destroy")
BaseStationConsumer baseStationConsumer(@Value("${mq.kafka.device.bs.topic}") String topic) {
BaseStationConsumer baseStationConsumer = new BaseStationConsumer();
baseStationConsumer.setnThreads(nThreads);
baseStationConsumer.setConsumerConfig(gpsConsumerConfig);
baseStationConsumer.setTopic(topic);
return baseStationConsumer;
}
@Bean(initMethod = "init", destroyMethod = "destroy")
GpsAndBsConsumer gpsAndBsConsumer(@Value("${mq.kafka.device.gpsandbs.topic}") String topic) {
GpsAndBsConsumer gpsAndBsConsumer = new GpsAndBsConsumer();
gpsAndBsConsumer.setnThreads(nThreads);
gpsAndBsConsumer.setConsumerConfig(gpsConsumerConfig);
gpsAndBsConsumer.setTopic(topic);
return gpsAndBsConsumer;
}
@Bean(initMethod = "init", destroyMethod = "destroy")
GpsConsumer channelRiskConsumer(@Value("${mq.kafka.device.gps.topic}") String topic) {
GpsConsumer gpsConsumer = new GpsConsumer();
gpsConsumer.setnThreads(nThreads);
gpsConsumer.setConsumerConfig(gpsConsumerConfig);
gpsConsumer.setTopic(topic);
return gpsConsumer;
}
}