浏览代码

Don't try and parse a timestamp of -1

As Yingnan Liu pointed out in #697, brokers configured with `CreateTime` instead
of `LogAppendTime` send back -1 for the timestamp, which doesn't parse to
something meaningful in Go.
Evan Huus 9 年之前
父节点
当前提交
7f0fe2ddaf
共有 1 个文件被更改,包括 5 次插入4 次删除
  1. 5 4
      produce_response.go

+ 5 - 4
produce_response.go

@@ -3,9 +3,10 @@ package sarama
 import "time"
 import "time"
 
 
 type ProduceResponseBlock struct {
 type ProduceResponseBlock struct {
-	Err       KError
-	Offset    int64
-	Timestamp time.Time // only provided if Version >= 2
+	Err    KError
+	Offset int64
+	// only provided if Version >= 2 and the broker is configured with `LogAppendTime`
+	Timestamp time.Time
 }
 }
 
 
 func (b *ProduceResponseBlock) decode(pd packetDecoder, version int16) (err error) {
 func (b *ProduceResponseBlock) decode(pd packetDecoder, version int16) (err error) {
@@ -23,7 +24,7 @@ func (b *ProduceResponseBlock) decode(pd packetDecoder, version int16) (err erro
 	if version >= 2 {
 	if version >= 2 {
 		if millis, err := pd.getInt64(); err != nil {
 		if millis, err := pd.getInt64(); err != nil {
 			return err
 			return err
-		} else {
+		} else if millis != -1 {
 			b.Timestamp = time.Unix(millis/1000, (millis%1000)*int64(time.Millisecond))
 			b.Timestamp = time.Unix(millis/1000, (millis%1000)*int64(time.Millisecond))
 		}
 		}
 	}
 	}