Skip to content

Commit

Permalink
Ftr: Tengine Calls Dubbo-go Example (apache#122)
Browse files Browse the repository at this point in the history
* Ftr: Tengine Calls Dubbo-go Example

* update: import to 3.0
  • Loading branch information
PhilYue authored Jun 1, 2021
1 parent e6ea018 commit a06e170
Show file tree
Hide file tree
Showing 12 changed files with 676 additions and 0 deletions.
15 changes: 15 additions & 0 deletions .run/tengine/tengine-go-server.run.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<component name="ProjectRunConfigurationManager">
<configuration default="false" name="tengine-go-server" type="GoApplicationRunConfiguration" factoryName="Go Application" folderName="tengine">
<module name="dubbo-go-samples" />
<working_directory value="$PROJECT_DIR$" />
<envs>
<env name="APP_LOG_CONF_FILE" value="$PROJECT_DIR$/tengine/go-server/conf/log.yml" />
<env name="CONF_PROVIDER_FILE_PATH" value="$PROJECT_DIR$/tengine/go-server/conf/server.yml" />
</envs>
<kind value="PACKAGE" />
<filePath value="$PROJECT_DIR$/tengine/go-server/cmd/server.go" />
<package value="github.com/apache/dubbo-go-samples/tengine/go-server/cmd" />
<directory value="$PROJECT_DIR$" />
<method v="2" />
</configuration>
</component>
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
* router: router examples, including condition and tag
* seata: A seata example
* shop: Shop sample
* tengine: Taobao Tengine and Dubbo-go example
* tls: Use TLS in Dubbo-go application
* tracing: tracing example
* game: game service example

Expand Down
2 changes: 2 additions & 0 deletions README_zh.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
* router: 展示了 dubbo3 统一路由规则的使用,包括基于文件路由配置和k8s环境下的动态路由配置
* seata: 展示了与 seata 的对接
* shop: 一个在线商店的小例子
* tengine: 基于淘宝 Tengine 与 Dubbo-go 调用例子
* tls: 在 Dubbo-go 中使用 TLS
* tracing: 链路追踪
* game: 游戏服务例子

Expand Down
165 changes: 165 additions & 0 deletions tengine/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,165 @@
# Tengine Calls Dubbo-go Example

## Backend

Tengine is a web server originated by Taobao, It is based on the Nginx HTTP server and has many advanced features.

Starting from version '2.3.2' to support the `dubbo` protocol, this example will demonstrate that based on the `dubbo` protocol, Tengine calls the Dubbo-go service.

## Introduction

```markdown
.
├── README.md
├── README_zh.md
└── go-server
├── cmd
├── conf
├── docker
└── pkg
```

- go-server: The Service Provider
- docker: Tengine & Zookeeper

## Install Tengine

### Uses Docker

Uses Docker :

Easy build and run with [/dubbo-go-sample/tengine/go-server/docker/docker-compose.yml](/tengine/go-server/docker/docker-compose.yml)

This example uses the latest version of Tengine 'v2.3.3', which in fact supports the 'dubbo' protocol from `v2.3.2`.

### Manual

See [tengine](https://github.com/alibaba/tengine)

#### Clone Tengine
```
git clone https://github.com/alibaba/tengine.git
```
#### Get some other vendor
```
cd ./tengine
wget https://ftp.pcre.org/pub/pcre/pcre-8.43.tar.gz
tar xvf pcre-8.43.tar.gz
wget https://www.openssl.org/source/openssl-1.0.2s.tar.gz
tar xvf openssl-1.0.2s.tar.gz
wget http://www.zlib.net/zlib-1.2.11.tar.gz
tar xvf zlib-1.2.11.tar.gz
```

### Build Tengine
```
./configure --add-module=./modules/mod_dubbo --add-module=./modules/ngx_multi_upstream_module --add-module=./modules/mod_config --with-pcre=./pcre-8.43/ --with-openssl=./openssl-1.0.2s/ --with-zlib=./zlib-1.2.11
make
sudo make install
```

### Config

modify Tengine config file `/usr/local/nginx/conf/nginx.conf`

```
worker_processes 1;
events {
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;
sendfile on;
server {
listen 8080;
server_name localhost;
#pass the Dubbo to Dubbo Provider server listening on 127.0.0.1:20880
location / {
dubbo_pass_all_headers on;
dubbo_pass_set args $args;
dubbo_pass_set uri $uri;
dubbo_pass_set method $request_method;
dubbo_pass org.apache.dubbo.UserProvider 0.0.0 GetUser dubbo_backend;
}
}
#pass the Dubbo to Dubbo Provider server listening on 127.0.0.1:20880
upstream dubbo_backend {
multi 1;
server 127.0.0.1:20000;
}
}
```

### Run Tengine

```
/usr/local/nginx/sbin/nginx
```

restart or stop

```
#restart
/usr/local/nginx/sbin/nginx -s reload
#stop
/usr/local/nginx/sbin/nginx -s stop
```

## Start Dubbo-go Provider

Configure the environment variable to specify the configuration file path required for the service to load.

go-server:

```shell
APP_LOG_CONF_FILE=tengine/go-server/conf/log.yml;
CONF_PROVIDER_FILE_PATH=tengine/go-server/conf/server.yml
```


Refer to [HOWTO.md](../HOWTO_zh.md) under the root directory to run this sample.

## See

execute with terminal :

```shell
curl http://127.0.0.1:8080/dubbo -i
```

Response:

```shell
HTTP/1.1 200 OK
Server: Tengine/2.3.3
Date: Sat, 29 May 2021 15:41:30 GMT
Content-Type: application/octet-stream
Transfer-Encoding: chunked
Connection: keep-alive
Age: 18
ID: A001
Name: Alex Stocks
Time: 1622302890448
```

Now, a simple example of Tengine Calls Dubbo-go is done.

More Features please refer to:

[tengine/../ngx_http_dubbo_module_cn](https://github.com/alibaba/tengine/blob/master/docs/modules/ngx_http_dubbo_module_cn.md)




162 changes: 162 additions & 0 deletions tengine/README_zh.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,162 @@
# Tengine Calls Dubbo-go 示例

## 背景

Tengine 是由淘宝网在Nginx的基础上发起的Web服务器项目。针对大访问量网站的需求,添加了很多高级功能和特性,比如 `2.3.2` 开始支持 Dubbo 协议,本示例将演示基于 Dubbo 协议,Tengine 调用 Dubbo-go 服务。

## 介绍

```markdown
.
├── README.md
├── README_zh.md
└── go-server
├── cmd
├── conf
├── docker
└── pkg
```

- go-server :服务提供者
- docker : 提供 Tengine 与 Zookeeper

## 安装 Tengine

### 使用 Docker

使用 Docker :

直接启动 [/dubbo-go-sample/tengine/go-server/docker/docker-compose.yml](/tengine/go-server/docker/docker-compose.yml)

本示例使用最新版本 tengine `v2.3.3`,事实上从 2.3.2 开始支持 `dubbo` 协议

### 手动安装

参考 [tengine](https://github.com/alibaba/tengine)

#### Clone Tengine
```
git clone https://github.com/alibaba/tengine.git
```
#### 安装其他支持库
```
cd ./tengine
wget https://ftp.pcre.org/pub/pcre/pcre-8.43.tar.gz
tar xvf pcre-8.43.tar.gz
wget https://www.openssl.org/source/openssl-1.0.2s.tar.gz
tar xvf openssl-1.0.2s.tar.gz
wget http://www.zlib.net/zlib-1.2.11.tar.gz
tar xvf zlib-1.2.11.tar.gz
```

### 构建 Tengine
```
./configure --add-module=./modules/mod_dubbo --add-module=./modules/ngx_multi_upstream_module --add-module=./modules/mod_config --with-pcre=./pcre-8.43/ --with-openssl=./openssl-1.0.2s/ --with-zlib=./zlib-1.2.11
make
sudo make install
```

### 修改配置

修改 tengine 配置文件 `/usr/local/nginx/conf/nginx.conf`

```
worker_processes 1;
events {
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;
sendfile on;
server {
listen 8080;
server_name localhost;
#pass the Dubbo to Dubbo Provider server listening on 127.0.0.1:20880
location / {
dubbo_pass_all_headers on;
dubbo_pass_set args $args;
dubbo_pass_set uri $uri;
dubbo_pass_set method $request_method;
dubbo_pass org.apache.dubbo.UserProvider 0.0.0 GetUser dubbo_backend;
}
}
#pass the Dubbo to Dubbo Provider server listening on 127.0.0.1:20880
upstream dubbo_backend {
multi 1;
server 127.0.0.1:20000;
}
}
```

### 启动 Tengine

```
/usr/local/nginx/sbin/nginx
```

重启、停止
```
#restart
/usr/local/nginx/sbin/nginx -s reload
#stop
/usr/local/nginx/sbin/nginx -s stop
```

## 启动服务提供者

注意:
配置环境变量,指定服务加载所需配置文件路径

go-server:

```shell
APP_LOG_CONF_FILE=direct/go-server/conf/log.yml;
CONF_PROVIDER_FILE_PATH=direct/go-server/conf/server.yml
```

具体请参阅根目录中的 [HOWTO.md](../HOWTO_zh.md) 来运行本例。

## 查看效果

执行:

```shell
curl http://127.0.0.1:8080/dubbo -i
```

响应:

```shell
HTTP/1.1 200 OK
Server: Tengine/2.3.3
Date: Sat, 29 May 2021 15:41:30 GMT
Content-Type: application/octet-stream
Transfer-Encoding: chunked
Connection: keep-alive
Age: 18
ID: A001
Name: Alex Stocks
Time: 1622302890448
```

一个简单的 Tengine Calls Dubbo-go 的例子已经完成了

更多功能请参考:

[tengine/../ngx_http_dubbo_module_cn](https://github.com/alibaba/tengine/blob/master/docs/modules/ngx_http_dubbo_module_cn.md)




Loading

0 comments on commit a06e170

Please sign in to comment.