@@ -1580,12 +1580,23 @@ func DLQWithProducerOptions(t *testing.T, prodOpt *ProducerOptions) {
1580
1580
defer producer .Close ()
1581
1581
1582
1582
// send 10 messages
1583
+ eventTimeList := make ([]time.Time , 10 )
1584
+ msgIDList := make ([]string , 10 )
1585
+ msgKeyList := make ([]string , 10 )
1583
1586
for i := 0 ; i < 10 ; i ++ {
1584
- if _ , err := producer .Send (ctx , & ProducerMessage {
1585
- Payload : []byte (fmt .Sprintf ("hello-%d" , i )),
1586
- }); err != nil {
1587
+ eventTime := time .Now ()
1588
+ eventTimeList [i ] = eventTime
1589
+ msgKeyList [i ] = fmt .Sprintf ("key-%d" , i )
1590
+ msgID , err := producer .Send (ctx , & ProducerMessage {
1591
+ Payload : []byte (fmt .Sprintf ("hello-%d" , i )),
1592
+ Key : fmt .Sprintf ("key-%d" , i ),
1593
+ OrderingKey : fmt .Sprintf ("key-%d" , i ),
1594
+ EventTime : eventTime ,
1595
+ })
1596
+ if err != nil {
1587
1597
log .Fatal (err )
1588
1598
}
1599
+ msgIDList [i ] = msgID .String ()
1589
1600
}
1590
1601
1591
1602
// receive 10 messages and only ack half-of-them
@@ -1624,10 +1635,25 @@ func DLQWithProducerOptions(t *testing.T, prodOpt *ProducerOptions) {
1624
1635
assert .True (t , regex .MatchString (msg .ProducerName ()))
1625
1636
1626
1637
// check original messageId
1638
+ assert .NotEmpty (t , msg .Properties ()[SysPropertyOriginMessageID ])
1639
+ assert .Equal (t , msgIDList [expectedMsgIdx ], msg .Properties ()[SysPropertyOriginMessageID ])
1627
1640
assert .NotEmpty (t , msg .Properties ()[PropertyOriginMessageID ])
1641
+ assert .Equal (t , msgIDList [expectedMsgIdx ], msg .Properties ()[PropertyOriginMessageID ])
1628
1642
1629
1643
// check original topic
1630
- assert .NotEmpty (t , msg .Properties ()[SysPropertyRealTopic ])
1644
+ assert .Contains (t , msg .Properties ()[SysPropertyRealTopic ], topic )
1645
+
1646
+ // check original key
1647
+ assert .NotEmpty (t , msg .Key ())
1648
+ assert .Equal (t , msgKeyList [expectedMsgIdx ], msg .Key ())
1649
+ assert .NotEmpty (t , msg .OrderingKey ())
1650
+ assert .Equal (t , msgKeyList [expectedMsgIdx ], msg .OrderingKey ())
1651
+
1652
+ // check original event time
1653
+ // Broker will ignore event time microsecond(us) level precision,
1654
+ // so that we need to check eventTime precision in millisecond level
1655
+ assert .NotEqual (t , 0 , msg .EventTime ())
1656
+ assert .True (t , eventTimeList [expectedMsgIdx ].Sub (msg .EventTime ()).Abs () < 2 * time .Millisecond )
1631
1657
}
1632
1658
1633
1659
// No more messages on the DLQ
@@ -1855,9 +1881,21 @@ func TestRLQ(t *testing.T) {
1855
1881
assert .Nil (t , err )
1856
1882
defer producer .Close ()
1857
1883
1884
+ eventTimeList := make ([]time.Time , N )
1885
+ msgIDList := make ([]string , N )
1886
+ msgKeyList := make ([]string , N )
1858
1887
for i := 0 ; i < N ; i ++ {
1859
- _ , err = producer .Send (ctx , & ProducerMessage {Payload : []byte (fmt .Sprintf ("MESSAGE_%d" , i ))})
1888
+ eventTime := time .Now ()
1889
+ eventTimeList [i ] = eventTime
1890
+ msgKeyList [i ] = fmt .Sprintf ("key-%d" , i )
1891
+ msgID , err := producer .Send (ctx , & ProducerMessage {
1892
+ Payload : []byte (fmt .Sprintf ("MESSAGE_%d" , i )),
1893
+ Key : fmt .Sprintf ("key-%d" , i ),
1894
+ OrderingKey : fmt .Sprintf ("key-%d" , i ),
1895
+ EventTime : eventTime ,
1896
+ })
1860
1897
assert .Nil (t , err )
1898
+ msgIDList [i ] = msgID .String ()
1861
1899
}
1862
1900
1863
1901
// 2. Create consumer on the Retry Topic to reconsume N messages (maxRedeliveries+1) times
@@ -1903,6 +1941,31 @@ func TestRLQ(t *testing.T) {
1903
1941
dlqReceived := 0
1904
1942
for dlqReceived < N {
1905
1943
msg , err := dlqConsumer .Receive (ctx )
1944
+ // check original messageId
1945
+ // we create a topic with three partitions,
1946
+ // so that messages maybe not be received as the same order as we produced
1947
+ assert .NotEmpty (t , msg .Properties ()[SysPropertyOriginMessageID ])
1948
+ assert .Contains (t , msgIDList , msg .Properties ()[SysPropertyOriginMessageID ])
1949
+ assert .NotEmpty (t , msg .Properties ()[PropertyOriginMessageID ])
1950
+ assert .Contains (t , msgIDList , msg .Properties ()[PropertyOriginMessageID ])
1951
+
1952
+ // check original topic
1953
+ assert .Contains (t , msg .Properties ()[SysPropertyRealTopic ], topic )
1954
+
1955
+ // check original key
1956
+ assert .NotEmpty (t , msg .Key ())
1957
+ assert .Contains (t , msgKeyList , msg .Key ())
1958
+ assert .NotEmpty (t , msg .OrderingKey ())
1959
+ assert .Contains (t , msgKeyList , msg .OrderingKey ())
1960
+
1961
+ // check original event time
1962
+ assert .NotEqual (t , 0 , msg .EventTime ())
1963
+ // check original event time
1964
+ // Broker will ignore event time microsecond(us) level precision,
1965
+ // so that we need to check eventTime precision in millisecond level
1966
+ assert .LessOrEqual (t , eventTimeList [0 ].Add (- 2 * time .Millisecond ), msg .EventTime ())
1967
+ assert .LessOrEqual (t , msg .EventTime (), eventTimeList [N - 1 ].Add (2 * time .Millisecond ))
1968
+
1906
1969
assert .Nil (t , err )
1907
1970
dlqConsumer .Ack (msg )
1908
1971
dlqReceived ++
0 commit comments