Commit 27f96467 by 杨林龙

优化kafka的配置

1 parent 0f4e01f3
...@@ -25,6 +25,9 @@ public class KafkaConfig { ...@@ -25,6 +25,9 @@ public class KafkaConfig {
@Autowired @Autowired
private KafkaNacosGpsProperties gpsKafkaProperties; private KafkaNacosGpsProperties gpsKafkaProperties;
@Autowired
private KafkaNacosBizProperties kafkaNacosBizProperties;
@Bean(name = "ddboxConsumerConfig") @Bean(name = "ddboxConsumerConfig")
public ConsumerConfig ddboxConsumerConfig() { public ConsumerConfig ddboxConsumerConfig() {
return new ConsumerConfig(ddboxGetProperties()); return new ConsumerConfig(ddboxGetProperties());
...@@ -35,6 +38,11 @@ public class KafkaConfig { ...@@ -35,6 +38,11 @@ public class KafkaConfig {
return new ConsumerConfig(gpsGetProperties()); return new ConsumerConfig(gpsGetProperties());
} }
@Bean(name = "bizConsumerConfig")
public ConsumerConfig bizConsumerConfig() {
return new ConsumerConfig(bizGetProperties());
}
@Bean @Bean
public PropertiesFactoryBean ddboxConsumerProperties() { public PropertiesFactoryBean ddboxConsumerProperties() {
PropertiesFactoryBean propertiesFactoryBean = new PropertiesFactoryBean(); PropertiesFactoryBean propertiesFactoryBean = new PropertiesFactoryBean();
...@@ -49,6 +57,13 @@ public class KafkaConfig { ...@@ -49,6 +57,13 @@ public class KafkaConfig {
return propertiesFactoryBean; return propertiesFactoryBean;
} }
@Bean
public PropertiesFactoryBean bizConsumerProperties() {
PropertiesFactoryBean propertiesFactoryBean = new PropertiesFactoryBean();
propertiesFactoryBean.setProperties(bizGetProperties());
return propertiesFactoryBean;
}
/** /**
* nacos属性封装Properties * nacos属性封装Properties
* *
...@@ -85,4 +100,21 @@ public class KafkaConfig { ...@@ -85,4 +100,21 @@ public class KafkaConfig {
return properties; return properties;
} }
/**
* nacos属性封装Properties
*
* @return
*/
public Properties bizGetProperties() {
Properties properties = new Properties();
properties.setProperty(KafkaConstant.ZOOKEEPER_CONNECT, kafkaNacosBizProperties.getConnect());
properties.setProperty(KafkaConstant.ZOOKEEPER_CONNECT_TIMEOUT, kafkaNacosBizProperties.getConnectTimeout());
properties.setProperty(KafkaConstant.ZOOKEEPER_SESSION_TIMEOUT, kafkaNacosBizProperties.getSessionTimeout());
properties.setProperty(KafkaConstant.GROUP_ID, kafkaNacosBizProperties.getGroupID());
properties.setProperty(KafkaConstant.AUTO_COMMIT_INTERVAL, kafkaNacosBizProperties.getAutoCommitInterval());
properties.setProperty(KafkaConstant.AUTO_OFFSET_RESET, kafkaNacosBizProperties.getAutoOffsetReset());
properties.setProperty(KafkaConstant.REBLANCE_BACKOFF, kafkaNacosBizProperties.getRebalanceBackoff());
properties.setProperty(KafkaConstant.REBLANCE_MAX_RETRIES, kafkaNacosBizProperties.getRebalanceMaxRetries());
return properties;
}
} }
...@@ -22,6 +22,9 @@ public class KafkaConsumerConfig { ...@@ -22,6 +22,9 @@ public class KafkaConsumerConfig {
@Resource(name = "gpsConsumerConfig") @Resource(name = "gpsConsumerConfig")
private ConsumerConfig gpsConsumerConfig; private ConsumerConfig gpsConsumerConfig;
@Resource(name = "bizConsumerConfig")
private ConsumerConfig bizConsumerConfig;
@Value("${consumer.nThreads}") @Value("${consumer.nThreads}")
private Integer nThreads; private Integer nThreads;
...@@ -101,7 +104,7 @@ public class KafkaConsumerConfig { ...@@ -101,7 +104,7 @@ public class KafkaConsumerConfig {
KafkaBatteryConsumer kafkaBatteryConsumer(@Value("${mq.kafka.device.battery.topic}") String topic) { KafkaBatteryConsumer kafkaBatteryConsumer(@Value("${mq.kafka.device.battery.topic}") String topic) {
KafkaBatteryConsumer kafkaBatteryConsumer = new KafkaBatteryConsumer(); KafkaBatteryConsumer kafkaBatteryConsumer = new KafkaBatteryConsumer();
kafkaBatteryConsumer.setnThreads(nThreads); kafkaBatteryConsumer.setnThreads(nThreads);
kafkaBatteryConsumer.setConsumerConfig(gpsConsumerConfig); kafkaBatteryConsumer.setConsumerConfig(bizConsumerConfig);
kafkaBatteryConsumer.setTopic(topic); kafkaBatteryConsumer.setTopic(topic);
return kafkaBatteryConsumer; return kafkaBatteryConsumer;
} }
......
package cn.com.glsx.kafka.config;
import lombok.Data;
import org.springframework.boot.context.properties.ConfigurationProperties;
/**
* @author yangll
* @time 2020/12/4
* @function kafka的nacos配置属性
*/
@Data
@ConfigurationProperties(prefix = "biz.kafka.config")
public class KafkaNacosBizProperties {
//从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!