Skip to content
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

Support Fixed key #123

Merged
merged 6 commits into from
Nov 7, 2017
Merged
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
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
FROM debian:stretch-slim

ARG librdkafka_version=v0.11.1-RC1
ARG librdkafka_version=v0.11.1
ARG yajl_version=2.1.0

COPY . /usr/src/kafkacat
Expand Down
15 changes: 14 additions & 1 deletion kafkacat.c
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ struct conf conf = {
.partition = RD_KAFKA_PARTITION_UA,
.msg_size = 1024*1024,
.null_str = "NULL",
.fixed_key = NULL
};

static struct stats {
Expand Down Expand Up @@ -350,6 +351,11 @@ static void producer_run (FILE *fp, char **paths, int pathcnt) {
}
}

if (!key && conf.fixed_key) {
key = conf.fixed_key;
key_len = conf.fixed_key_len;
}

if (!(msgflags & RD_KAFKA_MSG_F_COPY) &&
len > 1024 && !(conf.flags & CONF_F_TEE)) {
/* If message is larger than this arbitrary
Expand Down Expand Up @@ -936,6 +942,9 @@ static void RD_NORETURN usage (const char *argv0, int exitcode,
" -p -1 Use random partitioner\n"
" -D <delim> Delimiter to split input into messages\n"
" -K <delim> Delimiter to split input key and message\n"
" -k <str> Use a fixed key for all messages.\n"
" If combined with -K, per-message keys\n"
" takes precendence.\n"
" -l Send messages from a file separated by\n"
" delimiter, as with stdin.\n"
" (only one file allowed)\n"
Expand Down Expand Up @@ -1146,7 +1155,7 @@ static void argparse (int argc, char **argv,
int do_conf_dump = 0;

while ((opt = getopt(argc, argv,
"PCG:LQt:p:b:z:o:eED:K:Od:qvX:c:Tuf:ZlVh"
"PCG:LQt:p:b:z:o:eED:K:k:Od:qvX:c:Tuf:ZlVh"
#if ENABLE_JSON
"J"
#endif
Expand Down Expand Up @@ -1226,6 +1235,10 @@ static void argparse (int argc, char **argv,
key_delim = optarg;
conf.flags |= CONF_F_KEY_DELIM;
break;
case 'k':
conf.fixed_key = optarg;
conf.fixed_key_len = (size_t)(strlen(conf.fixed_key));
break;
case 'l':
conf.flags |= CONF_F_LINE;
break;
Expand Down
2 changes: 2 additions & 0 deletions kafkacat.h
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,8 @@ struct conf {
char *topic;
int32_t partition;
char *group;
char *fixed_key;
int32_t fixed_key_len;
int64_t offset;
int exit_eof;
int64_t msg_cnt;
Expand Down