apache / apache/rocketmq-client-go

PullConsumer Interface semantic issues

Open
#1,044 1 comment 0 reactions 0 assignees View on GitHub
help wanted
Dominant language
Go
Stars
1.4k
Forks
445
PR merge metrics
No merged PRs in 30d

Description

I noticed that PullConsumer has the following interface:
```golang
Subscribe(topic string, selector consumer.MessageSelector) error
Pull(ctx context.Context, numbers int) (*primitive.PullResult, error)
```
When I subscribe to multiple topics using the same consumer. Calling the `pull` method, I cannot figure out which topic's data is being pulled.

The business requirement is to use a pull mode consumer to subscribe to multiple topics.

The pseudocode is as follows:

```goalng
var nameSrv, _ = primitive.NewNamesrvAddr(nameServerAddr)
pullConsumer, _ := mqcliv2.NewPullConsumer(
consumer.WithGroupName("test"),
consumer.WithNameServer(nameSrv),
...
)
var topics := queryFormDB(...)
topics.range(func(item) {
go func() {
pullConsumer.Subscribe(topic,...)
.....

}
})

pullConsumer.Start()
....
```

At this point, when I execute the `pullConsumer.Pull(...)` method, it is no longer semantically certain which topic's data is being pulled. (However, topic data can be indirectly obtained from the return value data), as is well known, the reason for this is that every call to Subscribe will reassign `pc. topic=topic`(https://github.com/apache/rocketmq-client-go/blob/8ea107c9b0ffb8aea61b9ea581899023a7b9b5a6/consumer/pull_consumer.go#LL132C12-L132C12). The calling order of Subscribe is unclear, and the final value of `pc.topic` cannot be determined.

Therefore, I believe that the semantics of the PULL method are not very clear. It only means obtaining data from the latest pc.topic. thank you.
We look forward to your reply.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.