huangbo %!s(int64=6) %!d(string=hace) años
padre
commit
e909d88cf5

+ 9 - 0
dubbo-example/dubbo-service-provider/dubbo-service-provider.eml

@ -0,0 +1,9 @@
1
<?xml version="1.0" encoding="UTF-8"?>
2
<component inheritJdk="true">
3
	<output-test url="file://$MODULE_DIR$/target/test-classes"/>
4
	<contentEntry url="file://$MODULE_DIR$">
5
		<testFolder url="file://$MODULE_DIR$/src/test/java"/>
6
		<testFolder url="file://$MODULE_DIR$/src/test/resources"/>
7
		<excludeFolder url="file://$MODULE_DIR$/target"/>
8
	</contentEntry>
9
</component>

+ 29 - 28
dubbo-example/dubbo-service-provider/pom.xml

@ -1,29 +1,30 @@
1
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
2
	xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
3
	<modelVersion>4.0.0</modelVersion>
4
	<parent>
5
		<groupId>com.ai.ipu.example</groupId>
6
		<artifactId>dubbo-example</artifactId>
7
		<version>1.0-SNAPSHOT</version>
8
	</parent>
9

10
	<artifactId>dubbo-service-provider</artifactId>
11
	<name>dubbo-service-provider</name>
12
	<description>dubbo服务提供者</description>
13
	
14
	<properties>
15
		<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
16
	</properties>
17

18
	<dependencies>
19
		<dependency>
20
			<groupId>junit</groupId>
21
			<artifactId>junit</artifactId>
22
			<scope>test</scope>
23
		</dependency>
24
		<dependency>
25
			<groupId>com.ai.ipu.server</groupId>
26
			<artifactId>ipu-service</artifactId>
27
		</dependency>
28
	</dependencies>
1
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
2
	xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
3
	<modelVersion>4.0.0</modelVersion>
4
	<parent>
5
		<groupId>com.ai.ipu.example</groupId>
6
		<artifactId>dubbo-example</artifactId>
7
		<version>1.0-SNAPSHOT</version>
8
	</parent>
9
10
	<artifactId>dubbo-service-provider</artifactId>
11
	<name>dubbo-service-provider</name>
12
	<description>dubbo服务提供者</description>
13
	
14
	<properties>
15
		<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
16
	</properties>
17
18
	<dependencies>
19
		<dependency>
20
			<groupId>com.ai.ipu.server</groupId>
21
			<artifactId>ipu-service</artifactId>
22
		</dependency>
23
24
		<dependency>
25
			<groupId>junit</groupId>
26
			<artifactId>junit</artifactId>
27
			<version>3.8.2</version>
28
		</dependency>
29
	</dependencies>
29 30
</project>

+ 17 - 17
dubbo-example/dubbo-service-provider/src/main/java/com/ai/ipu/dubbo/provider/DubboServiceProviderStart.java

@ -1,17 +1,17 @@
1
package com.ai.ipu.dubbo.provider;
2

3
import org.springframework.context.support.ClassPathXmlApplicationContext;
4

5
public class DubboServiceProviderStart {
6
    public final static String MODE = "simple";
7
    public final static String DUBBO_PROVIDER_CONFIG = "dubbo-provider-" + MODE + ".xml";
8
    public final static String DUBBO_CONSUMER_CONFIG = "dubbo-consumer-" + MODE + ".xml";
9
    
10
    @SuppressWarnings("resource")
11
    public static void main(String[] args) throws Exception {
12
        ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(
13
                new String[] {DUBBO_PROVIDER_CONFIG});
14
        context.start();
15
        System.in.read(); // press any key to exit
16
    }
17
}
1
package com.ai.ipu.dubbo.provider;
2
3
import org.springframework.context.support.ClassPathXmlApplicationContext;
4
5
public class DubboServiceProviderStart {
6
    public final static String MODE = "simple";
7
    public final static String DUBBO_PROVIDER_CONFIG = "dubbo-provider-" + MODE + ".xml";
8
    public final static String DUBBO_CONSUMER_CONFIG = "dubbo-consumer-" + MODE + ".xml";
9
    
10
    @SuppressWarnings("resource")
11
    public static void main(String[] args) throws Exception {
12
        ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(
13
                new String[] {DUBBO_PROVIDER_CONFIG});
14
        context.start();
15
        System.in.read(); // press any key to exit
16
    }
17
}

+ 6 - 6
dubbo-example/dubbo-service-provider/src/main/java/com/ai/ipu/dubbo/provider/HelloService.java

@ -1,6 +1,6 @@
1
package com.ai.ipu.dubbo.provider;
2

3
public interface HelloService {
4
    
5
    public String hello(String name);
6
}
1
package com.ai.ipu.dubbo.provider;
2
3
public interface HelloService {
4
    
5
    public String hello(String name);
6
}

+ 10 - 10
dubbo-example/dubbo-service-provider/src/main/java/com/ai/ipu/dubbo/provider/impl/HelloServiceImpl.java

