Authored by liangyi.chen@yoho.cn

配置优化

package com.yoho.datasync.producer.canal;
import com.sun.deploy.util.StringUtils;
import com.yoho.datasync.core.base.message.TableConfig;
import com.yoho.datasync.core.base.message.TableConfigLoader;
import lombok.Data;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.stereotype.Component;
import javax.annotation.PostConstruct;
import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;
@Component
@ConfigurationProperties(prefix = "canal")
... ... @@ -16,6 +23,9 @@ public class CanalConfig {
private List<CanalInstance> canalInstance ;
@Resource
TableConfigLoader tableConfigLoader;
public List<CanalInstance> getCanalInstance() {
return canalInstance;
}
... ... @@ -56,7 +66,27 @@ public class CanalConfig {
String filter;
String dbname;
int fetchSize;
}
@PostConstruct
void buildInstanceFilter(){
canalInstance.forEach(instance -> {
String dbName = instance.getDbname();
String filter = buildCanalFilter(dbName);
instance.setFilter(filter);
});
}
private String buildCanalFilter(String dbName) {
List<TableConfig> dbTableConfigList = tableConfigLoader.getTableConfigs().stream().filter(a -> a.getDbName().equalsIgnoreCase(dbName)).collect(Collectors.toList());
List<String> filters = new ArrayList<>();
for (TableConfig tableConfig : dbTableConfigList) {
filters.add(dbName + "." + tableConfig.getTableName());
}
return StringUtils.join(filters, ",");
}
}
... ...
canal:
singleSocketAddress: "192.168.102.10"
singleSocketPort: 20211
singleSocketAddress: "192.168.104.246"
singleSocketPort: 30886
canalInstance:
- name: "yhgrass"
destination: "yhgrass"
dbname: "yh_grass"
username: ""
password: ""
<<<<<<< Updated upstream
filter: "yh_grass.grass_article_praise, yh_grass.grass_article_block, yh_grass.grass_article,
yh_grass.grass_article_comment, yh_grass.grass_article_label, yh_grass.grass_article_product,
yh_grass.grass_comment_praise"
=======
>>>>>>> Stashed changes
fetchSize: "1000"
zkAddress: ""
... ...
canal:
singleSocketAddress: "192.168.102.10"
singleSocketPort: 20211
singleSocketAddress: yoho-canal
singleSocketPort: 30886
canalInstance:
- name: "yhgrass"
destination: "yhgrass"
dbname: "yh_grass"
username: ""
password: ""
filter: "yh_grass.grass_article_praise"
fetchSize: "1000"
zkAddress: ""
rabbitmq:
server: "192.168.102.216"
server: yohoops-rabbit-common-service
port: 5672
username: "admin1"
password: "123qwe"
... ...