@@ -1580,12 +1580,26 @@ 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
+ Properties : map [string ]string {
1596
+ "key" : fmt .Sprintf ("key-%d" , i ),
1597
+ },
1598
+ })
1599
+ if err != nil {
1587
1600
log .Fatal (err )
1588
1601
}
1602
+ msgIDList [i ] = msgID .String ()
1589
1603
}
1590
1604
1591
1605
// receive 10 messages and only ack half-of-them
@@ -1624,10 +1638,27 @@ func DLQWithProducerOptions(t *testing.T, prodOpt *ProducerOptions) {
1624
1638
assert .True (t , regex .MatchString (msg .ProducerName ()))
1625
1639
1626
1640
// check original messageId
1641
+ assert .NotEmpty (t , msg .Properties ()[SysPropertyOriginMessageID ])
1642
+ assert .Equal (t , msgIDList [expectedMsgIdx ], msg .Properties ()[SysPropertyOriginMessageID ])
1627
1643
assert .NotEmpty (t , msg .Properties ()[PropertyOriginMessageID ])
1644
+ assert .Equal (t , msgIDList [expectedMsgIdx ], msg .Properties ()[PropertyOriginMessageID ])
1628
1645
1629
1646
// check original topic
1630
- assert .NotEmpty (t , msg .Properties ()[SysPropertyRealTopic ])
1647
+ assert .Contains (t , msg .Properties ()[SysPropertyRealTopic ], topic )
1648
+
1649
+ // check original key
1650
+ assert .NotEmpty (t , msg .Key ())
1651
+ assert .Equal (t , msgKeyList [expectedMsgIdx ], msg .Key ())
1652
+ assert .NotEmpty (t , msg .OrderingKey ())
1653
+ assert .Equal (t , msgKeyList [expectedMsgIdx ], msg .OrderingKey ())
1654
+ assert .NotEmpty (t , msg .Properties ()["key" ])
1655
+ assert .Equal (t , msg .Key (), msg .Properties ()["key" ])
1656
+
1657
+ // check original event time
1658
+ // Broker will ignore event time microsecond(us) level precision,
1659
+ // so that we need to check eventTime precision in millisecond level
1660
+ assert .NotEqual (t , 0 , msg .EventTime ())
1661
+ assert .True (t , eventTimeList [expectedMsgIdx ].Sub (msg .EventTime ()).Abs () < 2 * time .Millisecond )
1631
1662
}
1632
1663
1633
1664
// No more messages on the DLQ
@@ -1855,9 +1886,24 @@ func TestRLQ(t *testing.T) {
1855
1886
assert .Nil (t , err )
1856
1887
defer producer .Close ()
1857
1888
1889
+ eventTimeList := make ([]time.Time , N )
1890
+ msgIDList := make ([]string , N )
1891
+ msgKeyList := make ([]string , N )
1858
1892
for i := 0 ; i < N ; i ++ {
1859
- _ , err = producer .Send (ctx , & ProducerMessage {Payload : []byte (fmt .Sprintf ("MESSAGE_%d" , i ))})
1893
+ eventTime := time .Now ()
1894
+ eventTimeList [i ] = eventTime
1895
+ msgKeyList [i ] = fmt .Sprintf ("key-%d" , i )
1896
+ msgID , err := producer .Send (ctx , & ProducerMessage {
1897
+ Payload : []byte (fmt .Sprintf ("MESSAGE_%d" , i )),
1898
+ Key : fmt .Sprintf ("key-%d" , i ),
1899
+ OrderingKey : fmt .Sprintf ("key-%d" , i ),
1900
+ EventTime : eventTime ,
1901
+ Properties : map [string ]string {
1902
+ "key" : fmt .Sprintf ("key-%d" , i ),
1903
+ },
1904
+ })
1860
1905
assert .Nil (t , err )
1906
+ msgIDList [i ] = msgID .String ()
1861
1907
}
1862
1908
1863
1909
// 2. Create consumer on the Retry Topic to reconsume N messages (maxRedeliveries+1) times
@@ -1903,6 +1949,33 @@ func TestRLQ(t *testing.T) {
1903
1949
dlqReceived := 0
1904
1950
for dlqReceived < N {
1905
1951
msg , err := dlqConsumer .Receive (ctx )
1952
+ // check original messageId
1953
+ // we create a topic with three partitions,
1954
+ // so that messages maybe not be received as the same order as we produced
1955
+ assert .NotEmpty (t , msg .Properties ()[SysPropertyOriginMessageID ])
1956
+ assert .Contains (t , msgIDList , msg .Properties ()[SysPropertyOriginMessageID ])
1957
+ assert .NotEmpty (t , msg .Properties ()[PropertyOriginMessageID ])
1958
+ assert .Contains (t , msgIDList , msg .Properties ()[PropertyOriginMessageID ])
1959
+
1960
+ // check original topic
1961
+ assert .Contains (t , msg .Properties ()[SysPropertyRealTopic ], topic )
1962
+
1963
+ // check original key
1964
+ assert .NotEmpty (t , msg .Key ())
1965
+ assert .Contains (t , msgKeyList , msg .Key ())
1966
+ assert .NotEmpty (t , msg .OrderingKey ())
1967
+ assert .Contains (t , msgKeyList , msg .OrderingKey ())
1968
+ assert .NotEmpty (t , msg .Properties ()["key" ])
1969
+ assert .Equal (t , msg .Key (), msg .Properties ()["key" ])
1970
+
1971
+ // check original event time
1972
+ assert .NotEqual (t , 0 , msg .EventTime ())
1973
+ // check original event time
1974
+ // Broker will ignore event time microsecond(us) level precision,
1975
+ // so that we need to check eventTime precision in millisecond level
1976
+ assert .LessOrEqual (t , eventTimeList [0 ].Add (- 2 * time .Millisecond ), msg .EventTime ())
1977
+ assert .LessOrEqual (t , msg .EventTime (), eventTimeList [N - 1 ].Add (2 * time .Millisecond ))
1978
+
1906
1979
assert .Nil (t , err )
1907
1980
dlqConsumer .Ack (msg )
1908
1981
dlqReceived ++
0 commit comments