Browse Source

Merge branch 'master' of http://10.1.235.20:3000/rest/rest-guide.git

huangbo 7 years ago
parent
commit
0e0419f4c0

+ 18 - 0
ipu-service-demo/doc/pom可选配置.md

@ -0,0 +1,18 @@
1
如果需要支持redis注册中心,需要增加依赖:
2
		<dependency>
3
			<groupId>org.apache.commons</groupId>
4
			<artifactId>commons-pool2</artifactId>
5
			<version>2.2</version>
6
		</dependency>
7
		<dependency>
8
			<groupId>redis.clients</groupId>
9
			<artifactId>jedis</artifactId>
10
			<version>2.9.0</version>
11
		</dependency>
12

13
如果需要支持json格式报文(如IData param)作为方法的入参,需要增加依赖:		
14
		<dependency>
15
			<groupId>com.alibaba</groupId>
16
			<artifactId>fastjson</artifactId>
17
			<version>1.2.7</version>
18
		</dependency>

+ 18 - 0
ipu-service-demo/doc/服务缓存.md

@ -0,0 +1,18 @@
1
dubbo支持服务端查询结果进行缓存,减轻后端负载。支持3类缓存:
2
lru 基于最近最少使用原则删除多余缓存,保持最热的数据被缓存。缺省1000次。
3
threadlocal 当前线程缓存,比如一个页面渲染,用到很多 portal,每个 portal 都要去查用户信息,通过线程缓存,可以减少这种多余访问。
4
jcache 与 JSR107 集成,可以桥接各种缓存实现。
5
自定义缓存参见官方文档《http://dubbo.apache.org/books/dubbo-dev-book/impls/cache.html》
6

7
缓存级别:服务级、方法级。缓存配置在consumer/客户端,
8
服务级配置:
9
<dubbo:reference interface="com.foo.BarService" cache="lru" />
10

11
方法级配置:
12
<dubbo:reference interface="com.foo.BarService">
13
    <dubbo:method name="findBar" cache="lru" />
14
</dubbo:reference>
15

16
一旦起用缓存,dubbo会默认会缓存注册中心的信息文件,默认路径在/$userhome/.dubbo/dubbo-registry-$application_name$ip.cache
17
如果在1台机器上起了多个相同的服务进行缓存,需要在服务运行时,增加jvm参数设置不同的缓存文件,否则会报错。设置方法为:
18
-Ddubbo.registry.file=/data/.dubbo/dubbo-registry-$service_name$port.cache

+ 17 - 0
ipu-service-demo/doc/注册配置.md

@ -0,0 +1,17 @@
1
dubbo服务注册支持zookeeper、redis、multicast、simple。需要在生产者(provider/服务端)和消费者(consumer/客户端)配置文件中采用相同的注册方式。配置方式类似,
2
配置语法为:
3
1)<dubbo:registry protocol="zookeeper/redis/multicast/dubbo" address="ip:port" client="zkclient/curator" username="root" password="1234">
4
<dubbo:parameter key="unicast"value="false"/>
5
</dubbo:registry>
6

7

8
2)也可以在address里带上协议类型:
9
<dubbo:registry address="zookeeper://121.42.183.206:2181?client=curator" />
10
<dubbo:registry address="redis://121.42.183.206:11111" />
11
<dubbo:registry address="multicast://224.5.6.7:9999?unicast=false" />
12
<dubbo:registry address="127.0.0.1:20880" />
13

14
建议使用2),便于在命令行替换。
15
zookeeper还支持cluster,多个地址可以用英文逗号符号分隔.redis支持使用1主多从,但是配置到dubbo里时,provider/服务端应连接主redis,多个consumer/客户端可以分别连到从redis。
16

17
还支持自定义注册扩展,参见官方文档《http://dubbo.apache.org/books/dubbo-dev-book/impls/registry.html》

+ 24 - 0
ipu-service-demo/readme.md

@ -0,0 +1,24 @@
1
1。dubbo服务注册支持zookeeper、redis、multicast、simple和jvm,本地开发调试可以推荐使用single,服务器部署推荐使用zookeeper。具体说明见doc/《注册配置.md》
2
2。对于大量重复查询,建议使用服务缓存。具体说明见doc/《服务缓存.md》
3
3。尽量不要复用用于暴露服务的接口.一个接口有不同实现时,建议分组:
4
provider/服务端:
5
<dubbo:service group="feedback" interface="com.xxx.IndexService" />
6
<dubbo:service group="member" interface="com.xxx.IndexService" />
7
consumer/客户端:
8
<dubbo:reference id="feedbackIndexService" group="feedback" interface="com.xxx.IndexService" />
9
<dubbo:reference id="memberIndexService" group="member" interface="com.xxx.IndexService" />
10
4。本地做代码调试时,请在consumer/客户端的配置文件里配置合适的超时时间。配置方法:
11
<dubbo:consumer retries="0" timeout="20000"/>
12
5。建议通过jvm参数方式设置dubbo服务接口:
13
-Ddubbo.protocol.port="20880"
14
6.建议通过jvm参数方式设置dubbo服务ip:
15
-Ddubbo.protocol.host="10.1.1.1"
16
7。建议通过jvm参数方式设置dubbo注册方式及地址:
17
方式2修改:
18
-Ddubbo.registry.address="multicast://224.5.6.7:9999"
19
方式1修改:
20
-Ddubbo.registry.protocol="multicast"
21
-Ddubbo.registry.address="224.5.6.7:9999"
22
。。。
23

24
方式1、方式2参见doc/《注册配置.md》

+ 3 - 3
ipu-service-demo/src/test/java/com/ai/ipu/service/demo/impl/EchoServiceTest.java

@ -20,13 +20,13 @@ public class EchoServiceTest extends TestCase{
20 20
    /**
21 21
     * @author ThinkPad@asiainfo.com
22 22
     * @title: testEchoService
23
     * @desc: 回声测试可用性
23
     * @desc: 回声测试可用性,回声测试用于检测服务是否可用,用于监控
24 24
     */
25 25
    public void testEchoService() {
26 26
        // TODO Auto-generated method stub
27
        EchoService echoService = (EchoService)context.getBean("demoService"); 
27
        EchoService echoService = (EchoService)context.getBean("bizService"); 
28 28
        Object status = echoService.$echo("OK");
29
        System.out.println("demoService的服务状态:" + status);
29
        System.out.println("bizService的服务状态:" + status);
30 30
        assert(status.equals("OK"));
31 31
    }
32 32
}

+ 2 - 2
ipu-service-demo/src/test/resources/dubbo-consumer-simple.xml

@ -30,9 +30,9 @@
30 30
	<!-- 服务拦截 -->
31 31
	<bean id="serviceInterceptor" class="com.ai.ipu.service.demo.interceptor.ServiceInterceptor" />
32 32
	<dubbo:reference id="bizInterceptService" interface="com.ai.ipu.service.demo.IBizService">
33
		<dubbo:method name="queryUserInfo" oninvoke="serviceInterceptor.onInvoke"
33
		<dubbo:method name="queryUserInfo" 
34 34
			onreturn="serviceInterceptor.onReturn" />
35
		<dubbo:method name="triggerException" oninvoke="serviceInterceptor.onInvoke"
35
		<dubbo:method name="triggerException" 
36 36
			onthrow="serviceInterceptor.onThrow" async="true" />
37 37
	</dubbo:reference>
38 38
	<!-- 服务存根 -->