Copilot commented on code in PR #1456:
URL: https://github.com/apache/pulsar-client-go/pull/1456#discussion_r2696638788
##########
pulsar/consumer_regex_test.go:
##########
@@ -513,3 +513,70 @@ func TestRegexTopicGetLastMessageIDs(t *testing.T) {
assert.Equal(t, 1, len(messages))
}
}
+
+func TestRegexConsumerReconsumeLater(t *testing.T) {
+ client, err := NewClient(ClientOptions{
+ URL: lookupURL,
+ })
+ assert.Nil(t, err)
+ defer client.Close()
+
+ topic1 := fmt.Sprintf("regex-reconsume-topic-%v",
time.Now().Nanosecond())
+ assert.Nil(t, createPartitionedTopic(topic1, 1))
+
+ topic2 := fmt.Sprintf("regex-reconsume-topic-%v",
time.Now().Nanosecond())
Review Comment:
Using `time.Now().Nanosecond()` for generating unique topic names is
unreliable because `Nanosecond()` only returns the nanosecond offset within the
current second (0-999999999), not a unique timestamp. If the test runs multiple
times within the same nanosecond offset of different seconds, or if topics are
created in quick succession, name collisions can occur. Use
`time.Now().UnixNano()` instead to generate truly unique topic names.
```suggestion
topic1 := fmt.Sprintf("regex-reconsume-topic-%v", time.Now().UnixNano())
assert.Nil(t, createPartitionedTopic(topic1, 1))
topic2 := fmt.Sprintf("regex-reconsume-topic-%v", time.Now().UnixNano())
```
##########
pulsar/consumer_regex.go:
##########
@@ -454,6 +458,14 @@ func (c *regexConsumer) topics() ([]string, error) {
}
filtered := filterTopics(topics, c.pattern)
+
+ if c.options.RetryEnable && c.options.DLQ != nil {
+ retryTopic := c.options.DLQ.RetryLetterTopic
+ if !slices.Contains(filtered, retryTopic) {
Review Comment:
The check `c.options.DLQ != nil` is insufficient. If `RetryEnable` is true
but `RetryLetterTopic` is empty (which can happen if Comment 1's issue causes
initialization to fail), this code will add an empty string to the filtered
topics list, causing subscription errors. Add a check `retryTopic != \"\"`
before appending to the filtered list.
```suggestion
if retryTopic != "" && !slices.Contains(filtered, retryTopic) {
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]