浏览代码

案例工程代码结构调整

huangbo 7 年之前
父节点
当前提交
0189ab35d2

+ 6 - 0
ipu-service-demo/src/main/java/com/ai/ipu/service/demo/IAsyncService.java

@ -2,6 +2,12 @@ package com.ai.ipu.service.demo;
2 2

3 3
import com.ailk.common.data.IData;
4 4

5
/**
6
 * @author huangbo@asiainfo.com
7
 * @team IPU
8
 * @date 2018年3月6日下午3:46:58
9
 * @desc 服务异步调用案例
10
 */
5 11
public interface IAsyncService {
6 12

7 13
    public IData findFoo() throws Exception;

+ 19 - 0
ipu-service-demo/src/main/java/com/ai/ipu/service/demo/IBizService.java

@ -0,0 +1,19 @@
1
package com.ai.ipu.service.demo;
2

3
import com.ailk.common.data.IData;
4

5
/**
6
 * @author huangbo@asiainfo.com
7
 * @team IPU
8
 * @date 2018年3月6日下午3:41:56
9
 * @desc 业务服务调用案例
10
 */
11
public interface IBizService {
12
    
13
    /**
14
     * @author huangbo@asiainfo.com
15
     * @title: queryUserInfo
16
     * @desc: 用户信息查询
17
     */
18
    public IData queryUserInfo(IData param);
19
}

+ 7 - 3
ipu-service-demo/src/main/java/com/ai/ipu/service/demo/IDemoService.java

@ -2,10 +2,14 @@ package com.ai.ipu.service.demo;
2 2

3 3
import com.ailk.common.data.IData;
4 4

5
public interface IDemoService {
5
/**
6
 * @author huangbo@asiainfo.com
7
 * @team IPU
8
 * @date 2018年3月6日下午3:43:56
9
 * @desc 获取服务上下文案例
10
 */
11
public interface IContextService {
6 12

7
    public IData queryUserInfo(IData param);
8
    
9 13
    /**
10 14
     * @author huangbo@asiainfo.com
11 15
     * @title: takeRpcContext

+ 25 - 0
ipu-service-demo/src/main/java/com/ai/ipu/service/demo/impl/BizService.java

@ -0,0 +1,25 @@
1
package com.ai.ipu.service.demo.impl;
2

3
import com.ai.ipu.service.demo.IBizService;
4
import com.ailk.common.data.IData;
5
import com.ailk.common.data.impl.DataMap;
6

7
/**
8
 * @author huangbo@asiainfo.com
9
 * @team IPU
10
 * @date 2018年3月6日下午3:43:13
11
 * @desc TODO(描述类作用)
12
 */
13
public class BizService implements IBizService{
14

15
    public IData queryUserInfo(IData param) {
16
        // TODO Auto-generated method stub
17
        /*校验参数*/
18
        /*参数准备*/
19
        /*获取结果*/
20
        IData result = new DataMap();
21
        result.put("param", param);
22
        result.put("msg", "成功返回结果!");
23
        return result;
24
    }
25
}

+ 2 - 13
ipu-service-demo/src/main/java/com/ai/ipu/service/demo/impl/DemoService.java

@ -2,23 +2,12 @@ package com.ai.ipu.service.demo.impl;
2 2

3 3
import java.util.Map;
4 4

5
import com.ai.ipu.service.demo.IDemoService;
5
import com.ai.ipu.service.demo.IContextService;
6 6
import com.ailk.common.data.IData;
7 7
import com.ailk.common.data.impl.DataMap;
8 8
import com.alibaba.dubbo.rpc.RpcContext;
9 9

10
public class DemoService implements IDemoService{
11

12
    public IData queryUserInfo(IData param) {
13
        // TODO Auto-generated method stub
14
        /*校验参数*/
15
        /*参数准备*/
16
        /*获取结果*/
17
        IData result = new DataMap();
18
        result.put("param", param);
19
        result.put("msg", "成功返回结果!");
20
        return result;
21
    }
10
public class ContextService implements IContextService{
22 11

23 12
    /**
24 13
     * 获取上下文信息

+ 4 - 2
ipu-service-demo/src/main/resources/dubbo-provider-mult.xml

@ -16,8 +16,10 @@
16 16
    <!-- 全局配置 end=========================== -->
17 17
    
18 18
    <!-- 服务注册配置 start=========================== -->
19
    <dubbo:service interface="com.ai.ipu.service.demo.IDemoService" ref="demoService"/>
20
    <bean id="demoService" class="com.ai.ipu.service.demo.impl.DemoService"/>
19
    <dubbo:service interface="com.ai.ipu.service.demo.IBizService" ref="bizService"/>
20
    <bean id="bizService" class="com.ai.ipu.service.demo.impl.BizService"/>
21
    <dubbo:service interface="com.ai.ipu.service.demo.IContextService" ref="contextService"/>
22
    <bean id="contextService" class="com.ai.ipu.service.demo.impl.ContextService"/>
21 23
    <dubbo:service interface="com.ai.ipu.service.demo.IAsyncService" ref="asyncService"/>
22 24
    <bean id="asyncService" class="com.ai.ipu.service.demo.impl.AsyncService"/>
23 25
    <!-- 服务注册配置 end =========================== -->

+ 4 - 2
ipu-service-demo/src/main/resources/dubbo-provider-simple.xml

@ -23,8 +23,10 @@
23 23
    <!-- 全局配置 end=========================== -->
24 24
    
25 25
    <!-- 服务注册配置 start=========================== -->
26
    <dubbo:service interface="com.ai.ipu.service.demo.IDemoService" ref="demoService"/>
27
    <bean id="demoService" class="com.ai.ipu.service.demo.impl.DemoService"/>
26
    <dubbo:service interface="com.ai.ipu.service.demo.IBizService" ref="bizService"/>
27
    <bean id="bizService" class="com.ai.ipu.service.demo.impl.BizService"/>
28
    <dubbo:service interface="com.ai.ipu.service.demo.IContextService" ref="contextService"/>
29
    <bean id="contextService" class="com.ai.ipu.service.demo.impl.ContextService"/>
28 30
    <dubbo:service interface="com.ai.ipu.service.demo.IAsyncService" ref="asyncService"/>
29 31
    <bean id="asyncService" class="com.ai.ipu.service.demo.impl.AsyncService"/>
30 32
    <!-- 服务注册配置 end =========================== -->

+ 4 - 2
ipu-service-demo/src/main/resources/dubbo-provider-zoo.xml

@ -21,8 +21,10 @@
21 21
    <!-- 全局配置 end=========================== -->
22 22
    
23 23
    <!-- 服务注册配置 start=========================== -->
24
    <dubbo:service interface="com.ai.ipu.service.demo.IDemoService" ref="demoService"/>
25
    <bean id="demoService" class="com.ai.ipu.service.demo.impl.DemoService"/>
24
    <dubbo:service interface="com.ai.ipu.service.demo.IBizService" ref="bizService"/>
25
    <bean id="bizService" class="com.ai.ipu.service.demo.impl.BizService"/>
26
    <dubbo:service interface="com.ai.ipu.service.demo.IContextService" ref="contextService"/>
27
    <bean id="contextService" class="com.ai.ipu.service.demo.impl.ContextService"/>
26 28
    <dubbo:service interface="com.ai.ipu.service.demo.IAsyncService" ref="asyncService"/>
27 29
    <bean id="asyncService" class="com.ai.ipu.service.demo.impl.AsyncService"/>
28 30
    <!-- 服务注册配置 end =========================== -->

+ 29 - 0
ipu-service-demo/src/test/java/com/ai/ipu/service/demo/impl/BizServiceTest.java

@ -0,0 +1,29 @@
1
package com.ai.ipu.service.demo.impl;
2

3
import junit.framework.TestCase;
4

5
import org.springframework.context.support.ClassPathXmlApplicationContext;
6

7
import com.ai.ipu.service.DubboServiceStart;
8
import com.ai.ipu.service.demo.IBizService;
9
import com.ailk.common.data.IData;
10
import com.ailk.common.data.impl.DataMap;
11

12
public class BizServiceTest extends TestCase {
13
    private ClassPathXmlApplicationContext context;
14

15
    @Override
16
    protected void setUp() throws Exception {
17
        // TODO Auto-generated method stub
18
        context = new ClassPathXmlApplicationContext(new String[] { DubboServiceStart.DUBBO_CONSUMER_CONFIG });
19
        context.start();
20
    }
21
    
22

23
    public void testQueryUserInfo() {
24
        // TODO Auto-generated method stub
25
        IBizService contextService = (IBizService)context.getBean("bizService"); // 获取远程服务代理
26
        IData result = contextService.queryUserInfo(new DataMap()); // 执行远程方法
27
        System.out.println(result); // 显示调用结果
28
    }
29
}

+ 4 - 11
ipu-service-demo/src/test/java/com/ai/ipu/service/demo/impl/DemoServiceTest.java

@ -5,13 +5,13 @@ import junit.framework.TestCase;
5 5
import org.springframework.context.support.ClassPathXmlApplicationContext;
6 6

7 7
import com.ai.ipu.service.DubboServiceStart;
8
import com.ai.ipu.service.demo.IDemoService;
8
import com.ai.ipu.service.demo.IContextService;
9 9
import com.ai.ipu.service.dubbo.DubboContextData;
10 10
import com.ailk.common.data.IData;
11 11
import com.ailk.common.data.impl.DataMap;
12 12
import com.alibaba.dubbo.rpc.RpcContext;
13 13

14
public class DemoServiceTest extends TestCase{
14
public class ContextServiceTest extends TestCase{
15 15
    private ClassPathXmlApplicationContext context;
16 16
    
17 17
    @Override
@ -21,13 +21,6 @@ public class DemoServiceTest extends TestCase{
21 21
        context.start();
22 22
    }
23 23
    
24
    public void testQueryUserInfo() {
25
        // TODO Auto-generated method stub
26
        IDemoService demoService = (IDemoService)context.getBean("demoService"); // 获取远程服务代理
27
        IData result = demoService.queryUserInfo(new DataMap()); // 执行远程方法
28
        System.out.println(result); // 显示调用结果
29
    }
30
    
31 24
    /**
32 25
     * @author huangbo@asiainfo.com
33 26
     * @title: takeRpcContext
@ -40,8 +33,8 @@ public class DemoServiceTest extends TestCase{
40 33
        DubboContextData contextData = new DubboContextData();
41 34
        contextData.put("context_info", "上下文信息");
42 35
        RpcContext.getContext().setAttachments(contextData);
43
        IDemoService demoService = (IDemoService)context.getBean("demoService"); // 获取远程服务代理
44
        IData result = demoService.takeRpcContext(); // 执行远程方法
36
        IContextService contextService = (IContextService)context.getBean("contextService"); // 获取远程服务代理
37
        IData result = contextService.takeRpcContext(); // 执行远程方法
45 38
        System.out.println(result); // 显示调用结果
46 39

47 40
    }

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

@ -13,7 +13,8 @@
13 13
    <!-- 全局配置 end=========================== -->
14 14
	
15 15
	<!-- 服务注册配置 start=========================== -->
16
	<dubbo:reference id="demoService" interface="com.ai.ipu.service.demo.IDemoService" />
16
    <dubbo:reference id="bizService" interface="com.ai.ipu.service.demo.IBizService" />
17
	<dubbo:reference id="contextService" interface="com.ai.ipu.service.demo.IContextService" />
17 18
	<!-- 两级超时配置 -->
18 19
	<dubbo:reference id="asyncService" interface="com.ai.ipu.service.demo.IAsyncService" timeout="3000" >
19 20
		<dubbo:method name="findFoo" async="true" timeout="3500"/>

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

@ -12,7 +12,8 @@
12 12
	<!-- 全局配置 end=========================== -->
13 13
	
14 14
	<!-- 服务注册配置 start=========================== -->
15
	<dubbo:reference id="demoService" interface="com.ai.ipu.service.demo.IDemoService" />
15
	<dubbo:reference id="bizService" interface="com.ai.ipu.service.demo.IBizService" />
16
	<dubbo:reference id="contextService" interface="com.ai.ipu.service.demo.IContextService" />
16 17
	<!-- 两级超时配置 -->
17 18
	<dubbo:reference id="asyncService" interface="com.ai.ipu.service.demo.IAsyncService" timeout="3000" >
18 19
		<dubbo:method name="findFoo" async="true" timeout="3500"/>

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

@ -13,10 +13,11 @@
13 13
	<!-- 全局配置 end=========================== -->
14 14
	
15 15
	<!-- 开发阶段可使用直连模式 -->
16
	<!-- <dubbo:reference id="demoService" interface="com.ai.ipu.service.demo.IDemoService" url="dubbo://localhost:20880"/> -->
16
	<!-- <dubbo:reference id="demoService" interface="com.ai.ipu.service.demo.IContextService" url="dubbo://localhost:20880"/> -->
17 17
	
18 18
	<!-- 服务注册配置 start=========================== -->
19
	<dubbo:reference id="demoService" interface="com.ai.ipu.service.demo.IDemoService" />
19
	<dubbo:reference id="bizService" interface="com.ai.ipu.service.demo.IBizService" />
20
	<dubbo:reference id="contextService" interface="com.ai.ipu.service.demo.IContextService" />
20 21
	<!-- 两级超时配置 -->
21 22
	<dubbo:reference id="asyncService" interface="com.ai.ipu.service.demo.IAsyncService" timeout="3000" >
22 23
		<dubbo:method name="findFoo" async="true" timeout="3500"/>