This is an automated email from the ASF dual-hosted git repository.
dockerzhang pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/inlong-website.git
The following commit(s) were added to refs/heads/master by this push:
new b4edafe193 [INLONG-793][Doc] Add docs for tubemq go sdk. (#794)
b4edafe193 is described below
commit b4edafe19364241dfb6b26d69bd381c59d39a1e5
Author: Xue Huanran <[email protected]>
AuthorDate: Mon Jul 3 14:11:09 2023 +0800
[INLONG-793][Doc] Add docs for tubemq go sdk. (#794)
Co-authored-by: huanranxue <[email protected]>
---
docs/sdk/tubemq-sdk/go.md | 70 ++++++++++++++++++++++
.../current/sdk/tubemq-sdk/go.md | 70 ++++++++++++++++++++++
2 files changed, 140 insertions(+)
diff --git a/docs/sdk/tubemq-sdk/go.md b/docs/sdk/tubemq-sdk/go.md
new file mode 100644
index 0000000000..53eef8ddc0
--- /dev/null
+++ b/docs/sdk/tubemq-sdk/go.md
@@ -0,0 +1,70 @@
+---
+title: Golang SDK
+sidebar_position: 3
+---
+
+Similar to the C++/Python SDK, the Golang SDK is also divided into two parts:
`Producer` and `Consumer`. Here is an introduction to both.
+
+### Producer
+
+First, import necessary packages:
+
+```go
+import (
+
"github.com/apache/inlong/inlong-tubemq/tubemq-client-twins/tubemq-client-go/client"
+
"github.com/apache/inlong/inlong-tubemq/tubemq-client-twins/tubemq-client-go/config"
+
"github.com/apache/inlong/inlong-tubemq/tubemq-client-twins/tubemq-client-go/log"
+
"github.com/apache/inlong/inlong-tubemq/tubemq-client-twins/tubemq-client-go/util"
+)
+```
+
+Then, set the producer's configuration. In the following example, we access
the local `Master` and subscribe to the topic `demo_0`:
+
+```go
+cfg, err := config.ParseAddress("127.0.0.1:8715?topic=demo_0")
+```
+
+If there are multiple topics, you can directly modify the `Topics` in the
`config`:
+
+```go
+cfg.Producer.Topics = []string{"demo", "demo_0", "demo_1"}
+```
+
+After the configuration is completed, create a new instance of `Producer`.
During this process, the `SDK` will register to the `TubeMQ Master` and send a
heartbeat to get the metadata of the topic:
+
+```go
+p, err := client.NewProducer(cfg)
+```
+
+Then, construct and send the message:
+
+```go
+demoData := "hello_tubemq"
+msg := client.Message{
+ Topic: cfg.Producer.Topics[topicIndex], // You can choose from the
subscribed topic list
+ Data: []byte(demoData),
+ DataLen: int32(len(demoData)),
+}
+
+success, errCode, errMsg := p.SendMessage(&msg) // Send a message to TubeMQ,
return whether it is successful, the error code, and the error message
+```
+
+### Consumer
+
+The `Consumer` is roughly the same as the `Producer`, except that there is the
concept of a consumer group when setting the `config`:
+
+```go
+cfg, err := config.ParseAddress("127.0.0.1:8715?topic=demo_0&group=test_group")
+```
+
+Then, refer to the usage of the `Producer` to consume:
+
+```go
+c, err := client.NewConsumer(cfg) // Create a new Consumer instance
+cr, err := c.GetMessage() // Get message
+_, err = c.Confirm(cr.ConfirmContext, true) // Confirm to TubeMQ after getting
the data
+```
+
+### Example
+
+The above content is a demo and ignores some details. For a complete and
runnable example, please refer to [Golang SDK
Example](https://github.com/apache/inlong/tree/master/inlong-tubemq/tubemq-client-twins/tubemq-client-go/example).
diff --git
a/i18n/zh-CN/docusaurus-plugin-content-docs/current/sdk/tubemq-sdk/go.md
b/i18n/zh-CN/docusaurus-plugin-content-docs/current/sdk/tubemq-sdk/go.md
new file mode 100644
index 0000000000..be5e7d0cbf
--- /dev/null
+++ b/i18n/zh-CN/docusaurus-plugin-content-docs/current/sdk/tubemq-sdk/go.md
@@ -0,0 +1,70 @@
+---
+title: Golang SDK
+sidebar_position: 3
+---
+
+与 C++/Python SDK 类似,Golang SDK 也分为 `Producer` 和 `Consumer` 两部分,下面对其进行介绍。
+
+### Producer
+
+首先 import 必要的 package
+
+```go
+import (
+
"github.com/apache/inlong/inlong-tubemq/tubemq-client-twins/tubemq-client-go/client"
+
"github.com/apache/inlong/inlong-tubemq/tubemq-client-twins/tubemq-client-go/config"
+
"github.com/apache/inlong/inlong-tubemq/tubemq-client-twins/tubemq-client-go/log"
+
"github.com/apache/inlong/inlong-tubemq/tubemq-client-twins/tubemq-client-go/util"
+)
+```
+
+之后设置 `Producer` 的配置,下面例子中访问本地 `Master`,订阅 topic 为 demo_0
+
+```go
+cfg, err := config.ParseAddress("127.0.0.1:8715?topic=demo_0")
+```
+
+如果有多个 topic 需要进行访问,也可以直接对 config 的 topic 进行修改
+
+```go
+cfg.Producer.Topics = []string{"demo", "demo_0", "demo_1"}
+```
+
+配置完成后,新建 `Producer` 的实例,在这个过程中,`SDK` 会向 `TubeMQ Master` 申请注册,并发送心跳拿到 topic 的元数据
+
+```go
+p, err := client.NewProducer(cfg)
+```
+
+之后构造消息并发送即可
+
+```go
+demoData := "hello_tubemq"
+msg := client.Message{
+ Topic: cfg.Producer.Topics[topicIndex], // 可以从订阅的 topic 列表中选择
+ Data: []byte(demoData),
+ DataLen: int32(len(demoData)),
+}
+
+success, errCode, errMsg := p.SendMessage(&msg) // 向 tubemq 发送
message,返回是否成功,错误码以及错误信息
+```
+
+### Consumer
+
+`Consumer` 与 `Producer` 的大致相同,除了在设置 config 时,有消费 group 的概念
+
+```go
+cfg, err := config.ParseAddress("127.0.0.1:8715?topic=demo_0&group=test_group")
+```
+
+之后参考 `Producer` 的用法进行消费即可
+
+```go
+c, err := client.NewConsumer(cfg) // 新建 Consumer 实例
+cr, err := c.GetMessage() // 获取消息
+_, err = c.Confirm(cr.ConfirmContext, true) // 获取后向 tubemq 进行 confirm
+```
+
+### Example
+
+上述文档内容为示例,省去了一些细节,完整可以运行的例子请参考 [Golang SDK
Example](https://github.com/apache/inlong/tree/master/inlong-tubemq/tubemq-client-twins/tubemq-client-go/example)