@@ -164,7 +164,7 @@ static PyObject* KafkaError_richcompare (KafkaError *self, PyObject *o2,
164
164
Py_INCREF (result );
165
165
return result ;
166
166
}
167
-
167
+
168
168
169
169
static PyTypeObject KafkaErrorType = {
170
170
PyVarObject_HEAD_INIT (NULL , 0 )
@@ -326,6 +326,14 @@ static PyObject *Message_offset (Message *self, PyObject *ignore) {
326
326
}
327
327
328
328
329
+ static PyObject * Message_timestamp (Message * self , PyObject * ignore ) {
330
+ if (self -> timestamp > 0 )
331
+ return PyLong_FromLong (self -> timestamp );
332
+ else
333
+ Py_RETURN_NONE ;
334
+ }
335
+
336
+
329
337
static PyMethodDef Message_methods [] = {
330
338
{ "error" , (PyCFunction )Message_error , METH_NOARGS ,
331
339
" The message object is also used to propagate errors and events, "
@@ -362,6 +370,11 @@ static PyMethodDef Message_methods[] = {
362
370
" :rtype: int or None\n"
363
371
"\n"
364
372
},
373
+ { "timestamp" , (PyCFunction )Message_timestamp , METH_NOARGS ,
374
+ " :returns: message timestamp or None if not available.\n"
375
+ " :rtype: int or None\n"
376
+ "\n"
377
+ },
365
378
{ NULL }
366
379
};
367
380
@@ -495,6 +508,12 @@ PyObject *Message_new0 (const rd_kafka_message_t *rkm) {
495
508
self -> partition = rkm -> partition ;
496
509
self -> offset = rkm -> offset ;
497
510
511
+ rd_kafka_timestamp_type_t tstype ;
512
+ self -> timestamp = rd_kafka_message_timestamp (rkm , & tstype );
513
+ if (tstype != RD_KAFKA_TIMESTAMP_NOT_AVAILABLE ) {
514
+ // todo: make tstype available to python api
515
+ }
516
+
498
517
return (PyObject * )self ;
499
518
}
500
519
@@ -560,7 +579,7 @@ static PyObject *TopicPartition_new (PyTypeObject *type, PyObject *args,
560
579
561
580
return TopicPartition_new0 (topic , partition , offset , 0 );
562
581
}
563
-
582
+
564
583
565
584
566
585
static int TopicPartition_traverse (TopicPartition * self ,
@@ -758,7 +777,7 @@ PyObject *c_parts_to_py (const rd_kafka_topic_partition_list_t *c_parts) {
758
777
}
759
778
760
779
return parts ;
761
-
780
+
762
781
}
763
782
764
783
/**
0 commit comments