@ -1,10 +1,10 @@
1
package com.ai.ipu.dubbo.provider.impl;
2

3
import com.ai.ipu.dubbo.provider.HelloService;
4

5
public class HelloServiceImpl implements HelloService{
6

7
    public String hello(String name) {
8
        return "hello" + name;
9
    }
10
}
1
package com.ai.ipu.dubbo.provider.impl;
2
3
import com.ai.ipu.dubbo.provider.HelloService;
4
5
public class HelloServiceImpl implements HelloService{
6
7
    public String hello(String name) {
8
        return "hello" + name;
9
    }
10
}

+ 31 - 31
dubbo-example/dubbo-service-provider/src/main/resources/dubbo-provider-simple.xml

@ -1,32 +1,32 @@
1
<?xml version="1.0" encoding="UTF-8"?>
2
<beans xmlns="http://www.springframework.org/schema/beans"
3
	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4
	xmlns:dubbo="http://code.alibabatech.com/schema/dubbo"
5
	xsi:schemaLocation="http://www.springframework.org/schema/beans
6
	http://www.springframework.org/schema/beans/spring-beans.xsd
7
	http://code.alibabatech.com/schema/dubbo 
8
	http://code.alibabatech.com/schema/dubbo/dubbo.xsd">
9
    <!-- 全局配置 start=========================== -->
10
    <dubbo:application name="ipu-service-demo" logger="log4j"> <!-- 日志适配 -->
11
    	<dubbo:parameter key="dump.directory" value="/tmp" /> <!-- 线程栈自动dump -->
12
    </dubbo:application>
13
    <!-- 过滤器配置,服务延迟暴露 -->
14
    <dubbo:provider filter="IpuDubboServiceGlobalFilter" delay="-1" /><!-- server="netty4"  -->
15
    <!-- 服务协议 -->
16
    <dubbo:protocol name="dubbo" port="20880"/>
17
    <!-- 广播的方式注册 -->
18
    <dubbo:registry address="127.0.0.1:20880"/>
19
    <!-- 提供simple注册中心 -->
20
    <dubbo:service interface="com.alibaba.dubbo.registry.RegistryService" ref="registryService" registry="N/A" ondisconnect="disconnect" callbacks="1000">
21
        <dubbo:method name="subscribe"><dubbo:argument index="1" callback="true" /></dubbo:method>
22
        <dubbo:method name="unsubscribe"><dubbo:argument index="1" callback="false" /></dubbo:method>
23
    </dubbo:service>
24
    <!-- 简单注册中心实现,可自行扩展实现集群和状态同步 -->
25
    <bean id="registryService" class="com.alibaba.dubbo.registry.simple.SimpleRegistryService" />
26
    <!-- 全局配置 end=========================== -->
27
    
28
    <!-- 服务注册配置 start=========================== -->
29
    <dubbo:service interface="com.ai.ipu.dubbo.provider.HelloService" ref="helloService" token="true"/>
30
    <bean id="helloService" class="com.ai.ipu.dubbo.provider.impl.HelloServiceImpl"/>
31
    <!-- 服务注册配置 end =========================== -->
1
<?xml version="1.0" encoding="UTF-8"?>
2
<beans xmlns="http://www.springframework.org/schema/beans"
3
	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4
	xmlns:dubbo="http://code.alibabatech.com/schema/dubbo"
5
	xsi:schemaLocation="http://www.springframework.org/schema/beans
6
	http://www.springframework.org/schema/beans/spring-beans.xsd
7
	http://code.alibabatech.com/schema/dubbo 
8
	http://code.alibabatech.com/schema/dubbo/dubbo.xsd">
9
    <!-- 全局配置 start=========================== -->
10
    <dubbo:application name="ipu-service-demo" logger="log4j"> <!-- 日志适配 -->
11
    	<dubbo:parameter key="dump.directory" value="/tmp" /> <!-- 线程栈自动dump -->
12
    </dubbo:application>
13
    <!-- 过滤器配置,服务延迟暴露 -->
14
    <dubbo:provider filter="IpuDubboServiceGlobalFilter" delay="-1" /><!-- server="netty4"  -->
15
    <!-- 服务协议 -->
16
    <dubbo:protocol name="dubbo" port="20880"/>
17
    <!-- 广播的方式注册 -->
18
    <dubbo:registry address="127.0.0.1:20880"/>
19
    <!-- 提供simple注册中心 -->
20
    <dubbo:service interface="com.alibaba.dubbo.registry.RegistryService" ref="registryService" registry="N/A" ondisconnect="disconnect" callbacks="1000">
21
        <dubbo:method name="subscribe"><dubbo:argument index="1" callback="true" /></dubbo:method>
22
        <dubbo:method name="unsubscribe"><dubbo:argument index="1" callback="false" /></dubbo:method>
23
    </dubbo:service>
