-
Notifications
You must be signed in to change notification settings - Fork 10
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
Make it possible to react on rebalance #27
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -75,8 +75,35 @@ CAMLprim value ocaml_kafka_async_new_producer(value caml_delivery_callback, valu | |||||||||||
CAMLreturn(result); | ||||||||||||
} | ||||||||||||
|
||||||||||||
CAMLprim value ocaml_kafka_async_new_consumer(value caml_consumer_options) { | ||||||||||||
CAMLparam1(caml_consumer_options); | ||||||||||||
static void ocaml_kafka_async_rebalance_cb(rd_kafka_t *rk, rd_kafka_resp_err_t err, rd_kafka_topic_partition_list_t *partitions, void *opaque) { | ||||||||||||
CAMLparam0(); | ||||||||||||
CAMLlocal1(caml_cb); | ||||||||||||
|
||||||||||||
caml_cb = ((ocaml_kafka_opaque*)opaque)->caml_callback; | ||||||||||||
|
||||||||||||
// do the default thing, but also call our OCaml code | ||||||||||||
switch (err) | ||||||||||||
{ | ||||||||||||
case RD_KAFKA_RESP_ERR__ASSIGN_PARTITIONS: | ||||||||||||
rd_kafka_assign(rk, partitions); | ||||||||||||
caml_callback(caml_cb, Val_unit); | ||||||||||||
break; | ||||||||||||
|
||||||||||||
case RD_KAFKA_RESP_ERR__REVOKE_PARTITIONS: | ||||||||||||
rd_kafka_commit(rk, partitions, 0); | ||||||||||||
rd_kafka_assign(rk, NULL); | ||||||||||||
caml_callback(caml_cb, Val_unit); | ||||||||||||
break; | ||||||||||||
|
||||||||||||
default: | ||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this is missing a call to
|
||||||||||||
break; | ||||||||||||
} | ||||||||||||
|
||||||||||||
CAMLreturn0; | ||||||||||||
} | ||||||||||||
|
||||||||||||
CAMLprim value ocaml_kafka_async_new_consumer(value caml_rebalance_callback, value caml_consumer_options) { | ||||||||||||
CAMLparam2(caml_rebalance_callback, caml_consumer_options); | ||||||||||||
CAMLlocal1(result); | ||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||
|
||||||||||||
char error_msg[160]; | ||||||||||||
|
@@ -88,8 +115,16 @@ CAMLprim value ocaml_kafka_async_new_consumer(value caml_consumer_options) { | |||||||||||
CAMLreturn(result); | ||||||||||||
} | ||||||||||||
|
||||||||||||
ocaml_kafka_opaque* opaque = NULL; | ||||||||||||
if (Is_block(caml_rebalance_callback)) { | ||||||||||||
opaque = ocaml_kafka_opaque_create(caml_rebalance_callback); | ||||||||||||
Comment on lines
+119
to
+120
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||
rd_kafka_conf_set_opaque(conf, (void*) opaque); | ||||||||||||
rd_kafka_conf_set_rebalance_cb(conf, ocaml_kafka_async_rebalance_cb); | ||||||||||||
} | ||||||||||||
|
||||||||||||
rd_kafka_t *handler = rd_kafka_new(RD_KAFKA_CONSUMER, conf, error_msg, sizeof(error_msg)); | ||||||||||||
if (handler == NULL) { | ||||||||||||
ocaml_kafka_opaque_destroy(opaque); | ||||||||||||
rd_kafka_conf_destroy(conf); | ||||||||||||
result = ERROR(RD_KAFKA_RESP_ERR__FAIL, "Failed to create new kafka consumer (%s)", error_msg); | ||||||||||||
CAMLreturn(result); | ||||||||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this should probably handle cooperative assignors too, and call
rd_kafka_incremental_assign
(see https://docs.confluent.io/platform/current/clients/librdkafka/html/rdkafka_8h.html#a10db731dc1a295bd9884e4f8cb199311)