Skip to content

Commit

Permalink
Merge pull request #446 from xxxxzr/modify/wiki
Browse files Browse the repository at this point in the history
Modify/wiki
  • Loading branch information
rayzhang0603 authored May 25, 2017
2 parents 24d1f87 + 8095f94 commit 314f1d2
Show file tree
Hide file tree
Showing 2 changed files with 215 additions and 21 deletions.
208 changes: 201 additions & 7 deletions docs/wiki/en_quickstart.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,24 +19,24 @@ The quick start gives very basic example of running server and client on the sam
<dependency>
<groupId>com.weibo</groupId>
<artifactId>motan-core</artifactId>
<version>0.1.1</version>
<version>RELEASE</version>
</dependency>
<dependency>
<groupId>com.weibo</groupId>
<artifactId>motan-transport-netty</artifactId>
<version>0.1.1</version>
<version>RELEASE</version>
</dependency>

<!-- dependencies blow were only needed for spring-based features -->
<dependency>
<groupId>com.weibo</groupId>
<artifactId>motan-springsupport</artifactId>
<version>0.1.1</version>
<version>RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<version>4.2.4.RELEASE</version>
<version>RELEASE</version>
</dependency>
```

Expand Down Expand Up @@ -173,7 +173,7 @@ UI backend [http://localhost:8500/ui](http://localhost:8500/ui)
<dependency>
<groupId>com.weibo</groupId>
<artifactId>motan-registry-consul</artifactId>
<version>0.1.1</version>
<version>RELEASE</version>
</dependency>
```

