如何在Camel Kafka选项参数中设置Map类型的additionalProperties
Camel Kafka URI中传递Map类型additionalProperties参数的方法
在Camel Kafka的URI配置中,针对additionalProperties这种Map类型的参数,有两种常用的传递方式:
方式一:重复参数名,逐个传递键值对
对每个Map中的键值对,重复使用additionalProperties参数名,格式为&additionalProperties=键=值,多个键值对依次追加即可。方式二:单个参数内用逗号分隔多组键值对
在同一个additionalProperties参数中,用逗号分隔多组键=值,格式为&additionalProperties=键1=值1,键2=值2。
示例代码修改
假设你需要传递AuthProvider=MyAuthProvider和anotherKey=anotherValue两组Map参数,修改后的URI构建代码如下:
方式一实现
return "kafka:" + topic + "?brokers= " + host + "&groupId=" + group + "&securityProtocol=SASL_SSL" + "&saslJaasConfig=org.apache.kafka.common.security.oauthbearer.OAuthBearerLoginModule required;" + "&saslMechanism=OAUTHBEARER" + "&sslTruststorePassword=changeit" + "&additionalProperties=AuthProvider=MyAuthProvider" + "&additionalProperties=anotherKey=anotherValue" + "&sslTruststoreLocation=" + "truststore.jks";
方式二实现
return "kafka:" + topic + "?brokers= " + host + "&groupId=" + group + "&securityProtocol=SASL_SSL" + "&saslJaasConfig=org.apache.kafka.common.security.oauthbearer.OAuthBearerLoginModule required;" + "&saslMechanism=OAUTHBEARER" + "&sslTruststorePassword=changeit" + "&additionalProperties=AuthProvider=MyAuthProvider,anotherKey=anotherValue" + "&sslTruststoreLocation=" + "truststore.jks";
注意:如果键或值中包含逗号、等号这类特殊字符,需要进行URL编码(比如用%2C代替逗号,%3D代替等号),避免参数解析错误。
内容的提问来源于stack exchange,提问作者KOTIOS
相关产品推荐
相关产品推荐

