Skip to content

Commit

Permalink
Merge pull request apache#3 from apache/master
Browse files Browse the repository at this point in the history
merge master
  • Loading branch information
PhilYue authored Mar 3, 2021
2 parents 4af0861 + 19c6ece commit e095b64
Show file tree
Hide file tree
Showing 33 changed files with 1,597 additions and 236 deletions.
15 changes: 15 additions & 0 deletions .run/chain-backend-server.run.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<component name="ProjectRunConfigurationManager">
<configuration default="false" name="chain-backend-server" type="GoApplicationRunConfiguration" factoryName="Go Application">
<module name="dubbo-go-samples" />
<working_directory value="$PROJECT_DIR$/chain" />
<envs>
<env name="CONF_PROVIDER_FILE_PATH" value="backend/conf/server.yml" />
<env name="APP_LOG_CONF_FILE" value="backend/conf/log.yml" />
</envs>
<kind value="PACKAGE" />
<filePath value="$PROJECT_DIR$/chain/backend/cmd/server.go" />
<package value="github.com/apache/dubbo-go-samples/chain/backend/cmd" />
<directory value="$PROJECT_DIR$" />
<method v="2" />
</configuration>
</component>
17 changes: 17 additions & 0 deletions .run/chain-backend-test.run.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<component name="ProjectRunConfigurationManager">
<configuration default="false" name="chain-backend-test" type="GoTestRunConfiguration" factoryName="Go Test">
<module name="dubbo-go-samples" />
<working_directory value="$PROJECT_DIR$/chain" />
<useCustomBuildTags value="true" />
<envs>
<env name="CONF_CONSUMER_FILE_PATH" value="backend/conf/client.yml" />
<env name="APP_LOG_CONF_FILE" value="backend/conf/log.yml" />
</envs>
<framework value="gotest" />
<kind value="PACKAGE" />
<package value="github.com/apache/dubbo-go-samples/chain/backend/tests/integration" />
<directory value="$PROJECT_DIR$" />
<filePath value="$PROJECT_DIR$" />
<method v="2" />
</configuration>
</component>
15 changes: 15 additions & 0 deletions .run/chain-frontend-client.run.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<component name="ProjectRunConfigurationManager">
<configuration default="false" name="chain-frontend-client" type="GoApplicationRunConfiguration" factoryName="Go Application">
<module name="dubbo-go-samples" />
<working_directory value="$PROJECT_DIR$/chain" />
<envs>
<env name="CONF_CONSUMER_FILE_PATH" value="frontend/conf/client.yml" />
<env name="APP_LOG_CONF_FILE" value="frontend/conf/log.yml" />
</envs>
<kind value="PACKAGE" />
<filePath value="$PROJECT_DIR$/chain/frontend/cmd/client.go" />
<package value="github.com/apache/dubbo-go-samples/chain/frontend/cmd" />
<directory value="$PROJECT_DIR$" />
<method v="2" />
</configuration>
</component>
16 changes: 16 additions & 0 deletions .run/chain-middle-server.run.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<component name="ProjectRunConfigurationManager">
<configuration default="false" name="chain-middle-server" type="GoApplicationRunConfiguration" factoryName="Go Application">
<module name="dubbo-go-samples" />
<working_directory value="$PROJECT_DIR$/chain" />
<envs>
<env name="CONF_PROVIDER_FILE_PATH" value="middle/conf/server.yml" />
<env name="CONF_CONSUMER_FILE_PATH" value="middle/conf/client.yml" />
<env name="APP_LOG_CONF_FILE" value="middle/conf/log.yml" />
</envs>
<kind value="PACKAGE" />
<filePath value="$PROJECT_DIR$/chain/middle/cmd/server.go" />
<package value="github.com/apache/dubbo-go-samples/chain/middle/cmd" />
<directory value="$PROJECT_DIR$" />
<method v="2" />
</configuration>
</component>
17 changes: 17 additions & 0 deletions .run/chain-middle-test.run.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<component name="ProjectRunConfigurationManager">
<configuration default="false" name="chain-middle-test" type="GoTestRunConfiguration" factoryName="Go Test">
<module name="dubbo-go-samples" />
<working_directory value="$PROJECT_DIR$/chain" />
<useCustomBuildTags value="true" />
<envs>
<env name="CONF_CONSUMER_FILE_PATH" value="middle/conf/test.yml" />
<env name="APP_LOG_CONF_FILE" value="middle/conf/log.yml" />
</envs>
<framework value="gotest" />
<kind value="PACKAGE" />
<package value="github.com/apache/dubbo-go-samples/chain/middle/tests/integration" />
<directory value="$PROJECT_DIR$" />
<filePath value="$PROJECT_DIR$" />
<method v="2" />
</configuration>
</component>
77 changes: 77 additions & 0 deletions chain/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
# Chain Sample

### Backend

Most of the samples in this project uses one consumer and one provider for simplification purpose. That is, there are only two nodes in the calling chain. This sample demonstrates how a calling chain which contains nodes more than two - three nodes at minimal, is configured. This sample contains three parts, which are:

frontend -> middle -> backend

1. backend: Backend services, including 'CatService', 'DogService', 'TigerService' and 'LionService'. In "backend" directory, only service providers are provided.
2. middle: Middle services, in the middle of the calling chain, provides services 'ChineseService' and 'AmericanService', and consumes the services provided by "backend" directory. In "middle" directory, both service providers and service consumers are provided.
3. frontend: Frontend caller, consumes services provided by "middle" and output the result.

### Call other service in the current service

**Code**