Expand All @@ -183,7 +183,7 @@ UI backend [http://localhost:8500/ui](http://localhost:8500/ui)
<motan:registry regProtocol="consul" name="my_consul" address="127.0.0.1:8500"/>
```

3. Change the way of service discovery to registry in the configuration of server and client.
3. Change the way of service discovery to service discovery through registry in the configuration of server and client.

server:

Expand Down Expand Up @@ -230,7 +230,7 @@ Install and start ZooKeeper:
<dependency>
<groupId>com.weibo</groupId>
<artifactId>motan-registry-zookeeper</artifactId>
<version>0.1.1</version>
<version>RELEASE</version>
</dependency>
```

Expand Down Expand Up @@ -274,3 +274,197 @@ Install and start ZooKeeper:
[maven]:https://maven.apache.org
[gradle]:http://gradle.org

## <a id="other"></a>Other invoke examples

### <a id="motan-yar"></a>Providing YAR protocol service

[YAR](https://github.com/laruence/yar) protocol is a rpc extension of php,motan framework can provide yar protocol for RPC services
1、add motan-protocol-yar.jar

```xml
<dependency>
<groupId>com.weibo</groupId>
<artifactId>motan-protocol-yar</artifactId>
<version>RELEASE</version>
</dependency>
```

2Add annotations @YarConfig to the service interface class to declare the uri of the service

```java
@YarConfig(path = "/openapi/yarserver/test")
public interface YarService {
public String hello(String name);
```

3Configure protocol name = "yar"

```xml
<motan:protocol id="demoYar" name="yar" .../>
```

4Configure the export of service, using yar protocol to provide services

```xml
<motan:service interface="com.weibo.motan.demo.service.YarService"
export="demoYar:8003" .../>
```

Check motan-demo module to get specific configuration.
YAR protocol use [yar-java](https://github.com/weibocom/yar-java) to parse,and can be use directly when using java as client

### <a id="motan-annotation"></a>Using the annotations to configure the motan
#### server:

1Declare Annotation to specify the name of the package to be resolved

```java
@Bean
public AnnotationBean motanAnnotationBean() {
AnnotationBean motanAnnotationBean = new AnnotationBean();
motanAnnotationBean.setPackage("com.weibo.motan.demo.server");
return motanAnnotationBean;
}
```

2Configure the bean object of ProtocolConfig, RegistryConfig,and BasicServiceConfig, which is consistent with the protocol, registry, and basicService tags in the xml configuration

```java
@Bean(name = "demoMotan")
public ProtocolConfigBean protocolConfig1() {
ProtocolConfigBean config = new ProtocolConfigBean();
config.setDefault(true);
config.setName("motan");
config.setMaxContentLength(1048576);
return config;
}

@Bean(name = "registryConfig1")
public RegistryConfigBean registryConfig() {
RegistryConfigBean config = new RegistryConfigBean();
config.setRegProtocol("local");
return config;
}

@Bean
public BasicServiceConfigBean baseServiceConfig() {
BasicServiceConfigBean config = new BasicServiceConfigBean();
config.setExport("demoMotan:8002");
config.setGroup("testgroup");
config.setAccessLog(false);
config.setShareChannel(true);
config.setModule("motan-demo-rpc");
config.setApplication("myMotanDemo");
config.setRegistry("registryConfig1");
return config;
}
```

3Add the @MotanService annotation to the implementation class of the service. The configuration parameters of the annotation are the same as the service tag of the xml configuration.

```java
@MotanService(export = "demoMotan:8002")
public class MotanDemoServiceImpl implements MotanDemoService {

public String hello(String name) {
System.out.println(name);
return "Hello " + name + "!";
}
}
```

4Using [spring-boot](https://github.com/spring-projects/spring-boot) to boot service

```java
@EnableAutoConfiguration
@SpringBootApplication
public class SpringBootRpcServerDemo {

public static void main(String[] args) {
System.setProperty("server.port", "8081");
ConfigurableApplicationContext context = SpringApplication.run(SpringBootRpcServerDemo.class, args);

MotanSwitcherUtil.setSwitcherValue(MotanConstants.REGISTRY_HEARTBEAT_SWITCHER, true);
System.out.println("server start...");
}
}
```

Check motan-demo module to get specific configuration

#### client:
1Declare the configuration bean for Annotation, protocolConfig, and RegistryConfig. The server is configured similarly to the server.

2Configuring basicRefererConfig bean

```java
@Bean(name = "motantestClientBasicConfig")
public BasicRefererConfigBean baseRefererConfig() {
BasicRefererConfigBean config = new BasicRefererConfigBean();
config.setProtocol("demoMotan");
config.setGroup("motan-demo-rpc");
config.setModule("motan-demo-rpc");
config.setApplication("myMotanDemo");
config.setRegistry("registry");
config.setCheck(false);
config.setAccessLog(true);
config.setRetries(2);
config.setThrowException(true);
return config;
}
```

3Add the @MotanReferer annotation to the object that uses the motan service. The registration configuration is consistent with the referer tag in xml mode

```java
@RestController
public class HelloController {

@MotanReferer(basicReferer = "motantestClientBasicConfig", group = "testgroup", directUrl = "127.0.0.1:8002")
MotanDemoService service;

@RequestMapping("/")
@ResponseBody
public String home() {
String result = service.hello("test");
return result;
}
}
```

4Using spring-boot to boot client

```java
@EnableAutoConfiguration
@SpringBootApplication
public class SpringBootRpcClientDemo {

public static void main(String[] args) {
SpringApplication.run(SpringBootRpcClientDemo.class, args);
}
}
```

Check motan-demo module to get specific configuration

## <a id="opentracing"></a>Using OpenTracing

Motan support [OpenTracing](http://opentracing.io)through the filter's SPI extension mechanism, which can support any trace implementation that implements the OpenTracing standard. The following steps are required to use OpenTracing.

1、add filter-opentracing to pom

```xml
<dependency>
<groupId>com.weibo</groupId>
<artifactId>filter-opentracing</artifactId>
<version>RELEASE</version>
</dependency>
```

2If the third-party trace tool declares the io.opentracing.Tracer's SPI extension, you can directly introduce a third-party trace to the jar package. If the third party does not make a statement, turn to the third step.
3、Customize a TracerFactory implementation TracerFactory interface, through getTracer () to get different tracer implementation. Set the tracerFactory of the OpenTracingContext to a custom TracerFactory.
You can refer to the filter-opentracing module src / test / java / com.weibo.api.motan.filter.opentracing.zipkin.demo package under the server and client side to achieve.
28 changes: 14 additions & 14 deletions docs/wiki/zh_quickstart.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,24 +26,24 @@
<dependency>
<groupId>com.weibo</groupId>
<artifactId>motan-core</artifactId>
<version>0.2.2</version>
<version>RELEASE</version>
</dependency>
<dependency>
<groupId>com.weibo</groupId>
<artifactId>motan-transport-netty</artifactId>
<version>0.2.2</version>
<version>RELEASE</version>
</dependency>

<!-- only needed for spring-based features -->
<dependency>
<groupId>com.weibo</groupId>
<artifactId>motan-springsupport</artifactId>
<version>0.2.2</version>
<version>RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<version>4.2.4.RELEASE</version>
<version>RELEASE</version>
</dependency>
```

Expand Down Expand Up @@ -172,7 +172,7 @@
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>build-helper-maven-plugin</artifactId>
<version>1.10</version>
<version>RELEASE</version>
<executions>
<execution>
<phase>generate-sources</phase>
Expand Down Expand Up @@ -263,7 +263,7 @@ ui后台 [http://localhost:8500/ui](http://localhost:8500/ui)
<dependency>
<groupId>com.weibo</groupId>
<artifactId>motan-registry-consul</artifactId>
<version>0.1.1</version>
<version>RELEASE</version>
</dependency>
```

Expand Down Expand Up @@ -320,7 +320,7 @@ ui后台 [http://localhost:8500/ui](http://localhost:8500/ui)
<dependency>
<groupId>com.weibo</groupId>
<artifactId>motan-registry-zookeeper</artifactId>
<version>0.2.1</version>
<version>RELEASE</version>
</dependency>
```

Expand Down Expand Up @@ -366,7 +366,7 @@ ui后台 [http://localhost:8500/ui](http://localhost:8500/ui)

## <a id="other"></a>其他调用示例

###<a id="motan-yar"></a>提供YAR协议服务
### <a id="motan-yar"></a>提供YAR协议服务

[YAR](https://github.com/laruence/yar)协议是php的一个rpc扩展,motan框架可以提供yar协议的RPC服务
1、引入motan-protocol-yar.jar
Expand All @@ -375,7 +375,7 @@ ui后台 [http://localhost:8500/ui](http://localhost:8500/ui)
<dependency>
<groupId>com.weibo</groupId>
<artifactId>motan-protocol-yar</artifactId>
<version>0.2.1</version>
<version>RELEASE</version>
</dependency>
```

Expand Down Expand Up @@ -404,8 +404,8 @@ ui后台 [http://localhost:8500/ui](http://localhost:8500/ui)
具体配置见motan-demo模块
YAR协议使用[yar-java](https://github.com/weibocom/yar-java)进行解析,java作为YAR client时可以直接使用

###<a id="motan-annotation"></a>使用注解方式配置motan
####server端配置
### <a id="motan-annotation"></a>使用注解方式配置motan
#### server端配置

1、声明Annotation用来指定需要解析的包名

Expand Down Expand Up @@ -483,7 +483,7 @@ YAR协议使用[yar-java](https://github.com/weibocom/yar-java)进行解析,ja

server端详细配置请参考motan-demo模块

####client端配置
#### client端配置
1、声明Annotation、protocolConfig、RegistryConfig的配置bean。方式与server端配置类似。

2、配置basicRefererConfig bean
Expand Down Expand Up @@ -547,8 +547,8 @@ Motan通过filter的SPI扩展机制支持[OpenTracing](http://opentracing.io),
```xml
<dependency>
<groupId>com.weibo</groupId>
<artifactId>motan-protocol-yar</artifactId>
<version>0.2.3</version>
<artifactId>filter-opentracing</artifactId>
<version>RELEASE</version>
</dependency>
```

Expand Down

0 comments on commit 314f1d2

Please sign in to comment.