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

DeliveryReport attached to Message for Producer Calls #1121

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
20 changes: 20 additions & 0 deletions kafka/message.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,11 @@ func (t TimestampType) String() string {
}
}

type DeliveryReport struct {
ProducerLatency int64
BrokerID int32
}

// Message represents a Kafka message
type Message struct {
TopicPartition TopicPartition
Expand All @@ -76,6 +81,7 @@ type Message struct {
Timestamp time.Time
TimestampType TimestampType
Opaque interface{}
DeliveryReport DeliveryReport
Headers []Header
LeaderEpoch *int32 // Deprecated: LeaderEpoch or nil if not available. Use m.TopicPartition.LeaderEpoch instead.
}
Expand Down Expand Up @@ -135,6 +141,20 @@ func (h *handle) newMessageFromGlueMsg(gMsg *C.glue_msg_t) (msg *Message) {
return msg
}

func generateDeliveryReport(msg *Message, cmsg *C.rd_kafka_message_t) {
msg.DeliveryReport = DeliveryReport{}

// The latency for a produced message measured from the produce() call.
producerLatency := int64(C.rd_kafka_message_latency(cmsg))
if producerLatency >= 0 {
msg.DeliveryReport.ProducerLatency = producerLatency
}

// The latency for a produced message measured from the produce() call.
brokerId := int32(C.rd_kafka_message_broker_id(cmsg))
msg.DeliveryReport.BrokerID = brokerId
}

// setupMessageFromC sets up a message object from a C rd_kafka_message_t
func (h *handle) setupMessageFromC(msg *Message, cmsg *C.rd_kafka_message_t) {
if cmsg.rkt != nil {
Expand Down
6 changes: 6 additions & 0 deletions kafka/producer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,12 @@ func TestProducerAPIs(t *testing.T) {
switch e := ev.(type) {
case *Message:
msgCnt++
if *&e.DeliveryReport.ProducerLatency <= 0 {
t.Errorf("Producer Latency should be included in delivery reports, instead got %d", *&e.DeliveryReport.ProducerLatency)
}
if *&e.DeliveryReport.BrokerID == -1 {
t.Errorf("Broker ID should be included in delivery reports, instead got %d", *&e.DeliveryReport.BrokerID)
}
if (string)(e.Value) == "ProducerChannel" {
s := e.Opaque.(*string)
if s != &myOpq {
Expand Down