-
Notifications
You must be signed in to change notification settings - Fork 71
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added example for a converter. Added example for a transformation wit…
- Loading branch information
1 parent
a690082
commit cf9d9d1
Showing
15 changed files
with
251 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
58 changes: 58 additions & 0 deletions
58
src/main/resources/archetype-resources/src/main/java/MyConverter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
package ${package}; | ||
|
||
import org.apache.kafka.common.header.Header; | ||
import org.apache.kafka.connect.data.Schema; | ||
import org.apache.kafka.connect.data.SchemaAndValue; | ||
import org.apache.kafka.connect.storage.Converter; | ||
import org.apache.kafka.common.header.Header; | ||
import org.apache.kafka.common.header.Headers; | ||
import java.util.Map; | ||
import com.github.jcustenborder.kafka.connect.utils.config.Description; | ||
import com.github.jcustenborder.kafka.connect.utils.config.Title; | ||
import com.github.jcustenborder.kafka.connect.utils.config.DocumentationImportant; | ||
import com.github.jcustenborder.kafka.connect.utils.config.DocumentationNote; | ||
import com.github.jcustenborder.kafka.connect.utils.config.DocumentationTip; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
@Description("This is a description of this connector and will show up in the documentation") | ||
@DocumentationImportant("This is a important information that will show up in the documentation.") | ||
@DocumentationTip("This is a tip that will show up in the documentation.") | ||
@Title("Super Converter") //This is the display name that will show up in the documentation. | ||
@DocumentationNote("This is a note that will show up in the documentation") | ||
public class MyConverter implements Converter { | ||
private static Logger log = LoggerFactory.getLogger(MyConverter.class); | ||
|
||
@Override | ||
public void configure(Map<String, ?> settings, boolean isKey) { | ||
//TODO: Do your setup here. | ||
} | ||
|
||
@Override | ||
public byte[] fromConnectData(String s, Schema schema, Object o) { | ||
throw new UnsupportedOperationException( | ||
"This needs to be completed" | ||
); | ||
} | ||
|
||
@Override | ||
public byte[] fromConnectData(String topic, Headers headers, Schema schema, Object value) { | ||
throw new UnsupportedOperationException( | ||
"This converter requires Kafka 2.4.0 or higher with header support." | ||
); | ||
} | ||
|
||
@Override | ||
public SchemaAndValue toConnectData(String s, byte[] bytes) { | ||
throw new UnsupportedOperationException( | ||
"This needs to be completed" | ||
); | ||
} | ||
|
||
@Override | ||
public SchemaAndValue toConnectData(String topic, Headers headers, byte[] value) { | ||
throw new UnsupportedOperationException( | ||
"This converter requires Kafka 2.4.0 or higher with header support." | ||
); | ||
} | ||
} |
70 changes: 70 additions & 0 deletions
70
src/main/resources/archetype-resources/src/main/java/MyKeyValueTransformation.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
package ${package}; | ||
|
||
import com.github.jcustenborder.kafka.connect.utils.config.Description; | ||
import com.github.jcustenborder.kafka.connect.utils.config.Title; | ||
import com.github.jcustenborder.kafka.connect.utils.transformation.BaseKeyValueTransformation; | ||
import org.apache.kafka.common.config.ConfigDef; | ||
import org.apache.kafka.common.config.ConfigException; | ||
import org.apache.kafka.connect.connector.ConnectRecord; | ||
import org.apache.kafka.connect.data.Schema; | ||
import org.apache.kafka.connect.data.SchemaAndValue; | ||
import org.apache.kafka.connect.errors.DataException; | ||
|
||
import java.io.IOException; | ||
import java.io.InputStream; | ||
import java.util.Map; | ||
|
||
@Title("Super Cool Transformation") | ||
@Description("This transformation will change one record to another record.") | ||
public class MyKeyValueTransformation<R extends ConnectRecord<R>> extends BaseKeyValueTransformation<R> { | ||
MyKeyValueTransformationConfig config; | ||
|
||
protected MyKeyValueTransformation(boolean isKey) { | ||
super(isKey); | ||
} | ||
|
||
@Override | ||
public ConfigDef config() { | ||
return MyKeyValueTransformationConfig.config(); | ||
} | ||
|
||
@Override | ||
public void close() { | ||
|
||
} | ||
|
||
@Override | ||
protected SchemaAndValue processBytes(R record, Schema inputSchema, byte[] input) { | ||
throw new UnsupportedOperationException("This method will execute against byte arrays."); | ||
} | ||
|
||
@Override | ||
protected SchemaAndValue processString(R record, Schema inputSchema, String input) { | ||
throw new UnsupportedOperationException("This method will execute against Strings."); | ||
} | ||
|
||
@Override | ||
public void configure(Map<String, ?> map) { | ||
this.config = new MyKeyValueTransformationConfig(map); | ||
} | ||
|
||
/** | ||
* This implementation works against the key of the record. | ||
* @param <R> | ||
*/ | ||
public static class Key<R extends ConnectRecord<R>> extends MyKeyValueTransformation<R> { | ||
public Key() { | ||
super(true); | ||
} | ||
} | ||
|
||
/** | ||
* This implementation works against the value of the record. | ||
* @param <R> | ||
*/ | ||
public static class Value<R extends ConnectRecord<R>> extends MyKeyValueTransformation<R> { | ||
public Value() { | ||
super(false); | ||
} | ||
} | ||
} |
33 changes: 33 additions & 0 deletions
33
src/main/resources/archetype-resources/src/main/java/MyKeyValueTransformationConfig.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package ${package}; | ||
|
||
import org.apache.kafka.common.config.AbstractConfig; | ||
import org.apache.kafka.common.config.ConfigDef; | ||
import org.apache.kafka.common.config.ConfigDef.Type; | ||
import org.apache.kafka.common.config.ConfigDef.Importance; | ||
import com.github.jcustenborder.kafka.connect.utils.config.ConfigKeyBuilder; | ||
|
||
import java.util.Map; | ||
|
||
|
||
public class MyKeyValueTransformationConfig extends AbstractConfig { | ||
|
||
public static final String MY_SETTING_CONFIG = "my.setting"; | ||
private static final String MY_SETTING_DOC = "This is a setting important to my connector."; | ||
|
||
public final String mySetting; | ||
|
||
public MyKeyValueTransformationConfig(Map<?, ?> originals) { | ||
super(config(), originals); | ||
this.mySetting = this.getString(MY_SETTING_CONFIG); | ||
} | ||
|
||
public static ConfigDef config() { | ||
return new ConfigDef() | ||
.define( | ||
ConfigKeyBuilder.of(MY_SETTING_CONFIG, Type.STRING) | ||
.documentation(MY_SETTING_DOC) | ||
.importance(Importance.HIGH) | ||
.build() | ||
); | ||
} | ||
} |
20 changes: 18 additions & 2 deletions
20
src/main/resources/archetype-resources/src/main/java/package-info.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,22 @@ | ||
@Introduction("This is the high level introduction section for your plugin") | ||
@Title("This is the title of your plugin") | ||
/** | ||
* This attribute is used during documentation generation to write the introduction section. | ||
*/ | ||
@Introduction("This plugin is used to add additional JSON parsing functionality to Kafka Connect.") | ||
/** | ||
* This attribute is used as the display name during documentation generation. | ||
*/ | ||
@Title("${artifactId}") | ||
/** | ||
* This attribute is used to provide the owner on the connect hub. For example jcustenborder. | ||
*/ | ||
@PluginOwner("${groupId}") | ||
/** | ||
* This attribute is used to provide the name of the plugin on the connect hub. | ||
*/ | ||
@PluginName("${artifactId}") | ||
package ${package}; | ||
|
||
import com.github.jcustenborder.kafka.connect.utils.config.Introduction; | ||
import com.github.jcustenborder.kafka.connect.utils.config.PluginName; | ||
import com.github.jcustenborder.kafka.connect.utils.config.PluginOwner; | ||
import com.github.jcustenborder.kafka.connect.utils.config.Title; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
13 changes: 13 additions & 0 deletions
13
src/main/resources/archetype-resources/src/test/java/MyConverterTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package ${package}; | ||
|
||
import org.junit.jupiter.api.AfterAll; | ||
import org.junit.jupiter.api.BeforeAll; | ||
import org.junit.jupiter.api.BeforeEach; | ||
import org.junit.jupiter.api.Test; | ||
|
||
public class MyConverterTest { | ||
@Test | ||
public void test() { | ||
// Congrats on a passing test! | ||
} | ||
} |
13 changes: 13 additions & 0 deletions
13
src/main/resources/archetype-resources/src/test/java/MyKeyValueTransformationTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package ${package}; | ||
|
||
import org.junit.jupiter.api.AfterAll; | ||
import org.junit.jupiter.api.BeforeAll; | ||
import org.junit.jupiter.api.BeforeEach; | ||
import org.junit.jupiter.api.Test; | ||
|
||
public class MyKeyValueTransformationTest { | ||
@Test | ||
public void test() { | ||
// Congrats on a passing test! | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters