guyinyou commented on code in PR #1110: URL: https://github.com/apache/rocketmq-clients/pull/1110#discussion_r2485418404
########## golang/lite_push_consumer_options.go: ########## @@ -0,0 +1,143 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package golang + +import ( + "fmt" + "time" + + v2 "github.com/apache/rocketmq-clients/golang/v5/protocol/v2" + "google.golang.org/protobuf/types/known/durationpb" +) + +var _ = ClientSettings(&litePushConsumerSettings{}) + +type litePushConsumerSettings struct { + *pushConsumerSettings + bingTopic string + liteTopicSet map[string]struct{} Review Comment: lite topic可以随时更改订阅信息,这里是不是应该主动增加并发保护,例如增加sync.Mutex,或者使用sync.Map,否则在并发读写过程中可能出现panic ########## golang/lite_push_consumer_options.go: ########## @@ -0,0 +1,143 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package golang + +import ( + "fmt" + "time" + + v2 "github.com/apache/rocketmq-clients/golang/v5/protocol/v2" + "google.golang.org/protobuf/types/known/durationpb" +) + +var _ = ClientSettings(&litePushConsumerSettings{}) + +type litePushConsumerSettings struct { + *pushConsumerSettings + bingTopic string Review Comment: 这里应该是bindtopic? ########## golang/lite_push_consumer.go: ########## @@ -0,0 +1,204 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package golang + +import ( + "context" + "errors" + "time" + + "github.com/apache/rocketmq-clients/golang/v5/pkg/ticker" + v2 "github.com/apache/rocketmq-clients/golang/v5/protocol/v2" + "github.com/google/uuid" + "google.golang.org/protobuf/types/known/durationpb" +) + +type LitePushConsumer interface { + PushConsumer + SubscribeLite(liteTopic string) error + UnSubscribeLite(liteTopic string) error +} + +var _ = LitePushConsumer(&defaultLitePushConsumer{}) + +type defaultLitePushConsumer struct { + *defaultPushConsumer + litePushConsumerSettings *litePushConsumerSettings +} + +type LitePushConsumerConfig struct { + bindTopic string + invisibleDuration time.Duration +} + +func NewLitePushConsumerConfig(bindTopic string, invisibleDuration time.Duration) *LitePushConsumerConfig { + return &LitePushConsumerConfig{ + bindTopic: bindTopic, + invisibleDuration: invisibleDuration, + } +} + +var NewLitePushConsumer = func(config *Config, liteConfig *LitePushConsumerConfig, opts ...PushConsumerOption) (LitePushConsumer, error) { + if liteConfig.bindTopic == "" { + return nil, errors.New("LitePushConsumerConfig.bindTopic is required") + } + filterExpressionMap := map[string]*FilterExpression{ + liteConfig.bindTopic: SUB_ALL, + } + if liteConfig == nil { Review Comment: 这里的 nil 检查是不是应该提到函数最开始的地方。 因为前面已经访问了liteConfig.bindTopic,如果为空会直接panic。 -- 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]
