Skip to content

Commit f50747e

Browse files
committed
Added orig_broker_name to metadata
..since orig_broker_id will be -1 for bootstrap brokers.
1 parent ab2c278 commit f50747e

File tree

3 files changed

+8
-3
lines changed

3 files changed

+8
-3
lines changed

examples/rdkafka_example.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -168,9 +168,10 @@ static void metadata_print (const char *topic,
168168
const struct rd_kafka_metadata *metadata) {
169169
int i, j, k;
170170

171-
printf("Metadata for %s (from broker %"PRId32"):\n",
171+
printf("Metadata for %s (from broker %"PRId32": %s):\n",
172172
topic ? : "all topics",
173-
metadata->orig_broker_id);
173+
metadata->orig_broker_id,
174+
metadata->orig_broker_name);
174175

175176

176177
/* Iterate brokers */

src/rdkafka.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -895,6 +895,7 @@ struct rd_kafka_metadata {
895895
struct rd_kafka_metadata_topic *topics; /* Topics */
896896

897897
int32_t orig_broker_id; /* Broker originating this metadata */
898+
char *orig_broker_name; /* Name of originating broker */
898899
};
899900

900901

src/rdkafka_broker.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -797,14 +797,17 @@ rd_kafka_metadata_handle (rd_kafka_broker_t *rkb,
797797
int msh_of = 0;
798798
int msh_size;
799799
struct rd_kafka_metadata *md = NULL;
800+
int rkb_namelen = strlen(rkb->rkb_name)+1;
800801

801802
/* We assume that the marshalled representation is
802803
* no more than 4 times larger than the wire representation. */
803-
msh_size = sizeof(*md) + (size * 4);
804+
msh_size = sizeof(*md) + rkb_namelen + (size * 4);
804805
msh_buf = malloc(msh_size);
805806

806807
_MSH_ALLOC(md, sizeof(*md));
807808
md->orig_broker_id = rkb->rkb_nodeid;
809+
_MSH_ALLOC(md->orig_broker_name, rkb_namelen);
810+
memcpy(md->orig_broker_name, rkb->rkb_name, rkb_namelen);
808811

809812
/* Read Brokers */
810813
_READ_I32A(md->broker_cnt);

0 commit comments

Comments
 (0)