Flink作业认证方式接入Kafka

1、背景

Flink作业迁移到B3集群,完成kafka认证接入改造

2、目标

动态传入kafka安全认证参数,兼容非认证方式接入kafka

3、方案

采用Map接收kafka安全认证参数

4、难点

1) ParameterTool.fromArgs(args) 无法解析map格式的参数

* Returns {@link ParameterTool} for the given arguments. The arguments are keys followed by values.
* Keys have to start with '-' or '--'
*
* <p><strong>Example arguments:</strong>
* --key1 value1 --key2 value2 -key3 value3

解决:仅采用ScallopConf进行参数解析

2)sasl.jaas.config格式复杂,存在无法解析的问题
--kafka_consumer_props
security.protocol=SASL_PLAINTEXT
sasl.mechanism=SCRAM-SHA-256
sasl.jaas.config=org.apache.kafka.common.security.scram.ScramLoginModule required username\="CG_apm_mucker" password\="249664";

在前端传入参数时,对 "="进行转义,对解析后的参数进行手动解析,去除多余的引号。

后端接收到参数为
'sasl.jaas.config=org.apache.kafka.common.security.scram.ScramLoginModule required username\="CG_apm_mucker" password\="249664";'
对参数进行再次解析 for ((k, v) <- config.kafkaConsumerProperties) { if (k.startsWith("'")) { props.put(k.substring(1), v.substring(0, v.length - 1)) } else { props.put(k, v) } }

 

posted @ 2022-06-14 15:23  爱晴天  阅读(791)  评论(0)    收藏  举报