You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@rocketmq.apache.org by GitBox <gi...@apache.org> on 2021/12/02 14:03:34 UTC

[GitHub] [rocketmq-client-go] shendongsd opened a new pull request #750: the first version of high-level-pull-consumer

shendongsd opened a new pull request #750:
URL: https://github.com/apache/rocketmq-client-go/pull/750


   ## What is the purpose of the change
   
   [#738](https://github.com/apache/rocketmq-client-go/issues/738)
   
   ## Brief changelog
   
   the first version of high-level-pull-consumer, I have reused a lot of pushcousumer code, it feels a bit messy, do you need to refactor the code structure, submit it now, let’s see how to implement it later
   
   ## Verifying this change
   
   XXXX
   
   Follow this checklist to help us incorporate your contribution quickly and easily. Notice, `it would be helpful if you could finish the following 5 checklist(the last one is not necessary)before request the community to review your PR`.
   
   - [x] Make sure there is a [Github issue](https://github.com/apache/rocketmq/issues) filed for the change (usually before you start working on it). Trivial changes like typos do not require a Github issue. Your pull request should address just this issue, without pulling in other changes - one PR resolves one issue. 
   - [x] Format the pull request title like `[ISSUE #123] Fix UnknownException when host config not exist`. Each commit in the pull request should have a meaningful subject line and body.
   - [x] Write a pull request description that is detailed enough to understand what the pull request does, how, and why.
   - [x] Write necessary unit-test(over 80% coverage) to verify your logic correction, more mock a little better when a cross-module dependency exists.
   - [ ] If this contribution is large, please file an [Apache Individual Contributor License Agreement](http://www.apache.org/licenses/#clas).
   


-- 
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: dev-unsubscribe@rocketmq.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [rocketmq-client-go] shendongsd closed pull request #750: [ISSUE #738] the first version of high-level-pull-consumer

Posted by GitBox <gi...@apache.org>.
shendongsd closed pull request #750:
URL: https://github.com/apache/rocketmq-client-go/pull/750


   


-- 
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: dev-unsubscribe@rocketmq.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [rocketmq-client-go] wangweizZZ commented on a change in pull request #750: the first version of high-level-pull-consumer

Posted by GitBox <gi...@apache.org>.
wangweizZZ commented on a change in pull request #750:
URL: https://github.com/apache/rocketmq-client-go/pull/750#discussion_r765496018



##########
File path: api.go
##########
@@ -135,3 +135,30 @@ type PullConsumer interface {
 func NewPullConsumer(opts ...consumer.Option) (PullConsumer, error) {
 	return nil, errors.ErrPullConsumer
 }
+
+func NewHighLevelPullConsumer(opts ...consumer.Option) (defaultHighLevelPullConsumer, error) {
+	return consumer.NewHighLevelPullConsumer(opts...)
+}
+
+type defaultHighLevelPullConsumer interface {

Review comment:
       Interface can be defined as public

##########
File path: consumer/high_level_pull_consumer.go
##########
@@ -0,0 +1,473 @@
+/*
+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 consumer
+
+import (
+	"context"
+	"fmt"
+	errors2 "github.com/apache/rocketmq-client-go/v2/errors"
+	"github.com/apache/rocketmq-client-go/v2/internal"
+	"github.com/apache/rocketmq-client-go/v2/primitive"
+	"github.com/apache/rocketmq-client-go/v2/rlog"
+	"github.com/pkg/errors"
+	"strings"
+	"sync"
+	"sync/atomic"
+	"time"
+)
+
+type defaultHighLevelPullConsumer struct {
+	*defaultManualPullConsumer
+	consumerGroup           string
+	model                   MessageModel
+	namesrv                 internal.Namesrvs
+	option                  consumerOptions
+	client                  internal.RMQClient
+	interceptor             primitive.Interceptor
+	pullFromWhichNodeTable  sync.Map
+	storage                 OffsetStore
+	cType                   ConsumeType
+	state                   int32
+	subscriptionDataTable   sync.Map
+	allocate                func(string, string, []*primitive.MessageQueue, []string) []*primitive.MessageQueue
+	once                    sync.Once
+	unitMode                bool
+	topicSubscribeInfoTable sync.Map
+	subscribedTopic         map[string]string
+	closeOnce               sync.Once
+	done                    chan struct{}
+	consumerStartTimestamp  int64
+	processQueueTable       sync.Map
+	fromWhere               ConsumeFromWhere
+	stat                    *StatsManager
+}
+
+func NewHighLevelPullConsumer(options ...Option) (*defaultHighLevelPullConsumer, error) {
+	defaultOpts := defaultHighLevelPullConsumerOptions()
+	for _, apply := range options {
+		apply(&defaultOpts)
+	}
+
+	srvs, err := internal.NewNamesrv(defaultOpts.Resolver)
+	if err != nil {
+		return nil, errors.Wrap(err, "new Namesrv failed.")
+	}
+
+	defaultOpts.Namesrv = srvs
+
+	if defaultOpts.Namespace != "" {
+		defaultOpts.GroupName = defaultOpts.Namespace + "%" + defaultOpts.GroupName
+	}
+
+	dc := &defaultManualPullConsumer{
+		client:  internal.GetOrNewRocketMQClient(defaultOpts.ClientOptions, nil),
+		option:  defaultOpts,
+		namesrv: srvs,
+		group:   defaultOpts.GroupName,
+	}
+
+	hpc := &defaultHighLevelPullConsumer{
+		client:                    internal.GetOrNewRocketMQClient(defaultOpts.ClientOptions, nil),
+		consumerGroup:             defaultOpts.GroupName,
+		defaultManualPullConsumer: dc,
+		cType:                     _PullConsume,
+		state:                     int32(internal.StateCreateJust),
+		model:                     defaultOpts.ConsumerModel,
+		allocate:                  defaultOpts.Strategy,
+		namesrv:                   srvs,

Review comment:
       `GetOrSetNamesrv` will be  better

##########
File path: consumer/high_level_pull_consumer.go
##########
@@ -0,0 +1,473 @@
+/*
+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 consumer
+
+import (
+	"context"
+	"fmt"
+	errors2 "github.com/apache/rocketmq-client-go/v2/errors"
+	"github.com/apache/rocketmq-client-go/v2/internal"
+	"github.com/apache/rocketmq-client-go/v2/primitive"
+	"github.com/apache/rocketmq-client-go/v2/rlog"
+	"github.com/pkg/errors"
+	"strings"
+	"sync"
+	"sync/atomic"
+	"time"
+)
+
+type defaultHighLevelPullConsumer struct {
+	*defaultManualPullConsumer
+	consumerGroup           string
+	model                   MessageModel
+	namesrv                 internal.Namesrvs
+	option                  consumerOptions
+	client                  internal.RMQClient
+	interceptor             primitive.Interceptor
+	pullFromWhichNodeTable  sync.Map
+	storage                 OffsetStore
+	cType                   ConsumeType
+	state                   int32
+	subscriptionDataTable   sync.Map
+	allocate                func(string, string, []*primitive.MessageQueue, []string) []*primitive.MessageQueue
+	once                    sync.Once
+	unitMode                bool
+	topicSubscribeInfoTable sync.Map
+	subscribedTopic         map[string]string
+	closeOnce               sync.Once
+	done                    chan struct{}
+	consumerStartTimestamp  int64
+	processQueueTable       sync.Map
+	fromWhere               ConsumeFromWhere
+	stat                    *StatsManager
+}
+
+func NewHighLevelPullConsumer(options ...Option) (*defaultHighLevelPullConsumer, error) {
+	defaultOpts := defaultHighLevelPullConsumerOptions()
+	for _, apply := range options {
+		apply(&defaultOpts)
+	}
+
+	srvs, err := internal.NewNamesrv(defaultOpts.Resolver)
+	if err != nil {
+		return nil, errors.Wrap(err, "new Namesrv failed.")
+	}
+
+	defaultOpts.Namesrv = srvs
+
+	if defaultOpts.Namespace != "" {
+		defaultOpts.GroupName = defaultOpts.Namespace + "%" + defaultOpts.GroupName
+	}
+
+	dc := &defaultManualPullConsumer{

Review comment:
       use `NewManualPullConsumer` replace




-- 
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: dev-unsubscribe@rocketmq.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [rocketmq-client-go] shendongsd commented on pull request #750: [ISSUE #738] the first version of high-level-pull-consumer

Posted by GitBox <gi...@apache.org>.
shendongsd commented on pull request #750:
URL: https://github.com/apache/rocketmq-client-go/pull/750#issuecomment-1004549597


   > @shendongsd Hi, Could you rebase the upstream branch?
   Ok


-- 
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: dev-unsubscribe@rocketmq.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [rocketmq-client-go] wenfengwang commented on pull request #750: [ISSUE #738] the first version of high-level-pull-consumer

Posted by GitBox <gi...@apache.org>.
wenfengwang commented on pull request #750:
URL: https://github.com/apache/rocketmq-client-go/pull/750#issuecomment-1004071227


   @shendongsd ping


-- 
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: dev-unsubscribe@rocketmq.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org