Commit e50adbf0 by 刘宇峰

新增gps集群消费

1 parent 9443fa00
......@@ -7,6 +7,7 @@ import org.springframework.beans.factory.config.PropertiesFactoryBean;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import java.util.Properties;
/**
......@@ -17,32 +18,71 @@ import java.util.Properties;
@Configuration
@EnableConfigurationProperties(KafkaNacosProperties.class)
public class KafkaConfig {
@Autowired
KafkaNacosProperties kafkaProperties;
private KafkaNacosProperties ddboxKafkaProperties;
@Autowired
private KafkaNacosGpsProperties gpsKafkaProperties;
@Bean(name = "ddboxConsumerConfig")
public ConsumerConfig ddboxConsumerConfig() {
return new ConsumerConfig(ddboxGetProperties());
}
@Bean(name = "gpsConsumerConfig")
public ConsumerConfig gpsConsumerConfig() {
return new ConsumerConfig(gpsGetProperties());
}
@Bean
public PropertiesFactoryBean consumerProperties() {
public PropertiesFactoryBean ddboxConsumerProperties() {
PropertiesFactoryBean propertiesFactoryBean = new PropertiesFactoryBean();
propertiesFactoryBean.setProperties(getProperties());
propertiesFactoryBean.setProperties(ddboxGetProperties());
return propertiesFactoryBean;
}
@Bean
public ConsumerConfig consumerConfig() {
return new ConsumerConfig(getProperties());
public PropertiesFactoryBean consumerProperties() {
PropertiesFactoryBean propertiesFactoryBean = new PropertiesFactoryBean();
propertiesFactoryBean.setProperties(gpsGetProperties());
return propertiesFactoryBean;
}
/**
* nacos属性封装Properties
*
* @return
*/
public Properties ddboxGetProperties() {
Properties properties = new Properties();
properties.setProperty(KafkaConstant.ZOOKEEPER_CONNECT, ddboxKafkaProperties.getConnect());
properties.setProperty(KafkaConstant.ZOOKEEPER_CONNECT_TIMEOUT, ddboxKafkaProperties.getConnectTimeout());
properties.setProperty(KafkaConstant.ZOOKEEPER_SESSION_TIMEOUT, ddboxKafkaProperties.getSessionTimeout());
properties.setProperty(KafkaConstant.GROUP_ID, ddboxKafkaProperties.getGroupID());
properties.setProperty(KafkaConstant.AUTO_COMMIT_INTERVAL, ddboxKafkaProperties.getAutoCommitInterval());
properties.setProperty(KafkaConstant.AUTO_OFFSET_RESET, ddboxKafkaProperties.getAutoOffsetReset());
properties.setProperty(KafkaConstant.REBLANCE_BACKOFF, ddboxKafkaProperties.getRebalanceBackoff());
properties.setProperty(KafkaConstant.REBLANCE_MAX_RETRIES, ddboxKafkaProperties.getRebalanceMaxRetries());
return properties;
}
//nacos属性封装Properties
public Properties getProperties() {
/**
* nacos属性封装Properties
*
* @return
*/
public Properties gpsGetProperties() {
Properties properties = new Properties();
properties.setProperty(KafkaConstant.ZOOKEEPER_CONNECT, kafkaProperties.getConnect());
properties.setProperty(KafkaConstant.ZOOKEEPER_CONNECT_TIMEOUT, kafkaProperties.getConnectTimeout());
properties.setProperty(KafkaConstant.ZOOKEEPER_SESSION_TIMEOUT, kafkaProperties.getSessionTimeout());
properties.setProperty(KafkaConstant.GROUP_ID, kafkaProperties.getGroupID());
properties.setProperty(KafkaConstant.AUTO_COMMIT_INTERVAL, kafkaProperties.getAutoCommitInterval());
properties.setProperty(KafkaConstant.AUTO_OFFSET_RESET, kafkaProperties.getAutoOffsetReset());
properties.setProperty(KafkaConstant.REBLANCE_BACKOFF, kafkaProperties.getRebalanceBackoff());
properties.setProperty(KafkaConstant.REBLANCE_MAX_RETRIES, kafkaProperties.getRebalanceMaxRetries());
properties.setProperty(KafkaConstant.ZOOKEEPER_CONNECT, gpsKafkaProperties.getConnect());
properties.setProperty(KafkaConstant.ZOOKEEPER_CONNECT_TIMEOUT, gpsKafkaProperties.getConnectTimeout());
properties.setProperty(KafkaConstant.ZOOKEEPER_SESSION_TIMEOUT, gpsKafkaProperties.getSessionTimeout());
properties.setProperty(KafkaConstant.GROUP_ID, gpsKafkaProperties.getGroupID());
properties.setProperty(KafkaConstant.AUTO_COMMIT_INTERVAL, gpsKafkaProperties.getAutoCommitInterval());
properties.setProperty(KafkaConstant.AUTO_OFFSET_RESET, gpsKafkaProperties.getAutoOffsetReset());
properties.setProperty(KafkaConstant.REBLANCE_BACKOFF, gpsKafkaProperties.getRebalanceBackoff());
properties.setProperty(KafkaConstant.REBLANCE_MAX_RETRIES, gpsKafkaProperties.getRebalanceMaxRetries());
return properties;
}
}
......@@ -3,11 +3,12 @@ package cn.com.glsx.kafka.config;
import cn.com.glsx.kafka.queue.consumer.ChannelRiskConsumer;
import cn.com.glsx.kafka.queue.consumer.FenceDriverConsumer;
import kafka.consumer.ConsumerConfig;
import org.springframework.beans.factory.annotation.Autowired;
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
......@@ -15,27 +16,32 @@ import org.springframework.context.annotation.Configuration;
*/
@Configuration
public class KafkaConsumerConfig {
@Autowired
private ConsumerConfig consumerConfig;
@Resource(name = "ddboxConsumerConfig")
private ConsumerConfig ddboxConsumerConfig;
@Resource(name = "gpsConsumerConfig")
private ConsumerConfig gpsConsumerConfig;
@Value("${consumer.nThreads}")
private Integer nThreads;
@Bean(initMethod = "init",destroyMethod = "destroy")
ChannelRiskConsumer channelRiskConsumer(@Value("${mq.kafka.channelRisk.topic}") String topic){
@Bean(initMethod = "init", destroyMethod = "destroy")
ChannelRiskConsumer channelRiskConsumer(@Value("${mq.kafka.channelRisk.topic}") String topic) {
ChannelRiskConsumer channelRiskConsumer = new ChannelRiskConsumer();
channelRiskConsumer.setnThreads(nThreads);
channelRiskConsumer.setConsumerConfig(consumerConfig);
channelRiskConsumer.setConsumerConfig(ddboxConsumerConfig);
channelRiskConsumer.setTopic(topic);
return channelRiskConsumer;
}
@Bean(initMethod = "init",destroyMethod = "destroy")
FenceDriverConsumer fenceDriverConsumer(@Value("${mq.kafka.fence.drive.topic}") String topic){
@Bean(initMethod = "init", destroyMethod = "destroy")
FenceDriverConsumer fenceDriverConsumer(@Value("${mq.kafka.fence.drive.topic}") String topic) {
FenceDriverConsumer driverConsumer = new FenceDriverConsumer();
driverConsumer.setnThreads(nThreads);
driverConsumer.setConsumerConfig(consumerConfig);
driverConsumer.setConsumerConfig(gpsConsumerConfig);
driverConsumer.setTopic(topic);
return driverConsumer;
}
}
package cn.com.glsx.kafka.config;
import lombok.Data;
import org.springframework.boot.context.properties.ConfigurationProperties;
/**
* @author fengzhi
* @time 2020/12/4
* @function kafka的nacos配置属性
*/
@Data
@ConfigurationProperties(prefix = "kafka.gps.config")
public class KafkaNacosGpsProperties {
//从nacos获取属性
private String connect;
private String connectTimeout;
private String sessionTimeout;
private String groupID;
private String autoCommitInterval;
private String autoOffsetReset;
private String rebalanceBackoff;
private String rebalanceMaxRetries;
}
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!