You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tubemq.apache.org by go...@apache.org on 2020/07/03 06:08:19 UTC

[incubator-tubemq] branch tubemq-client-go updated: [TUBEMQ-264] Init pull consumer and config (#179)

This is an automated email from the ASF dual-hosted git repository.

gosonzhang pushed a commit to branch tubemq-client-go
in repository https://gitbox.apache.org/repos/asf/incubator-tubemq.git


The following commit(s) were added to refs/heads/tubemq-client-go by this push:
     new e2fb986  [TUBEMQ-264] Init pull consumer and config (#179)
e2fb986 is described below

commit e2fb98634782d172a01111021632ac4d040d9ae2
Author: lubanproj <53...@users.noreply.github.com>
AuthorDate: Fri Jul 3 14:08:11 2020 +0800

    [TUBEMQ-264] Init pull consumer and config (#179)
    
    Co-authored-by: delvintang <de...@tencent.com>
---
 tubemq-client-twins/tubemq-client-go/config.go   | 27 +++++++++++
 tubemq-client-twins/tubemq-client-go/consumer.go | 60 ++++++++++++++++++++++++
 2 files changed, 87 insertions(+)

diff --git a/tubemq-client-twins/tubemq-client-go/config.go b/tubemq-client-twins/tubemq-client-go/config.go
new file mode 100644
index 0000000..ede829c
--- /dev/null
+++ b/tubemq-client-twins/tubemq-client-go/config.go
@@ -0,0 +1,27 @@
+/**
+ * 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
+ * <p>
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * <p>
+ * 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 tubeclient
+
+// Config defines the configurations of Consumer
+type Config struct {
+	// Group is the name of a consumer group
+	// Only one consumer in the same consumer Group can consume messages at any one time
+	Group string
+	// Address TODO...
+	Address string
+}
\ No newline at end of file
diff --git a/tubemq-client-twins/tubemq-client-go/consumer.go b/tubemq-client-twins/tubemq-client-go/consumer.go
new file mode 100644
index 0000000..a0780ec
--- /dev/null
+++ b/tubemq-client-twins/tubemq-client-go/consumer.go
@@ -0,0 +1,60 @@
+/**
+ * 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
+ * <p>
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * <p>
+ * 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 tubeclient
+
+import "errors"
+
+// Consumer defines a basic contract that all consumers need to follow
+type Consumer interface {
+	// Subscribe defines a subscription to the topic
+	Subscribe(topic string)
+}
+
+// PullConsumer implements Consumber with the pull consumption
+type PullConsumer struct {
+	config *Config
+}
+
+func New(config *Config) *PullConsumer {
+	if err := checkConfig(config); err != nil {
+		panic(err)
+	}
+
+	// TODO: add log
+	c := &PullConsumer{
+		config: config,
+	}
+
+	return c
+}
+
+func checkConfig(config *Config) error {
+	if config == nil {
+		return errors.New("consumer config cannot be nil")
+	}
+
+	if config.Address == "" {
+		return errors.New("consumer config err, address cannot be empty")
+	}
+
+	if config.Group == "" {
+		return errors.New("consumer config err, group cannot be empty")
+	}
+
+	return nil
+}
\ No newline at end of file