You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@dubbo.apache.org by zh...@apache.org on 2021/12/08 11:57:13 UTC
[dubbo-website] branch master updated: add dubbo-go 1.5 (#1005)
This is an automated email from the ASF dual-hosted git repository.
zhaoyunxing pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/dubbo-website.git
The following commit(s) were added to refs/heads/master by this push:
new 8bb97d6 add dubbo-go 1.5 (#1005)
8bb97d6 is described below
commit 8bb97d64c0eac1bfbe9f9eb0877e66fd3b82ae76
Author: Jason Deng <76...@users.noreply.github.com>
AuthorDate: Wed Dec 8 19:57:03 2021 +0800
add dubbo-go 1.5 (#1005)
* add dubbo go 1.5
* add dubbo go 1.5
Co-authored-by: Xu Song <xu...@gmail.com>
Co-authored-by: 15301580353@163.com <dzw19971017>
---
.github/themes/docsy | 1 +
.gitmodules | 3 +
.../docs/languages/golang/dubbo-go-1.5/_index.md | 9 +
.../golang/dubbo-go-1.5/configuration/_index.md | 8 +
.../golang/dubbo-go-1.5/configuration/client.md | 205 +++++++++++++++++++++
.../golang/dubbo-go-1.5/configuration/provider.md | 202 ++++++++++++++++++++
.../languages/golang/dubbo-go-1.5/quick-start.md | 204 ++++++++++++++++++++
content/zh/docs/languages/golang/go-specific.md | 2 +-
8 files changed, 633 insertions(+), 1 deletion(-)
diff --git a/.github/themes/docsy b/.github/themes/docsy
new file mode 160000
index 0000000..7dc7083
--- /dev/null
+++ b/.github/themes/docsy
@@ -0,0 +1 @@
+Subproject commit 7dc70837461881b639215e40d90b6502974e3a14
diff --git a/.gitmodules b/.gitmodules
index 92c7b2c..6c4de10 100644
--- a/.gitmodules
+++ b/.gitmodules
@@ -2,3 +2,6 @@
[submodule "themes/docsy"]
path = themes/docsy
url = https://github.com/google/docsy.git
+[submodule ".github/themes/docsy"]
+ path = .github/themes/docsy
+ url = git@github.com:google/docsy.git
diff --git a/content/zh/docs/languages/golang/dubbo-go-1.5/_index.md b/content/zh/docs/languages/golang/dubbo-go-1.5/_index.md
new file mode 100644
index 0000000..739e4af
--- /dev/null
+++ b/content/zh/docs/languages/golang/dubbo-go-1.5/_index.md
@@ -0,0 +1,9 @@
+
+---
+type: docs
+title: "Dubbo-go 1.5"
+linkTitle: "Dubbo-go 1.5"
+weight: 200
+description: "Dubbo-go 1.5"
+---
+
diff --git a/content/zh/docs/languages/golang/dubbo-go-1.5/configuration/_index.md b/content/zh/docs/languages/golang/dubbo-go-1.5/configuration/_index.md
new file mode 100644
index 0000000..efc8d49
--- /dev/null
+++ b/content/zh/docs/languages/golang/dubbo-go-1.5/configuration/_index.md
@@ -0,0 +1,8 @@
+---
+type: docs
+title: 配置
+keywords: 提供端,server provider
+linkTitle: 配置
+description: 提示用户配置服务提供
+---
+
diff --git a/content/zh/docs/languages/golang/dubbo-go-1.5/configuration/client.md b/content/zh/docs/languages/golang/dubbo-go-1.5/configuration/client.md
new file mode 100644
index 0000000..e636040
--- /dev/null
+++ b/content/zh/docs/languages/golang/dubbo-go-1.5/configuration/client.md
@@ -0,0 +1,205 @@
+
+
+---
+type: docs
+title: client
+keywords: 消费端,client provider
+linkTitle: client
+description: 快速上手dubbo-go,编写一个简单的hellowworld应用
+---
+# client
+
+## 第一步:编写消费端的服务
+
+1. 编写需要被编码的结构体,由于使用 `Hessian2` 作为编码协议,`User` 需要实现 `JavaClassName` 方法,它的返回值在dubbo中对应User类的类名。
+
+ ```go
+ type User struct {
+ Id string
+ Name string
+ Age int32
+ Time time.Time
+ }
+
+ func (u User) JavaClassName() string {
+ return "org.apache.dubbo.User"
+ }
+ ```
+
+
+
+2. 与服务端不同的是,提供服务的方法作为结构体的参数,不需要编写具体业务逻辑。另外,`Provider` 不对应dubbo中的实现,而是对应一个接口。
+
+ ```go
+ type UserProvider struct {
+ GetUser func(ctx context.Context, req []interface{}, rsp *User) error
+ }
+
+ func (u *UserProvider) Reference() string {
+ return "UserProvider"
+ }
+ ```
+
+
+
+3. 注册服务和对象
+
+ ```go
+ func init() {
+ config.SetConsumerService(userProvider)
+ hessian.RegisterPOJO(&User{})
+ }
+ ```
+
+## 第二步:编写消费端主程序
+
+1. 引入必需的dubbo-go包
+
+ ```go
+ import (
+ hessian "github.com/apache/dubbo-go-hessian2"
+ _ "github.com/apache/dubbo-go/cluster/cluster_impl"
+ _ "github.com/apache/dubbo-go/cluster/loadbalance"
+ _ "github.com/apache/dubbo-go/common/proxy/proxy_factory"
+ "github.com/apache/dubbo-go/config"
+ _ "github.com/apache/dubbo-go/filter/filter_impl"
+ _ "github.com/apache/dubbo-go/protocol/dubbo"
+ _ "github.com/apache/dubbo-go/registry/protocol"
+ _ "github.com/apache/dubbo-go/registry/zookeeper"
+
+ gxlog "github.com/dubbogo/gost/log"
+ )
+ ```
+
+
+
+2. main 函数
+
+ ```go
+ func main() {
+ config.Load()
+ time.Sleep(3 * time.Second)
+
+ gxlog.CInfo("\n\n\nstart to test dubbo")
+ user := &pkg.User{}
+ err := userProvider.GetUser(context.TODO(), []interface{}{"A001"}, user)
+ if err != nil {
+ gxlog.CError("error: %v\n", err)
+ os.Exit(1)
+ return
+ }
+ gxlog.CInfo("response result: %v\n", user)
+ }
+ ```
+
+## 第三步:编写配置文件并配置环境变量
+
+1. 编辑配置文件 log.yml, client.yml
+
+ - log.yml
+
+ ~~~yml
+ level: "debug"
+ development: true
+ disableCaller: false
+ disableStacktrace: false
+ sampling:
+ encoding: "console"
+
+ # encoder
+ encoderConfig:
+ messageKey: "message"
+ levelKey: "level"
+ timeKey: "time"
+ nameKey: "logger"
+ callerKey: "caller"
+ stacktraceKey: "stacktrace"
+ lineEnding: ""
+ levelEncoder: "capital"
+ timeEncoder: "iso8601"
+ durationEncoder: "seconds"
+ callerEncoder: "short"
+ nameEncoder: ""
+
+ outputPaths:
+ - "stderr"
+ errorOutputPaths:
+ - "stderr"
+ initialFields:
+ ~~~
+
+ - log.yml
+
+ ~~~yml
+ # dubbo client yaml configure file
+
+ check: true
+ # client
+ request_timeout: "3s"
+ # connect timeout
+ connect_timeout: "3s"
+
+ # application config
+ application:
+ organization: "dubbo.io"
+ name: "UserInfoClient"
+ module: "dubbo-go user-info client"
+ version: "0.0.1"
+ environment: "dev"
+
+ # registry config
+ registries:
+ "demoZk":
+ protocol: "zookeeper"
+ timeout: "3s"
+ address: "127.0.0.1:2181"
+ username: ""
+ password: ""
+
+ # reference config
+ references:
+ "UserProvider":
+ registry: "demoZk"
+ protocol: "dubbo"
+ interface: "org.apache.dubbo.UserProvider"
+ cluster: "failover"
+ methods:
+ - name: "GetUser"
+ retries: 3
+
+ # protocol config
+ protocol_conf:
+ dubbo:
+ reconnect_interval: 0
+ connection_number: 1
+ heartbeat_period: "5s"
+ session_timeout: "180s"
+ pool_size: 64
+ pool_ttl: 600
+ getty_session_param:
+ compress_encoding: false
+ tcp_no_delay: true
+ tcp_keep_alive: true
+ keep_alive_period: "120s"
+ tcp_r_buf_size: 262144
+ tcp_w_buf_size: 65536
+ pkg_rq_size: 1024
+ pkg_wq_size: 512
+ tcp_read_timeout: "1s"
+ tcp_write_timeout: "5s"
+ wait_timeout: "1s"
+ max_msg_len: 1024000
+ session_name: "client"
+ ~~~
+
+
+
+2. 把上面的两个配置文件分别配置为环境变量,为防止log的环境变量和服务端的log环境变量冲突,建议所有的环境变量不要做全局配置,在当前起效即可。
+
+ ```shell
+ export CONF_CONSUMER_FILE_PATH="xxx"
+ export APP_LOG_CONF_FILE="xxx"
+ ```
+
+
+本文章源码详情见git:https://github.com/apache/dubbo-go-samples/tree/1.5/helloworld/go-client
diff --git a/content/zh/docs/languages/golang/dubbo-go-1.5/configuration/provider.md b/content/zh/docs/languages/golang/dubbo-go-1.5/configuration/provider.md
new file mode 100644
index 0000000..3882b3c
--- /dev/null
+++ b/content/zh/docs/languages/golang/dubbo-go-1.5/configuration/provider.md
@@ -0,0 +1,202 @@
+
+---
+type: docs
+title: service providers
+keywords: 提供端,server provider
+linkTitle: service providers
+description: 提示用户配置服务提供
+---
+# service providers
+
+## 第一步:编写提供端的服务
+
+1. 编写需要被编码的结构体,由于使用 `Hessian2` 作为编码协议,`User` 需要实现 `JavaClassName` 方法,它的返回值在dubbo中对应User类的类名。
+
+ ```go
+ type User struct {
+ Id string
+ Name string
+ Age int32
+ Time time.Time
+ }
+
+ func (u User) JavaClassName() string {
+ return "org.apache.dubbo.User"
+ }
+ ```
+
+
+
+2. 编写业务逻辑,`UserProvider` 相当于dubbo中的一个服务实现。需要实现 `Reference` 方法,返回值是这个服务的唯一标识,对应dubbo的 `beans` 和 `path` 字段。
+
+ ```go
+ type UserProvider struct {
+ }
+
+ func (u *UserProvider) GetUser(ctx context.Context, req []interface{}) (*User, error) {
+ println("req:%#v", req)
+ rsp := User{"A001", "hellowworld", 18, time.Now()}
+ println("rsp:%#v", rsp)
+ return &rsp, nil
+ }
+
+ func (u *UserProvider) Reference() string {
+ return "UserProvider"
+ }
+ ```
+
+
+
+3. 注册服务和对象
+
+ ```go
+ func init() {
+ config.SetProviderService(new(UserProvider))
+ // ------for hessian2------
+ hessian.RegisterPOJO(&User{})
+ }
+ ```
+
+
+
+## 第二步:编写主程序
+
+1. 引入必需的dubbo-go包
+
+ ```go
+ import (
+ hessian "github.com/apache/dubbo-go-hessian2"
+ _ "github.com/apache/dubbo-go/cluster/cluster_impl"
+ _ "github.com/apache/dubbo-go/cluster/loadbalance"
+ "github.com/apache/dubbo-go/common/logger"
+ _ "github.com/apache/dubbo-go/common/proxy/proxy_factory"
+ "github.com/apache/dubbo-go/config"
+ _ "github.com/apache/dubbo-go/filter/filter_impl"
+ _ "github.com/apache/dubbo-go/protocol/dubbo"
+ _ "github.com/apache/dubbo-go/registry/protocol"
+ _ "github.com/apache/dubbo-go/registry/zookeeper"
+ )
+ ```
+
+
+
+2. main 函数
+
+ ```go
+ func main() {
+ config.Load()
+ }
+ ```
+
+
+
+## 第三步:编写配置文件并配置环境变量
+
+1. 设置配置文件 log.yml, server.yml
+
+ - **log.yml**
+
+ ```yml
+ level: "error"
+ development: true
+ disableCaller: false
+ disableStacktrace: false
+ sampling:
+ encoding: "console"
+
+ # encoder
+ encoderConfig:
+ messageKey: "message"
+ levelKey: "level"
+ timeKey: "time"
+ nameKey: "logger"
+ callerKey: "caller"
+ stacktraceKey: "stacktrace"
+ lineEnding: ""
+ levelEncoder: "capital"
+ timeEncoder: "iso8601"
+ durationEncoder: "seconds"
+ callerEncoder: "short"
+ nameEncoder: ""
+
+ outputPaths:
+ - "stderr"
+ errorOutputPaths:
+ - "stderr"
+ initialFields:
+ ```
+
+ - server.yml
+
+ ```yml
+ # dubbo server yaml configure file
+
+ # application config
+ application:
+ organization: "dubbo.io"
+ name: "UserInfoServer"
+ module: "dubbo-go user-info server"
+ version: "0.0.1"
+ environment: "dev"
+
+ # registry config
+ registries:
+ "demoZk":
+ protocol: "zookeeper"
+ timeout: "3s"
+ address: "127.0.0.1:2181"
+
+ # service config
+ services:
+ "UserProvider":
+ registry: "demoZk"
+ protocol: "dubbo"
+ interface: "org.apache.dubbo.UserProvider"
+ loadbalance: "random"
+ warmup: "100"
+ cluster: "failover"
+ methods:
+ - name: "GetUser"
+ retries: 1
+ loadbalance: "random"
+
+ # protocol config
+ protocols:
+ "dubbo":
+ name: "dubbo"
+ port: 20000
+
+ protocol_conf:
+ dubbo:
+ session_number: 700
+ session_timeout: "180s"
+ getty_session_param:
+ compress_encoding: false
+ tcp_no_delay: true
+ tcp_keep_alive: true
+ keep_alive_period: "120s"
+ tcp_r_buf_size: 262144
+ tcp_w_buf_size: 65536
+ pkg_rq_size: 1024
+ pkg_wq_size: 512
+ tcp_read_timeout: "1s"
+ tcp_write_timeout: "5s"
+ wait_timeout: "1s"
+ max_msg_len: 1024000
+ session_name: "server"
+ ```
+
+ 主要编辑以下部分:
+
+ - `registries` 结点下需要配置zk的数量和地址
+ - `services` 结点下配置服务的具体信息,需要配置 `interface` 配置,修改为对应服务的接口名,服务的key对应第一步中 `Provider` 的 `Reference` 返回值
+
+2. 把上面的两个配置文件分别配置为环境变量
+
+ ```shell
+ export CONF_PROVIDER_FILE_PATH="xxx"
+ export APP_LOG_CONF_FILE="xxx"
+ ```
+
+
+本文章源码详情见git:https://github.com/apache/dubbo-go-samples/tree/1.5/helloworld/go-server
diff --git a/content/zh/docs/languages/golang/dubbo-go-1.5/quick-start.md b/content/zh/docs/languages/golang/dubbo-go-1.5/quick-start.md
new file mode 100644
index 0000000..b2e16d6
--- /dev/null
+++ b/content/zh/docs/languages/golang/dubbo-go-1.5/quick-start.md
@@ -0,0 +1,204 @@
+
+---
+type: docs
+title: 快速开始
+keywords: 快速开始, hellowworld, Provider
+linkTitle: 快速开始
+description: 快速上手dubbo-go,编写一个简单的hellowworld应用
+---
+
+# 快速开始
+
+通过一个 `hellowworld` 例子带领大家快速上手Dubbo-go框架。
+
+协议:Dubbo
+编码:Hessian2
+注册中心:Zookeeper
+
+## 环境
+
+* Go编程环境
+* 启动zookeeper服务,也可以使用远程实例
+
+## 从服务端开始
+
+### 第一步:编写 `Provider` 结构体和提供服务的方法
+
+> <https://github.com/dubbogo/dubbo-samples/blob/master/golang/helloworld/dubbo/go-server/app/user.go>
+
+1. 编写需要被编码的结构体,由于使用 `Hessian2` 作为编码协议,`User` 需要实现 `JavaClassName` 方法,它的返回值在dubbo中对应User类的类名。
+
+```go
+type User struct {
+ Id string
+ Name string
+ Age int32
+ Time time.Time
+}
+
+func (u User) JavaClassName() string {
+ return "com.ikurento.user.User"
+}
+```
+
+2. 编写业务逻辑,`UserProvider` 相当于dubbo中的一个服务实现。需要实现 `Reference` 方法,返回值是这个服务的唯一标识,对应dubbo的 `beans` 和 `path` 字段。
+
+```go
+type UserProvider struct {
+}
+
+func (u *UserProvider) GetUser(ctx context.Context, req []interface{}) (*User, error) {
+ println("req:%#v", req)
+ rsp := User{"A001", "hellowworld", 18, time.Now()}
+ println("rsp:%#v", rsp)
+ return &rsp, nil
+}
+
+func (u *UserProvider) Reference() string {
+ return "UserProvider"
+}
+```
+
+3. 注册服务和对象
+
+```go
+func init() {
+ config.SetProviderService(new(UserProvider))
+ // ------for hessian2------
+ hessian.RegisterPOJO(&User{})
+}
+```
+
+### 第二步:编写主程序
+
+> <https://github.com/dubbogo/dubbo-samples/blob/master/golang/helloworld/dubbo/go-server/app/server.go>
+
+1. 引入必需的dubbo-go包
+
+```go
+import (
+ hessian "github.com/apache/dubbo-go-hessian2"
+ "github.com/apache/dubbo-go/config"
+ _ "github.com/apache/dubbo-go/registry/protocol"
+ _ "github.com/apache/dubbo-go/common/proxy/proxy_factory"
+ _ "github.com/apache/dubbo-go/filter/impl"
+ _ "github.com/apache/dubbo-go/cluster/cluster_impl"
+ _ "github.com/apache/dubbo-go/cluster/loadbalance"
+ _ "github.com/apache/dubbo-go/registry/zookeeper"
+
+ _ "github.com/apache/dubbo-go/protocol/dubbo"
+)
+
+```
+
+2. main 函数
+
+```go
+func main() {
+ config.Load()
+}
+```
+
+### 第三步:编写配置文件并配置环境变量
+
+1. 参考 [log](https://github.com/dubbogo/dubbo-samples/blob/master/golang/helloworld/dubbo/go-server/profiles/release/log.yml) 和 [server](https://github.com/dubbogo/dubbo-samples/blob/master/golang/helloworld/dubbo/go-server/profiles/release/server.yml) 编辑配置文件。
+
+主要编辑以下部分:
+
+* `registries` 结点下需要配置zk的数量和地址
+
+* `services` 结点下配置服务的具体信息,需要配置 `interface` 配置,修改为对应服务的接口名,服务的key对应第一步中 `Provider` 的 `Reference` 返回值
+
+2. 把上面的两个配置文件分别配置为环境变量
+
+```shell
+export CONF_PROVIDER_FILE_PATH="xxx"
+export APP_LOG_CONF_FILE="xxx"
+```
+
+## 接着是客户端
+
+### 第一步:编写客户端 `Provider`
+
+> <https://github.com/dubbogo/dubbo-samples/blob/master/golang/helloworld/dubbo/go-client/app/user.go>
+
+1. 参考服务端第一步的第一点。
+
+2. 与服务端不同的是,提供服务的方法作为结构体的参数,不需要编写具体业务逻辑。另外,`Provider` 不对应dubbo中的接口,而是对应一个实现。
+
+```go
+type UserProvider struct {
+ GetUser func(ctx context.Context, req []interface{}, rsp *User) error
+}
+
+func (u *UserProvider) Reference() string {
+ return "UserProvider"
+}
+```
+
+3. 注册服务和对象
+
+```go
+func init() {
+ config.SetConsumerService(userProvider)
+ hessian.RegisterPOJO(&User{})
+}
+```
+
+### 第二步:编写客户端主程序
+
+> <https://github.com/dubbogo/dubbo-samples/blob/master/golang/helloworld/dubbo/go-client/app/client.go>
+
+1. 引入必需的dubbo-go包
+
+```go
+import (
+ hessian "github.com/apache/dubbo-go-hessian2"
+ "github.com/apache/dubbo-go/config"
+ _ "github.com/apache/dubbo-go/registry/protocol"
+ _ "github.com/apache/dubbo-go/common/proxy/proxy_factory"
+ _ "github.com/apache/dubbo-go/filter/impl"
+ _ "github.com/apache/dubbo-go/cluster/cluster_impl"
+ _ "github.com/apache/dubbo-go/cluster/loadbalance"
+ _ "github.com/apache/dubbo-go/registry/zookeeper"
+
+ _ "github.com/apache/dubbo-go/protocol/dubbo"
+)
+```
+
+2. main 函数
+
+```go
+func main() {
+ config.Load()
+ time.Sleep(3e9)
+
+ println("\n\n\nstart to test dubbo")
+ user := &User{}
+ err := userProvider.GetUser(context.TODO(), []interface{}{"A001"}, user)
+ if err != nil {
+ panic(err)
+ }
+ println("response result: %v\n", user)
+}
+func println(format string, args ...interface{}) {
+ fmt.Printf("\033[32;40m"+format+"\033[0m\n", args...)
+}
+```
+
+### 第三步:编写配置文件并配置环境变量
+
+1. 参考 [log](https://github.com/dubbogo/dubbo-samples/blob/master/golang/helloworld/dubbo/go-client/profiles/release/log.yml) 和 [client](https://github.com/dubbogo/dubbo-samples/blob/master/golang/helloworld/dubbo/go-client/profiles/release/client.yml) 编辑配置文件。
+
+主要编辑以下部分:
+
+* `registries` 结点下需要配置zk的数量和地址
+
+* `references` 结点下配置服务的具体信息,需要配置 `interface` 配置,修改为对应服务的接口名,服务的key对应第一步中 `Provider` 的 `Reference` 返回值
+
+2. 把上面的两个配置文件费别配置为环境变量,为防止log的环境变量和服务端的log环境变量冲突,建议所有的环境变量不要做全局配置,在当前起效即可。
+
+```shell
+export CONF_CONSUMER_FILE_PATH="xxx"
+export APP_LOG_CONF_FILE="xxx"
+```
diff --git a/content/zh/docs/languages/golang/go-specific.md b/content/zh/docs/languages/golang/go-specific.md
index 4f18341..456c1e8 100644
--- a/content/zh/docs/languages/golang/go-specific.md
+++ b/content/zh/docs/languages/golang/go-specific.md
@@ -4,4 +4,4 @@ title: "Go 语言定义服务"
linkTitle: "Go 语言定义服务"
weight: 10
description: ""
----
\ No newline at end of file
+---