24
    <!-- 简单注册中心实现,可自行扩展实现集群和状态同步 -->
25
    <bean id="registryService" class="com.alibaba.dubbo.registry.simple.SimpleRegistryService" />
26
    <!-- 全局配置 end=========================== -->
27
    
28
    <!-- 服务注册配置 start=========================== -->
29
    <dubbo:service interface="com.ai.ipu.dubbo.provider.HelloService" ref="helloService" token="true"/>
30
    <bean id="helloService" class="com.ai.ipu.dubbo.provider.impl.HelloServiceImpl"/>
31
    <!-- 服务注册配置 end =========================== -->
32 32
</beans>

+ 23 - 24
dubbo-example/dubbo-service-provider/src/test/java/com/ai/ipu/dubbo/provider/HelloServiceTest.java

@ -1,24 +1,23 @@
1
package com.ai.ipu.dubbo.provider;
2

3
import junit.framework.TestCase;
4

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

7
public class HelloServiceTest extends TestCase {
8
    private ClassPathXmlApplicationContext context;
9

10
    @Override
11
    protected void setUp() throws Exception {
12
        // TODO Auto-generated method stub
13
        context = new ClassPathXmlApplicationContext(new String[] { DubboServiceProviderStart.DUBBO_CONSUMER_CONFIG });
14
        context.start();
15
    }
16
    
17

18
    public void testHello() {
19
        // TODO Auto-generated method stub
20
        HelloService helloService = (HelloService)context.getBean("helloService"); // 获取远程服务代理
21
        String result = helloService.hello("测试名称"); // 执行远程方法
22
        System.out.println(result); // 显示调用结果
23
    }
24
}
1
package com.ai.ipu.dubbo.provider;
2
3
4
import org.springframework.context.support.ClassPathXmlApplicationContext;
5
6
public class HelloServiceTest extends TestCase {
7
    private ClassPathXmlApplicationContext context;
8
9
    @Override
10
    protected void setUp() throws Exception {
11
        // TODO Auto-generated method stub
12
        context = new ClassPathXmlApplicationContext(new String[] { DubboServiceProviderStart.DUBBO_CONSUMER_CONFIG });
13
        context.start();
14
    }
15
    
16
17
    public void testHello() {
18
        // TODO Auto-generated method stub
19
        HelloService helloService = (HelloService)context.getBean("helloService"); // 获取远程服务代理
20
        String result = helloService.hello("测试名称"); // 执行远程方法
21
        System.out.println(result); // 显示调用结果
22
    }
23
}

+ 18 - 18
dubbo-example/dubbo-service-provider/src/test/resources/dubbo-consumer-simple.xml

@ -1,19 +1,19 @@
1
<?xml version="1.0" encoding="UTF-8"?>
2
<beans xmlns="http://www.springframework.org/schema/beans"
3
	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:dubbo="http://code.alibabatech.com/schema/dubbo"
4
	xsi:schemaLocation="http://www.springframework.org/schema/beans
5
	http://www.springframework.org/schema/beans/spring-beans.xsd
6
	http://code.alibabatech.com/schema/dubbo 
7
	http://code.alibabatech.com/schema/dubbo/dubbo.xsd">
8
	<!-- 全局配置 start=========================== -->
9
	<dubbo:application name="ipu-service-demo" />
10
	<!-- 关闭重试,延长超时 -->
11
	<dubbo:consumer retries="0" timeout="2000"/>	<!-- client="netty4" -->
12
	<dubbo:registry address="127.0.0.1:20880" />
13
	<!-- 全局配置 end=========================== -->
14

15
	<!-- 服务注册配置 start=========================== -->
16
	<dubbo:reference id="helloService"
17
		interface="com.ai.ipu.dubbo.provider.HelloService" />
18
	<!-- 服务注册配置 end =========================== -->
1
<?xml version="1.0" encoding="UTF-8"?>
2
<beans xmlns="http://www.springframework.org/schema/beans"
3
	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:dubbo="http://code.alibabatech.com/schema/dubbo"
4
	xsi:schemaLocation="http://www.springframework.org/schema/beans
5
	http://www.springframework.org/schema/beans/spring-beans.xsd
6
	http://code.alibabatech.com/schema/dubbo 
7
	http://code.alibabatech.com/schema/dubbo/dubbo.xsd">
8
	<!-- 全局配置 start=========================== -->
9
	<dubbo:application name="ipu-service-demo" />
10
	<!-- 关闭重试,延长超时 -->
11
	<dubbo:consumer retries="0" timeout="2000"/>	<!-- client="netty4" -->
12
	<dubbo:registry address="127.0.0.1:20880" />
13
	<!-- 全局配置 end=========================== -->
14
15
	<!-- 服务注册配置 start=========================== -->
16
	<dubbo:reference id="helloService"
17
		interface="com.ai.ipu.dubbo.provider.HelloService" />
18
	<!-- 服务注册配置 end =========================== -->
19 19
</beans>