[pulsar-client] Avoid subscribing the same topic again (#7823)
### Motivation The current key of `MultiTopicsConsumerImpl.topics` is the topic name passed by user. The `topicNameValid` method checks if the name is valid and `topics` doesn't contain the key. However, if a multi topics consumer subscribed a partition of a subscribed partitioned topic, `subscribeAsync` succeed and a new `ConsumerImpl` of the same partition was created, which is redundant. Also, if a multi topics consumer subscribed `public/default/topic` or `persistent://public/default/topic`, while the initial subscribed topic is `topic`, the redundant consumers would be created. ### Modifications - Use full topic name as key of `MultiTopicsConsumerImpl.topics` - Check both full topic name and full partitioned topic name not exist in `MultiTopicsConsumerImpl.topics` when `subscribeAsync` is called - Throw a different exception to differ topic is invalid and topic is already subscribed - Add a unit test for subscribing a partition of a subscribed partitioned topic or the same topic with prefix
Showing
想要评论请 注册 或 登录