Creating and using a custom kafka connect configuration provider

╄→尐↘猪︶ㄣ 提交于 2020-05-29 09:14:48

问题


I have installed and tested kafka connect in distributed mode, it works now and it connects to the configured sink and reads from the configured source. That being the case, I moved to enhance my installation. The one area I think needs immediate attention is the fact that to create a connector, the only available mean is through REST calls, this means I need to send my information through the wire, unprotected. In order to secure this, kafka introduced the new ConfigProvider seen here. This is helpful as it allows to set properties in the server and then reference them in the rest call, like so:

{
.
.
"property":"${file:/path/to/file:nameOfThePropertyInFile}"
.
.
}

This works really well, just by adding the property file on the server and adding the following config on the distributed.properties file:

config.providers=file   # multiple comma-separated provider types can be specified here
config.providers.file.class=org.apache.kafka.common.config.provider.FileConfigProvider

While this solution works, it really does not help to easy my concerns regarding security, as the information now passed from being sent over the wire, to now be seating on a repository, with text on plain sight for everyone to see. The kafka team foresaw this issue and allowed clients to produce their own configuration providers implementing the interface ConfigProvider. I have created my own implementation and packaged in a jar, givin it the sugested final name:

META-INF/services/org.apache.kafka.common.config.ConfigProvider

and added the following entry in the distributed file:

config.providers=cust
config.providers.cust.class=com.somename.configproviders.CustConfigProvider

However I am getting an error from connect, stating that a class implementing ConfigProvider, with the name:

com.somename.configproviders.CustConfigProvider

could not be found. I am at a loss now, because the documentation on their site is not explicit about how to configure custom config providers very well.

Has someone worked on a similar issue and could provide some insight into this? Any help would be appreciated.


回答1:


I just went through these to setup a custom ConfigProvider recently. The official doc is ambiguous and confusing.

I have created my own implementation and packaged in a jar, givin it the sugested final name: META-INF/services/org.apache.kafka.common.config.ConfigProvider

You could name the final name of jar whatever you like, but needs to pack to jar format which has .jar suffix.

Here is the complete step by step. Suppose your custom ConfigProvider fully-qualified name is com.my.CustomConfigProvider.MyClass. 1. create a file under directory: META-INF/services/org.apache.kafka.common.config.ConfigProvider. File content is full qualified class name: com.my.CustomConfigProvider.MyClass

  1. Include your source code, and above META-INF folder to generate a Jar package. If you are using Maven, file structure looks like this

  2. put your final Jar file, say custom-config-provider-1.0.jar, under the Kafka worker plugin folder. Default is /usr/share/java. PLUGIN_PATH in Kafka worker config file.

  3. Upload all the dependency jars to PLUGIN_PATH as well. Use the META-INFO/MANIFEST.MF file inside your Jar file to configure the 'ClassPath' of dependent jars that your code will use.

  4. In kafka worker config file, create two additional properties:

CONNECT_CONFIG_PROVIDERS: 'mycustom', // Alias name of your ConfigProvider
CONNECT_CONFIG_PROVIDERS_MYCUSTOM_CLASS:'com.my.CustomConfigProvider.MyClass',
  1. Restart workers

  2. Update your connector config file by curling POST to Kafka Restful API. In Connector config file, you could reference the value inside ConfigData returned from ConfigProvider:get(path, keys) by using the syntax like:

database.password=${mycustom:/path/pass/to/get/method:password}

ConfigData is a HashMap which contains {password: 123}

  1. If you still seeing ClassNotFound exception, probably your ClassPath is not setup correctly.

Note: • If you are using AWS ECS/EC2, you need to set the worker config file by setting the environment variable. • worker config and connector config file are different.



来源:https://stackoverflow.com/questions/57995742/creating-and-using-a-custom-kafka-connect-configuration-provider

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!