This is an automated email from the ASF dual-hosted git repository.
rxl pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/pulsar-client-go.git
The following commit(s) were added to refs/heads/master by this push:
new fb10d4f deduplicate user topics before using them (#426)
fb10d4f is described below
commit fb10d4f557639df342a649be367c44e5ae62e4eb
Author: wuYin <[email protected]>
AuthorDate: Mon Jan 4 19:12:44 2021 +0800
deduplicate user topics before using them (#426)
### Motivation
- Deduplicate user topics before using them, just like client-java's
`TreeSet` topics implementation, see
[ConsumerConfigurationData.java#L56](https://github.com/apache/pulsar/blob/master/pulsar-client/src/main/java/org/apache/pulsar/client/impl/conf/ConsumerConfigurationData.java#L56)
### Modifications
- add `distinct` utility function to deduplicate user provided topics
---
pulsar/consumer_impl.go | 13 +++++++++++++
1 file changed, 13 insertions(+)
diff --git a/pulsar/consumer_impl.go b/pulsar/consumer_impl.go
index 370ea12..6379993 100644
--- a/pulsar/consumer_impl.go
+++ b/pulsar/consumer_impl.go
@@ -164,6 +164,7 @@ func newConsumer(client *client, options ConsumerOptions)
(Consumer, error) {
for i := range options.Topics {
options.Topics[i] = tns[i].Name
}
+ options.Topics = distinct(options.Topics)
return newMultiTopicConsumer(client, options, options.Topics,
messageCh, dlq, rlq)
}
@@ -555,6 +556,18 @@ func generateRandomName() string {
return string(bytes)
}
+func distinct(fqdnTopics []string) []string {
+ set := make(map[string]struct{})
+ uniques := make([]string, 0, len(fqdnTopics))
+ for _, topic := range fqdnTopics {
+ if _, ok := set[topic]; !ok {
+ set[topic] = struct{}{}
+ uniques = append(uniques, topic)
+ }
+ }
+ return uniques
+}
+
func toProtoSubType(st SubscriptionType) pb.CommandSubscribe_SubType {
switch st {
case Exclusive: