-
Notifications
You must be signed in to change notification settings - Fork 934
Add timestamp() to librdkafka messages #50
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
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
- Loading branch information
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -326,6 +326,14 @@ static PyObject *Message_offset (Message *self, PyObject *ignore) { | |
| } | ||
|
|
||
|
|
||
| static PyObject *Message_timestamp (Message *self, PyObject *ignore) { | ||
| if (self->timestamp > 0) | ||
|
||
| return PyLong_FromLong(self->timestamp); | ||
| else | ||
| Py_RETURN_NONE; | ||
| } | ||
|
|
||
|
|
||
| static PyMethodDef Message_methods[] = { | ||
| { "error", (PyCFunction)Message_error, METH_NOARGS, | ||
| " The message object is also used to propagate errors and events, " | ||
|
|
@@ -362,6 +370,11 @@ static PyMethodDef Message_methods[] = { | |
| " :rtype: int or None\n" | ||
| "\n" | ||
| }, | ||
| { "timestamp", (PyCFunction)Message_timestamp, METH_NOARGS, | ||
|
Contributor
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. It needs to return the timestamp type as well (none, append, create).
Contributor
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. Please add the timestamp type as a class level constant, e.g.: |
||
| " :returns: message timestamp or None if not available.\n" | ||
| " :rtype: int or None\n" | ||
|
||
| "\n" | ||
| }, | ||
| { NULL } | ||
| }; | ||
|
|
||
|
|
@@ -495,6 +508,12 @@ PyObject *Message_new0 (const rd_kafka_message_t *rkm) { | |
| self->partition = rkm->partition; | ||
| self->offset = rkm->offset; | ||
|
|
||
| rd_kafka_timestamp_type_t tstype; | ||
|
||
| self->timestamp = rd_kafka_message_timestamp(rkm, &tstype); | ||
| if (tstype != RD_KAFKA_TIMESTAMP_NOT_AVAILABLE) { | ||
| // todo: make tstype available to python api | ||
| } | ||
|
|
||
| return (PyObject *)self; | ||
| } | ||
|
|
||
|
|
||
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.
I think it would be better to have a single timestamp() method that returns a tuple: tstype, timestamp