```golang
type DogService struct {
GetId func() (int, error)
GetName func() (string, error)
Yell func() (string, error)
}

func (d *DogService) Reference() string {
return "DogService"
}

type TigerService struct {
GetId func() (int, error)
GetName func() (string, error)
Yell func() (string, error)
}

func (t *TigerService) Reference() string {
return "TigerService"
}

func init() {
dog := new(DogService)
config.SetConsumerService(dog)
tiger := new(TigerService)
config.SetConsumerService(tiger)

config.SetProviderService(&ChineseService{
dog: dog,
tiger: tiger,
})
}
```

**Configuration**

```yaml
# reference config
references:
"CatService":
registry: "demoZk"
protocol: "dubbo"
interface: "org.apache.dubbo.demo.CatService"
"DogService":
registry: "demoZk"
protocol: "dubbo"
interface: "org.apache.dubbo.demo.DogService"

# service config
services:
"ChineseService":
registry: "demoZk"
protocol: "dubbo"
interface: "org.apache.dubbo.demo.ChineseService"
"AmericanService":
registry: "demoZk"
protocol: "dubbo"
interface: "org.apache.dubbo.demo.AmericanService"
```
Pls. refer to [HOWTO.md](../HOWTO.md) under the root directory to run this sample.
80 changes: 80 additions & 0 deletions chain/README_zh.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
# 链路调用示例

### 背景

为了简化起见,绝大部分的例子都是展示了一个 consumer 调用一个 provider 的场景。也就是说,这个调用链路上只有两个节点。本例展示了大于两个节点的最小链路单元 —— 三节点,dubbo-go 是如何配置和工作的。在这个例子中,由三部分组成:

frontend -> middle -> backend

1. backend: 后端服务,包含 CatService、DogService、TigerService 和 LionService。"backend" 目录只包含了服务的提供者。
2. middle: 中间服务,在链路的中间,负责向前端(frontend)暴露服务 ChineseService 和 AmericanService,并调用后端(backend)服务。"middle" 目录既包含了服务的提供者,也包含了服务的调用者。
3. frontend: 前端调用者,调用 middle 提供的服务并输出。

### 在提供的服务中调用其他服务的示例

**代码**

```golang
type DogService struct {
GetId func() (int, error)
GetName func() (string, error)
Yell func() (string, error)
}

func (d *DogService) Reference() string {
return "DogService"
}

type TigerService struct {
GetId func() (int, error)
GetName func() (string, error)
Yell func() (string, error)
}

func (t *TigerService) Reference() string {
return "TigerService"
}

func init() {
dog := new(DogService)
config.SetConsumerService(dog)
tiger := new(TigerService)
config.SetConsumerService(tiger)

config.SetProviderService(&ChineseService{
dog: dog,
tiger: tiger,
})
}
```

**配置**

```yaml
# reference config
references:
"CatService":
registry: "demoZk"
protocol: "dubbo"
interface: "org.apache.dubbo.demo.CatService"
"DogService":
registry: "demoZk"
protocol: "dubbo"
interface: "org.apache.dubbo.demo.DogService"

# service config
services:
"ChineseService":
registry: "demoZk"
protocol: "dubbo"
interface: "org.apache.dubbo.demo.ChineseService"
"AmericanService":
registry: "demoZk"
protocol: "dubbo"
interface: "org.apache.dubbo.demo.AmericanService"
```
请参阅根目录中的 [HOWTO.md](../HOWTO_zh.md) 来运行本例。
76 changes: 76 additions & 0 deletions chain/backend/cmd/server.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
/*
* 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 (
"fmt"
"os"
"os/signal"
"syscall"
"time"
)

import (
_ "github.com/apache/dubbo-go-samples/chain/backend/pkg"
)

import (
_ "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/metadata/service/inmemory"
_ "github.com/apache/dubbo-go/protocol/dubbo"
_ "github.com/apache/dubbo-go/registry/protocol"
_ "github.com/apache/dubbo-go/registry/zookeeper"
)

var (
survivalTimeout = int(3e9)
)

// need to setup environment variable "CONF_PROVIDER_FILE_PATH" to "conf/server.yml" before run
func main() {
config.Load()
initSignal()
}

func initSignal() {
signals := make(chan os.Signal, 1)
// It is not possible to block SIGKILL or syscall.SIGSTOP
signal.Notify(signals, os.Interrupt, os.Kill, syscall.SIGHUP, syscall.SIGQUIT, syscall.SIGTERM, syscall.SIGINT)
for {
sig := <-signals
logger.Infof("get signal %s", sig.String())
switch sig {
case syscall.SIGHUP:
// reload()
default:
time.AfterFunc(time.Duration(survivalTimeout), func() {
logger.Warnf("app exit now by force...")
os.Exit(1)
})

// The program exits normally or timeout forcibly exits.
fmt.Println("provider app exit now...")
return
}
}
}
67 changes: 67 additions & 0 deletions chain/backend/conf/client.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
# dubbo client yaml configure file

check: true
# client
request_timeout: "3s"
# connect timeout
connect_timeout: "3s"

# application config
application:
organization: "dubbo.io"
name: "BackEndServicesTest"
module: "dubbo-go backend services test"
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:
"CatService":
registry: "demoZk"
protocol: "dubbo"
interface: "org.apache.dubbo.demo.CatService"
"DogService":
registry: "demoZk"
protocol: "dubbo"
interface: "org.apache.dubbo.demo.DogService"
"TigerService":
registry: "demoZk"
protocol: "dubbo"
interface: "org.apache.dubbo.demo.TigerService"
"LionService":
registry: "demoZk"
protocol: "dubbo"
interface: "org.apache.dubbo.demo.LionService"

# 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"
Loading

0 comments on commit e095b64

Please sign in to comment.