Skip to content

Commit

Permalink
add dubbo samples for tengine dubbo
Browse files Browse the repository at this point in the history
  • Loading branch information
MengqiWu committed Aug 16, 2019
1 parent a2b6a0a commit 39be20e
Show file tree
Hide file tree
Showing 10 changed files with 700 additions and 0 deletions.
175 changes: 175 additions & 0 deletions dubbo-samples-tengine/README.md
@@ -0,0 +1,175 @@
# Quick Start

## Install Tengine

### Get 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
```

CentOS maybe need
```
sudo yum install gcc
sudo yum install gcc-c++
```

### Run Tengine

modify tengine config file ```/usr/local/nginx/conf/nginx.conf``` to

```
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.samples.tengine.DemoService 0.0.0 tengineDubbo 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:20880;
}
}
```

### Start Tengine

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

Other Commond (no need execute usual)
```
#restart
/usr/local/nginx/sbin/nginx -s reload
#stop
/usr/local/nginx/sbin/nginx -s stop
```

### More document
```
https://github.com/alibaba/tengine/blob/master/docs/modules/ngx_http_dubbo_module.md
https://github.com/alibaba/tengine/blob/master/docs/modules/ngx_http_dubbo_module_cn.md
```

## Install Dubbo
### Get Dubbo Samples

```
git clone https://github.com/apache/dubbo-samples.git
```

### Build Dubbo Tengine Sample
depend on ```maven``` and ```jdk8```

```
cd ./dubbo-samples/dubbo-samples-tengine
mvn package
```

CentOS maybe need
```
sudo yum install maven
#or
wget http://repos.fedorapeople.org/repos/dchen/apache-maven/epel-apache-maven.repo -O /etc/yum.repos.d/epel-apache-maven.repo
sudo yum -y install apache-maven
sudo yum install java-1.8.0-openjdk-devel
```

Ubuntu maybe need
```
sudo apt install maven
sudo apt install openjdk-8-jdk-devel
#some times
sudo apt-get install software-properties-common
sudo add-apt-repository ppa:openjdk-r/ppa
sudo apt-get update
sudo apt-get install openjdk-8-jdk
sudo update-alternatives --config java
```

### Run Dubbo Demo
```
cd dubbo-samples-tengine-provider/target/
java -Djava.net.preferIPv4Stack=true -jar dubbo-demo-provider.one-jar.jar
```


## Do Test

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

Like this

```
curl http://127.0.0.1:8080/dubbo -i
HTTP/1.1 200 OK
Server: Tengine/2.3.1
Date: Thu, 15 Aug 2019 05:42:15 GMT
Content-Type: application/octet-stream
Content-Length: 13
Connection: keep-alive
test: 123
dubbo success
```

This doc Verified on
```
Ubuntu 14.04
Ubuntu 16.04
Ubuntu 18.04
Centos 7
Centos 6
```
29 changes: 29 additions & 0 deletions dubbo-samples-tengine/dubbo-samples-tengine-interface/pom.xml
@@ -0,0 +1,29 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.apache.dubbo.sample</groupId>
<artifactId>dubbo-samples-tengine</artifactId>
<version>1.0.0-SNAPSHOT</version>
</parent>
<groupId>org.apache.dubbo.sample</groupId>
<artifactId>dubbo-samples-tengine-interface</artifactId>
<version>1.0.0-SNAPSHOT</version>
<packaging>jar</packaging>
<name>${project.artifactId}</name>
<description>The demo module of tengine dubbo</description>
<properties>
<skip_maven_deploy>true</skip_maven_deploy>
</properties>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
</plugins>
</build>
</project>
@@ -0,0 +1,43 @@
/*
* 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 org.apache.dubbo.samples.tengine;

import java.util.Map;

public interface DemoService {;

/**
* standard samples tengine dubbo infterace demo
* @param context tengine pass http infos
* @return Map<String, Object></> pass to tengine response http
**/
Map<String, Object> tengineDubbo(Map<String, Object> context);

/**
* a test sample for dubbo to http invoke
* @param context tengine pass http infos
* @return Map<String, Object></> pass to tengine response http
**/
Map<String, Object> dubbo2Http(Map<String, Object> context);

/**
* a test for dubbo boundary case
* @param context tengine pass http infos
* @return Map<String, Object></> pass to tengine response http
**/
Map<String, Object> tengineTest(Map<String, Object> context);
}
80 changes: 80 additions & 0 deletions dubbo-samples-tengine/dubbo-samples-tengine-provider/pom.xml
@@ -0,0 +1,80 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.apache.dubbo.sample</groupId>
<artifactId>dubbo-samples-tengine</artifactId>
<version>1.0.0-SNAPSHOT</version>
</parent>
<groupId>org.apache.dubbo.sample</groupId>
<artifactId>dubbo-samples-tengine-provider</artifactId>
<version>1.0.0-SNAPSHOT</version>
<packaging>jar</packaging>
<name>${project.artifactId}</name>
<description>The demo provider module of dubbo tengine</description>
<properties>
<skip_maven_deploy>true</skip_maven_deploy>
<slf4j-log4j12.version>1.7.25</slf4j-log4j12.version>
<curator.version>2.12.0</curator.version>
<dubbo.version>2.7.3</dubbo.version>
</properties>

<dependencies>
<dependency>
<groupId>org.apache.dubbo.sample</groupId>
<artifactId>dubbo-samples-tengine-interface</artifactId>
<version>1.0.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>org.apache.dubbo</groupId>
<artifactId>dubbo</artifactId>
<version>${dubbo.version}</version>
</dependency>
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient</artifactId>
<version>4.5.5</version>
</dependency>
</dependencies>

<build>
<finalName>dubbo-demo-provider</finalName>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<configuration>
<archive>
<manifest>
<mainClass>org.apache.dubbo.samples.tengine.provider.Provider</mainClass>
</manifest>
</archive>
</configuration>
</plugin>
<plugin>
<groupId>com.jolira</groupId>
<artifactId>onejar-maven-plugin</artifactId>
<version>1.4.4</version>
<executions>
<execution>
<goals>
<goal>one-jar</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>

0 comments on commit 39be20e

Please sign in to comment.