diff --git a/Chapter9-2-2/compute-service/compute-api-server/pom.xml b/Chapter9-2-2/compute-service/compute-api-server/pom.xml new file mode 100644 index 0000000..7a0b498 --- /dev/null +++ b/Chapter9-2-2/compute-service/compute-api-server/pom.xml @@ -0,0 +1,93 @@ + + + 4.0.0 + + com.didispace + compute-api-server + 1.0.0 + jar + + compute-api-server + Spring Boot project + + + org.springframework.boot + spring-boot-starter-parent + 1.3.2.RELEASE + + + + + UTF-8 + 1.8 + + + + + + + org.springframework.boot + spring-boot-starter + + + + org.springframework.boot + spring-boot-starter-test + test + + + + + com.didispace + compute-api + 1.0-SNAPSHOT + + + + + com.alibaba + dubbo + 2.5.3 + + + spring + org.springframework + + + + + + org.apache.zookeeper + zookeeper + 3.4.6 + + + org.slf4j + slf4j-log4j12 + + + log4j + log4j + + + + + + com.github.sgroschupf + zkclient + 0.1 + + + + + + + + org.springframework.boot + spring-boot-maven-plugin + + + + + \ No newline at end of file diff --git a/Chapter9-2-2/compute-service/compute-api-server/src/main/java/com/didispace/Application.java b/Chapter9-2-2/compute-service/compute-api-server/src/main/java/com/didispace/Application.java new file mode 100644 index 0000000..4742e52 --- /dev/null +++ b/Chapter9-2-2/compute-service/compute-api-server/src/main/java/com/didispace/Application.java @@ -0,0 +1,30 @@ +package com.didispace; + +import org.apache.log4j.Logger; +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.context.ApplicationContext; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.ImportResource; + +import java.util.concurrent.CountDownLatch; + +@SpringBootApplication +@ImportResource({"classpath:dubbo.xml"}) +public class Application { + + private static final Logger logger = Logger.getLogger(Application.class); + + @Bean + public CountDownLatch closeLatch() { + return new CountDownLatch(1); + } + + public static void main(String[] args) throws InterruptedException { + ApplicationContext ctx = SpringApplication.run(Application.class, args); + logger.info("项目启动!"); + CountDownLatch closeLatch = ctx.getBean(CountDownLatch.class); + closeLatch.await(); + } + +} diff --git a/Chapter9-2-2/compute-service/compute-api-server/src/main/java/com/didispace/service/impl/ComputeServiceImpl.java b/Chapter9-2-2/compute-service/compute-api-server/src/main/java/com/didispace/service/impl/ComputeServiceImpl.java new file mode 100644 index 0000000..3027859 --- /dev/null +++ b/Chapter9-2-2/compute-service/compute-api-server/src/main/java/com/didispace/service/impl/ComputeServiceImpl.java @@ -0,0 +1,15 @@ +package com.didispace.service.impl; + +import com.didispace.service.ComputeService; + +/** + * Created by zhaiyc on 2016/7/14. + */ +public class ComputeServiceImpl implements ComputeService { + + @Override + public Integer add(int a, int b) { + return a + b; + } + +} diff --git a/Chapter9-2-2/compute-service/compute-api-server/src/main/resources/application.properties b/Chapter9-2-2/compute-service/compute-api-server/src/main/resources/application.properties new file mode 100644 index 0000000..27fa322 --- /dev/null +++ b/Chapter9-2-2/compute-service/compute-api-server/src/main/resources/application.properties @@ -0,0 +1,4 @@ +#ZooKeeper +dubbo.registry.address=localhost:2181 + +logging.level.root=DEBUG \ No newline at end of file diff --git a/Chapter9-2-2/compute-service/compute-api-server/src/main/resources/dubbo.xml b/Chapter9-2-2/compute-service/compute-api-server/src/main/resources/dubbo.xml new file mode 100644 index 0000000..02491d7 --- /dev/null +++ b/Chapter9-2-2/compute-service/compute-api-server/src/main/resources/dubbo.xml @@ -0,0 +1,24 @@ + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/Chapter9-2-2/compute-service/compute-api-server/src/test/java/com/didispace/ApplicationTests.java b/Chapter9-2-2/compute-service/compute-api-server/src/test/java/com/didispace/ApplicationTests.java new file mode 100644 index 0000000..3ee6230 --- /dev/null +++ b/Chapter9-2-2/compute-service/compute-api-server/src/test/java/com/didispace/ApplicationTests.java @@ -0,0 +1,22 @@ +package com.didispace; + +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.boot.test.SpringApplicationConfiguration; +import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; + + +@RunWith(SpringJUnit4ClassRunner.class) +@SpringApplicationConfiguration(classes = Application.class) +public class ApplicationTests { + + @Before + public void setUp() throws Exception { + } + + @Test + public void getHello() throws Exception { + } + +} diff --git a/Chapter9-2-2/compute-service/compute-api/pom.xml b/Chapter9-2-2/compute-service/compute-api/pom.xml new file mode 100644 index 0000000..0a2049c --- /dev/null +++ b/Chapter9-2-2/compute-service/compute-api/pom.xml @@ -0,0 +1,17 @@ + + + + 4.0.0 + + + com.didispace + compute-service + 1.0-SNAPSHOT + + + compute-api + compute-api + jar + + \ No newline at end of file diff --git a/Chapter9-2-2/compute-service/compute-api/src/main/java/com/didispace/service/ComputeService.java b/Chapter9-2-2/compute-service/compute-api/src/main/java/com/didispace/service/ComputeService.java new file mode 100644 index 0000000..327ab16 --- /dev/null +++ b/Chapter9-2-2/compute-service/compute-api/src/main/java/com/didispace/service/ComputeService.java @@ -0,0 +1,10 @@ +package com.didispace.service; + +/** + * Created by zhaiyc on 2016/7/14. + */ +public interface ComputeService { + + Integer add(int a, int b); + +} diff --git a/Chapter9-2-2/compute-service/compute-api/src/main/java/com/didispace/service/impl/ComputeServiceImpl.java b/Chapter9-2-2/compute-service/compute-api/src/main/java/com/didispace/service/impl/ComputeServiceImpl.java new file mode 100644 index 0000000..3027859 --- /dev/null +++ b/Chapter9-2-2/compute-service/compute-api/src/main/java/com/didispace/service/impl/ComputeServiceImpl.java @@ -0,0 +1,15 @@ +package com.didispace.service.impl; + +import com.didispace.service.ComputeService; + +/** + * Created by zhaiyc on 2016/7/14. + */ +public class ComputeServiceImpl implements ComputeService { + + @Override + public Integer add(int a, int b) { + return a + b; + } + +} diff --git a/Chapter9-2-2/compute-service/pom.xml b/Chapter9-2-2/compute-service/pom.xml new file mode 100644 index 0000000..3d8d6c9 --- /dev/null +++ b/Chapter9-2-2/compute-service/pom.xml @@ -0,0 +1,26 @@ + + + + 4.0.0 + + com.didispace + compute-service + pom + 1.0-SNAPSHOT + + + compute-api + compute-api-server + + + + true + UTF-8 + 1.7 + 1.7 + 1.7 + + + + \ No newline at end of file diff --git a/Chapter9-2-2/consumer/pom.xml b/Chapter9-2-2/consumer/pom.xml new file mode 100644 index 0000000..e3630d2 --- /dev/null +++ b/Chapter9-2-2/consumer/pom.xml @@ -0,0 +1,95 @@ + + + 4.0.0 + + com.didispace + consumer + 1.0.0 + jar + + consumer + Spring Boot project + + + org.springframework.boot + spring-boot-starter-parent + 1.3.2.RELEASE + + + + + UTF-8 + 1.8 + + + + + org.springframework.boot + spring-boot-starter + + + + org.springframework.boot + spring-boot-starter-web + + + + org.springframework.boot + spring-boot-starter-test + test + + + + + com.didispace + compute-api + 1.0-SNAPSHOT + + + + com.alibaba + dubbo + 2.5.3 + + + spring + org.springframework + + + + + + org.apache.zookeeper + zookeeper + 3.4.6 + + + org.slf4j + slf4j-log4j12 + + + log4j + log4j + + + + + + com.github.sgroschupf + zkclient + 0.1 + + + + + + + + org.springframework.boot + spring-boot-maven-plugin + + + + + \ No newline at end of file diff --git a/Chapter9-2-2/consumer/src/main/java/com/didispace/Application.java b/Chapter9-2-2/consumer/src/main/java/com/didispace/Application.java new file mode 100644 index 0000000..945f495 --- /dev/null +++ b/Chapter9-2-2/consumer/src/main/java/com/didispace/Application.java @@ -0,0 +1,15 @@ +package com.didispace; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.context.annotation.ImportResource; + +@SpringBootApplication +@ImportResource({"classpath:dubbo.xml"}) +public class Application { + + public static void main(String[] args) throws InterruptedException { + SpringApplication.run(Application.class, args); + } + +} diff --git a/Chapter9-2-2/consumer/src/main/resources/application.properties b/Chapter9-2-2/consumer/src/main/resources/application.properties new file mode 100644 index 0000000..714b908 --- /dev/null +++ b/Chapter9-2-2/consumer/src/main/resources/application.properties @@ -0,0 +1,5 @@ +#ZooKeeper +dubbo.registry.address=localhost:2181 + + +logging.level.root=INFO \ No newline at end of file diff --git a/Chapter9-2-2/consumer/src/main/resources/dubbo.xml b/Chapter9-2-2/consumer/src/main/resources/dubbo.xml new file mode 100644 index 0000000..4760bfa --- /dev/null +++ b/Chapter9-2-2/consumer/src/main/resources/dubbo.xml @@ -0,0 +1,18 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/Chapter9-2-2/consumer/src/test/java/com/didispace/ApplicationTests.java b/Chapter9-2-2/consumer/src/test/java/com/didispace/ApplicationTests.java new file mode 100644 index 0000000..4f5c3d5 --- /dev/null +++ b/Chapter9-2-2/consumer/src/test/java/com/didispace/ApplicationTests.java @@ -0,0 +1,24 @@ +package com.didispace; + +import com.didispace.service.ComputeService; +import org.junit.Assert; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.SpringApplicationConfiguration; +import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; + + +@RunWith(SpringJUnit4ClassRunner.class) +@SpringApplicationConfiguration(classes = Application.class) +public class ApplicationTests { + + @Autowired + private ComputeService computeService; + + @Test + public void testAdd() throws Exception { + Assert.assertEquals("compute-service:add", new Integer(3), computeService.add(1, 2)); + } + +}