Skip to content

Added the optional message.key value #1

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,10 @@ public class DatagenConnectorConfig extends AbstractConfig {
private static final String POLL_INTERVAL_DISPLAY = "Poll Interval";
private static final int POLL_INTERVAL_DEFAULT = 10000;

private static final String MESSAGE_KEY_NAME_CONFIG = "message.key";
private static final String MESSAGE_KEY_NAME_DOC = "Key of the message to be used for each message (optional).";
private static final String MESSAGE_KEY_NAME_DISPLAY = "Key message";

private static final String MESSAGE_TEMPLATE_CONFIG = "message.template";
private static final String MESSAGE_TEMPLATE_DOC = "Message template to be used for each message.";
private static final String MESSAGE_TEMPLATE_DISPLAY = "Message Template";
Expand Down Expand Up @@ -78,6 +82,14 @@ public class DatagenConnectorConfig extends AbstractConfig {
CONNECTOR_GROUP, 4,
ConfigDef.Width.LONG,
POLL_INTERVAL_DISPLAY)
.define(MESSAGE_KEY_NAME_CONFIG,
Type.STRING,
null, // Default value
Importance.MEDIUM,
MESSAGE_KEY_NAME_DOC,
CONNECTOR_GROUP, 5,
ConfigDef.Width.LONG,
MESSAGE_KEY_NAME_DISPLAY)
.define(MESSAGE_TEMPLATE_CONFIG,
Type.STRING,
Importance.MEDIUM,
Expand All @@ -104,6 +116,7 @@ public class DatagenConnectorConfig extends AbstractConfig {
public final String topicName;
public final int pollSize;
public final int pollInterval;
public final String messageKey;
public final String messageTemplate;
public final List<String> randomFields;
public final String eventTimestampField;
Expand All @@ -113,6 +126,7 @@ public DatagenConnectorConfig(ConfigDef definition, Map<?, ?> originals) {
this.topicName = getString(TOPIC_NAME_CONFIG);
this.pollSize = getInt(POLL_SIZE_CONFIG);
this.pollInterval = getInt(POLL_INTERVAL_CONFIG);
this.messageKey = getString(MESSAGE_KEY_NAME_CONFIG);
this.messageTemplate = getString(MESSAGE_TEMPLATE_CONFIG);
this.randomFields = getList(RANDOM_FIELDS_CONFIG);
this.eventTimestampField = getString(EVENT_TIMESTAMP_FIELD_CONFIG);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,16 @@ public List<SourceRecord> poll() throws InterruptedException {

msg.addProperty(config.eventTimestampField, nanos);

records.add(new SourceRecord(sourcePartition, sourceOffset, config.topicName, Schema.STRING_SCHEMA, gson.toJson(msg)));
if(config.messageKey != null && config.messageKey.length() != 0 ) {

records.add(new SourceRecord(sourcePartition, sourceOffset, config.topicName, Schema.STRING_SCHEMA, config.messageKey, Schema.STRING_SCHEMA, gson.toJson(msg)));

} else {

records.add(new SourceRecord(sourcePartition, sourceOffset, config.topicName, Schema.STRING_SCHEMA, gson.toJson(msg)));
}


}

return records;
Expand Down