This is an automated email from the ASF dual-hosted git repository.
gosonzhang pushed a commit to branch INLONG-25
in repository https://gitbox.apache.org/repos/asf/incubator-inlong.git
The following commit(s) were added to refs/heads/INLONG-25 by this push:
new 23ad421 [INLONG-1430]Go SDK example (#1431)
23ad421 is described below
commit 23ad421bee4e078a7541afa6875a4fd2842f923b
Author: Zijie Lu <[email protected]>
AuthorDate: Mon Aug 9 21:37:54 2021 +0800
[INLONG-1430]Go SDK example (#1431)
Signed-off-by: Zijie Lu <[email protected]>
---
.../tubemq-client-go/example/consumer.go | 61 ++++++++++++++++++++++
1 file changed, 61 insertions(+)
diff --git a/tubemq-client-twins/tubemq-client-go/example/consumer.go
b/tubemq-client-twins/tubemq-client-go/example/consumer.go
new file mode 100644
index 0000000..eb3d988
--- /dev/null
+++ b/tubemq-client-twins/tubemq-client-go/example/consumer.go
@@ -0,0 +1,61 @@
+// 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 main
+
+import (
+ "time"
+
+
"github.com/apache/incubator-inlong/tubemq-client-twins/tubemq-client-go/client"
+
"github.com/apache/incubator-inlong/tubemq-client-twins/tubemq-client-go/config"
+
"github.com/apache/incubator-inlong/tubemq-client-twins/tubemq-client-go/log"
+)
+
+func main() {
+ cfg, err :=
config.ParseAddress("9.23.27.160:8099?topics=test_1&group=test_group")
+ if err != nil {
+ log.Errorf("Failed to parse address", err.Error())
+ panic(err)
+ }
+ c, err := client.NewConsumer(cfg)
+ if err != nil {
+ log.Errorf("new consumer error %s", err.Error())
+ panic(err)
+ }
+ start := time.Now()
+ for {
+ elapsed := time.Since(start)
+ if elapsed >= 10*time.Minute {
+ break
+ }
+ cr, err := c.GetMessage()
+ if err != nil {
+ log.Errorf("Get message error %s", err.Error())
+ continue
+ }
+ cr, err = c.Confirm(cr.ConfirmContext, true)
+ if err != nil {
+ log.Errorf("Confirm error %s", err.Error())
+ continue
+ }
+ }
+ err = c.Close()
+ if err != nil {
+ log.Errorf("Close err %s", err.Error())
+ panic(err)
+ }
+}