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 2019/07/09 03:49:34 UTC

[GitHub] [rocketmq-client-go] wenfengwang commented on a change in pull request #103: [ISSUE #93] More usability API

wenfengwang commented on a change in pull request #103: [ISSUE #93] More usability API
URL: https://github.com/apache/rocketmq-client-go/pull/103#discussion_r301386110
 
 

 ##########
 File path: consumer/option.go
 ##########
 @@ -151,77 +97,78 @@ type ConsumerOptions struct {
 	Strategy       AllocateStrategy
 	ConsumeOrderly bool
 	FromWhere      ConsumeFromWhere
-	// TODO traceDispatcher
 
-	Interceptors []CInterceptor
+	Interceptors []primitive.Interceptor
+	// TODO traceDispatcher
 }
 
-func DefaultPushConsumerOptions() ConsumerOptions{
-	return ConsumerOptions{
-		ClientOption: ClientOption{
-			InstanceName: "DEFAULT",
-			ClientIP: utils.LocalIP(),
-		},
-		Strategy: AllocateByAveragely,
+func defaultPushConsumerOptions() consumerOptions {
+	return consumerOptions{
+		ClientOptions: internal.DefaultClientOptions(),
+		Strategy:      AllocateByAveragely,
 	}
 }
 
-type ConsumerOption struct {
-	Apply func(*ConsumerOptions)
-}
-
-func NewConsumerOption(f func(*ConsumerOptions)) *ConsumerOption {
-	return &ConsumerOption{
-		Apply: f,
-	}
-}
+type Option func(*consumerOptions)
 
-func WithConsumerModel(m MessageModel) *ConsumerOption {
-	return NewConsumerOption(func(options *ConsumerOptions) {
+func WithConsumerModel(m MessageModel) Option {
+	return func(options *consumerOptions) {
 		options.ConsumerModel = m
-	})
+	}
 }
 
-func WithConsumeFromWhere(w ConsumeFromWhere) *ConsumerOption{
-	return NewConsumerOption(func(options *ConsumerOptions) {
+func WithConsumeFromWhere(w ConsumeFromWhere) Option {
+	return func(options *consumerOptions) {
 		options.FromWhere = w
-	})
-}
-
-// WithConsumerInterceptor returns a ConsumerOption that specifies the interceptor for consumer.
-func WithConsumerInterceptor(f CInterceptor) *ConsumerOption {
-	return NewConsumerOption(func(options *ConsumerOptions) {
-		options.Interceptors = append(options.Interceptors, f)
-	})
+	}
 }
 
 // WithChainConsumerInterceptor returns a ConsumerOption that specifies the chained interceptor for consumer.
 // The first interceptor will be the outer most, while the last interceptor will be the inner most wrapper
 // around the real call.
-func WithChainConsumerInterceptor(fs ...CInterceptor) *ConsumerOption {
-	return NewConsumerOption(func(options *ConsumerOptions) {
+func WithInterceptor(fs ...primitive.Interceptor) Option {
+	return func(options *consumerOptions) {
 		options.Interceptors = append(options.Interceptors, fs...)
-	})
+	}
 }
 
-func (opt *ClientOption) ChangeInstanceNameToPID() {
-	if opt.InstanceName == "DEFAULT" {
-		opt.InstanceName = strconv.Itoa(os.Getegid())
+// WithGroupName set group name address
+func WithGroupName(group string) Option {
+	return func(opts *consumerOptions) {
+		if group == "" {
+			return
+		}
+		opts.GroupName = group
 	}
 }
 
-func (opt *ClientOption) String() string {
-	return fmt.Sprintf("ClientOption [ClientIP=%s, InstanceName=%s, "+
-		"UnitMode=%v, UnitName=%s, VIPChannelEnabled=%v, UseTLS=%v]", opt.ClientIP,
-		opt.InstanceName, opt.UnitMode, opt.UnitName, opt.VIPChannelEnabled, opt.UseTLS)
+// WithNameServer set NameServer address, only support one NameServer cluster in alpha2
+func WithNameServer(nameServers ...[]string) Option {
+	return func(opts *consumerOptions) {
+		if len(nameServers) > 0 {
+			opts.NameServerAddrs = nameServers[0]
 
 Review comment:
   arguments is `[][]string`, each `[]string` represent a NameServer cluster. we only support one cluster now.

----------------------------------------------------------------
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.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services