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/09 09:53:10 UTC

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

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