tydhot commented on a change in pull request #300:
URL: https://github.com/apache/dubbo-go-pixiu/pull/300#discussion_r753807550



##########
File path: pkg/client/mq/kafka_facade.go
##########
@@ -0,0 +1,256 @@
+/*
+ * 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 mq
+
+import (
+       "bytes"
+       "context"
+       "encoding/json"
+       "fmt"
+       "net/http"
+       "strconv"
+       "sync"
+       "time"
+)
+
+import (
+       "github.com/apache/dubbo-go-pixiu/pkg/logger"
+)
+
+import (
+       "github.com/Shopify/sarama"
+       perrors "github.com/pkg/errors"
+)
+
+type kafkaErrors struct {
+       count int
+       err   string
+}
+
+func (ke kafkaErrors) Error() string {
+       return fmt.Sprintf("Failed to deliver %d messages due to %s", ke.count, 
ke.err)
+}
+
+func NewKafkaConsumerFacade(config KafkaConsumerConfig, consumerGroup string) 
(*KafkaConsumerFacade, error) {
+       c := sarama.NewConfig()
+       c.ClientID = config.ClientID
+       c.Metadata.Full = config.Metadata.Full
+       c.Metadata.Retry.Max = config.Metadata.Retry.Max
+       c.Metadata.Retry.Backoff = config.Metadata.Retry.Backoff
+       if config.ProtocolVersion != "" {
+               version, err := sarama.ParseKafkaVersion(config.ProtocolVersion)
+               if err != nil {
+                       return nil, err
+               }
+               c.Version = version
+       }
+       client, err := sarama.NewConsumerGroup(config.Brokers, consumerGroup, c)
+       if err != nil {
+               return nil, err
+       }
+
+       return &KafkaConsumerFacade{consumerGroup: client, httpClient: 
&http.Client{Timeout: 5 * time.Second}, done: make(chan struct{})}, nil
+}
+
+type KafkaConsumerFacade struct {
+       consumerGroup   sarama.ConsumerGroup
+       consumerManager map[string]func()
+       httpClient      *http.Client
+       wg              sync.WaitGroup
+       done            chan struct{}
+}
+
+func (f *KafkaConsumerFacade) Subscribe(ctx context.Context, opts ...Option) 
error {
+       cOpt := DefaultOptions()
+       cOpt.ApplyOpts(opts...)
+       c, cancel := context.WithCancel(ctx)
+       key := GetConsumerManagerKey(cOpt.TopicList, cOpt.ConsumerGroup)

Review comment:
       这里我和俊铭的考虑是 
这一块其实是在kafka之上的一个通用的facade抽象。目前因为只有一个kafka实现可能比较冗余,但是在多种实现下,这里可能需要把一些通用参数转化成每种mq能够进行必要性判断和具体使用的格式,这里主要是出于这样
 的考虑不过MQOptions也应该移动到kafka_facade内




-- 
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: notifications-unsubscr...@dubbo.apache.org

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



---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscr...@dubbo.apache.org
For additional commands, e-mail: notifications-h...@dubbo.apache.org

Reply via email to