diff --git a/README.md b/README.md index d6e47d1b31493627ecf6e83b366a136befe49f2b..3d5ac284b5e95f6d4654fd979f750002d9a5d0e6 100644 --- a/README.md +++ b/README.md @@ -15,5 +15,7 @@ rocketmq-console rocketmq管理后台
whatsmars-rpc 常用rpc
whatsmars-spring-boot springboot果然很方便
whatsmars-redis Cache Service & Redis Cluster
+whatsmars-motan weibo分布式RPC框架 demo server
+whatsmars-motan-demo weibo分布式RPC框架 demo server&client
# 技术生态 java.toutiao.im \ No newline at end of file diff --git a/pom.xml b/pom.xml index 6adea3b7de44b43b56b6e2581a7d2f346078f0bc..4196c7e99694e70b2fc15ee33c7bbd57be081eab 100644 --- a/pom.xml +++ b/pom.xml @@ -29,6 +29,7 @@ rocketmq-console whatsmars-redis whatsmars-motan + whatsmars-motan-demo diff --git a/whatsmars-motan-demo/README.md b/whatsmars-motan-demo/README.md new file mode 100644 index 0000000000000000000000000000000000000000..74ef763e09d8c67887db6be43749fed31d9a9c64 --- /dev/null +++ b/whatsmars-motan-demo/README.md @@ -0,0 +1 @@ +先启动zookeeper(port:2181)和whatsmars-motan \ No newline at end of file diff --git a/whatsmars-motan-demo/pom.xml b/whatsmars-motan-demo/pom.xml new file mode 100644 index 0000000000000000000000000000000000000000..caf2fedf54cce2fe209d0518016ce2b852abe6c4 --- /dev/null +++ b/whatsmars-motan-demo/pom.xml @@ -0,0 +1,105 @@ + + + 4.0.0 + + whatsmars-motan-demo + + + + com.itlong.motan.demo.App + 0.1.1 + + + + org.springframework.boot + spring-boot-starter-parent + 1.5.2.RELEASE + + + + + org.springframework.boot + spring-boot-starter-web + + + + com.weibo + motan-core + ${motan.version} + + + com.weibo + motan-transport-netty + ${motan.version} + + + com.weibo + motan-registry-consul + ${motan.version} + + + com.weibo + motan-registry-zookeeper + ${motan.version} + + + + + com.weibo + motan-springsupport + ${motan.version} + + + + org.springframework.boot + whatsmars-motan + 1.5.2.RELEASE + + + + + ${project.artifactId} + + + src/main/resources + + true + + + + + + org.springframework.boot + spring-boot-maven-plugin + + + + org.springframework + springloaded + 1.2.6.RELEASE + + + + + + + + + + \ No newline at end of file diff --git a/whatsmars-motan-demo/src/main/java/com/itlong/motan/demo/App.java b/whatsmars-motan-demo/src/main/java/com/itlong/motan/demo/App.java new file mode 100644 index 0000000000000000000000000000000000000000..cb76baeb5385356f5724dad19926b8f9e62662c9 --- /dev/null +++ b/whatsmars-motan-demo/src/main/java/com/itlong/motan/demo/App.java @@ -0,0 +1,23 @@ +package com.itlong.motan.demo; + +import com.weibo.api.motan.common.MotanConstants; +import com.weibo.api.motan.util.MotanSwitcherUtil; +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.EnableAutoConfiguration; +import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.context.annotation.ImportResource; + +@SpringBootApplication +@EnableAutoConfiguration +// 注意:依赖包里满足条件的配置也会加载进来,这里以demo开头确保只加载本module下的配置 +@ImportResource(locations={"classpath*:spring/demo*.xml"}) +public class App { + + public static void main(String[] args) { + SpringApplication.run(App.class, args); + + MotanSwitcherUtil.setSwitcherValue(MotanConstants.REGISTRY_HEARTBEAT_SWITCHER, true); + System.out.println("server start..."); + } + +} \ No newline at end of file diff --git a/whatsmars-motan-demo/src/main/java/com/itlong/motan/demo/DemoCommandRunner.java b/whatsmars-motan-demo/src/main/java/com/itlong/motan/demo/DemoCommandRunner.java new file mode 100644 index 0000000000000000000000000000000000000000..0ce15e0a5ca53e2267520d0efb7f3b4cec8a4578 --- /dev/null +++ b/whatsmars-motan-demo/src/main/java/com/itlong/motan/demo/DemoCommandRunner.java @@ -0,0 +1,26 @@ +package com.itlong.motan.demo; + +import com.weibo.motan.demo.service.MotanDemoService; +import org.springframework.boot.CommandLineRunner; +import org.springframework.stereotype.Component; + +import javax.annotation.Resource; + +/** + * Created by javahongxi on 2017/6/30. + */ +@Component +public class DemoCommandRunner implements CommandLineRunner { + @Resource(name = "motanDemoService") + private MotanDemoService motanDemoService; + + @Override + public void run(String... strings) throws Exception { + for (int i = 0; i < Integer.MAX_VALUE; i++) { + System.out.println(motanDemoService.hello("motan" + i)); + Thread.sleep(500); + } + System.out.println("motan demo is finish."); + System.exit(0); + } +} diff --git a/whatsmars-motan-demo/src/main/java/com/itlong/motan/demo/DemoMotanService.java b/whatsmars-motan-demo/src/main/java/com/itlong/motan/demo/DemoMotanService.java new file mode 100644 index 0000000000000000000000000000000000000000..d6cc7be8c9a4182dc303a7c39cb78d850b6a081e --- /dev/null +++ b/whatsmars-motan-demo/src/main/java/com/itlong/motan/demo/DemoMotanService.java @@ -0,0 +1,10 @@ +/** + * Created by shenhongxi on 2017/3/27. + */ + +package com.itlong.motan.demo; + +public interface DemoMotanService { + String hello(String name); + +} diff --git a/whatsmars-spring-boot/src/main/java/com/itlong/whatsmars/spring/boot/motan/MotanDemoServiceImpl.java b/whatsmars-motan-demo/src/main/java/com/itlong/motan/demo/DemoMotanServiceImpl.java similarity index 60% rename from whatsmars-spring-boot/src/main/java/com/itlong/whatsmars/spring/boot/motan/MotanDemoServiceImpl.java rename to whatsmars-motan-demo/src/main/java/com/itlong/motan/demo/DemoMotanServiceImpl.java index 81322bc4a74c991e606dd528fef701abc73dd9ce..bda6935e19745002b1d3cf0c646ef25a1ee08dfe 100644 --- a/whatsmars-spring-boot/src/main/java/com/itlong/whatsmars/spring/boot/motan/MotanDemoServiceImpl.java +++ b/whatsmars-motan-demo/src/main/java/com/itlong/motan/demo/DemoMotanServiceImpl.java @@ -2,9 +2,9 @@ * Created by shenhongxi on 2017/3/27. */ -package com.itlong.whatsmars.spring.boot.motan; +package com.itlong.motan.demo; -public class MotanDemoServiceImpl implements MotanDemoService { +public class DemoMotanServiceImpl implements DemoMotanService { public String hello(String name) { System.out.println(name); diff --git a/whatsmars-motan-demo/src/main/resources/application.properties b/whatsmars-motan-demo/src/main/resources/application.properties new file mode 100644 index 0000000000000000000000000000000000000000..a639de5067f291be2c9002497556fd5de84a70dc --- /dev/null +++ b/whatsmars-motan-demo/src/main/resources/application.properties @@ -0,0 +1 @@ +server.port: 8088 \ No newline at end of file diff --git a/whatsmars-motan-demo/src/main/resources/log4j.properties b/whatsmars-motan-demo/src/main/resources/log4j.properties new file mode 100644 index 0000000000000000000000000000000000000000..6bcae9abfd868459bfbbd48a3fcb2d894dc18d9e --- /dev/null +++ b/whatsmars-motan-demo/src/main/resources/log4j.properties @@ -0,0 +1,74 @@ +# +# Copyright 2009-2016 Weibo, Inc. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +log4j.rootLogger=warn +log4j.logger.info=info,infofile +log4j.logger.warn=warn,warnfile +log4j.logger.error=error,errorfile +log4j.logger.profile=info,profile + +log4j.logger.trace=trace,tracefile +log4j.logger.accessLog=debug,accessfile +log4j.logger.serviceStatsLog=info,serviceStatsLog + +log4j.appender.tracefile=org.apache.log4j.DailyRollingFileAppender +log4j.appender.tracefile.file=./logs/server/trace.log +log4j.appender.tracefile.DatePattern='.'yyyyMMdd +log4j.appender.tracefile.layout=org.apache.log4j.PatternLayout +log4j.appender.tracefile.layout.ConversionPattern=%-d{yyyy-MM-dd HH:mm:ss} [%p] %m%n + +log4j.appender.accessfile=org.apache.log4j.DailyRollingFileAppender +log4j.appender.accessfile.file=./logs/server/access.log +log4j.appender.accessfile.DatePattern='.'yyyyMMdd +log4j.appender.accessfile.layout=org.apache.log4j.PatternLayout +log4j.appender.accessfile.layout.ConversionPattern=%-d{yyyy-MM-dd HH:mm:ss} [%p] %m%n + +log4j.appender.stdout=org.apache.log4j.ConsoleAppender +log4j.appender.stdout.layout=org.apache.log4j.PatternLayout +log4j.appender.stdout.layout.ConversionPattern=%p %d{yy/MM/dd HH:mm:ss} %-50.50c(%L) - %m%n + +log4j.appender.infofile=org.apache.log4j.DailyRollingFileAppender +log4j.appender.infofile.file=./logs/server/info.log +log4j.appender.infofile.DatePattern='.'yyyyMMdd-HH +log4j.appender.infofile.layout=org.apache.log4j.PatternLayout +log4j.appender.infofile.layout.ConversionPattern=%-d{yyyy-MM-dd HH:mm:ss} [%p] %m%n + +log4j.appender.warnfile=org.apache.log4j.DailyRollingFileAppender +log4j.appender.warnfile.file=./logs/server/warn.log +log4j.appender.warnfile.DatePattern='.'yyyyMMdd +log4j.appender.warnfile.layout=org.apache.log4j.PatternLayout +log4j.appender.warnfile.layout.ConversionPattern=%-d{yyyy-MM-dd HH:mm:ss} [%p] %m%n + +log4j.appender.errorfile=org.apache.log4j.DailyRollingFileAppender +log4j.appender.errorfile.file=./logs/server/error.log +log4j.appender.errorfile.DatePattern='.'yyyyMMdd +log4j.appender.errorfile.layout=org.apache.log4j.PatternLayout +log4j.appender.errorfile.layout.ConversionPattern=%-d{yyyy-MM-dd HH:mm:ss} [%p] %m%n + + +#profile +log4j.appender.profile=org.apache.log4j.DailyRollingFileAppender +log4j.appender.profile.file=./logs/server/profile.log +log4j.appender.profile.DatePattern='.'yyyyMMdd-HH +log4j.appender.profile.layout=org.apache.log4j.PatternLayout +log4j.appender.profile.layout.ConversionPattern=%-d{yyyy-MM-dd HH:mm:ss} %m%n + +#serviceStats +log4j.appender.serviceStatsLog=org.apache.log4j.DailyRollingFileAppender +log4j.appender.serviceStatsLog.file=./logs/server/serverserviceStatsLog.log +log4j.appender.serviceStatsLog.DatePattern='.'yyyyMMdd +log4j.appender.serviceStatsLog.layout=org.apache.log4j.PatternLayout +log4j.appender.serviceStatsLog.layout.ConversionPattern=%-d{HH:mm:ss} %m%n diff --git a/whatsmars-spring-boot/src/main/resources/spring/motan.xml b/whatsmars-motan-demo/src/main/resources/spring/demo_motan.xml similarity index 100% rename from whatsmars-spring-boot/src/main/resources/spring/motan.xml rename to whatsmars-motan-demo/src/main/resources/spring/demo_motan.xml diff --git a/whatsmars-spring-boot/src/main/resources/spring/motan_demo_client.xml b/whatsmars-motan-demo/src/main/resources/spring/demo_motan_client.xml similarity index 100% rename from whatsmars-spring-boot/src/main/resources/spring/motan_demo_client.xml rename to whatsmars-motan-demo/src/main/resources/spring/demo_motan_client.xml diff --git a/whatsmars-spring-boot/src/main/resources/spring/motan_demo_server.xml.bak b/whatsmars-motan-demo/src/main/resources/spring/demo_motan_server.xml similarity index 79% rename from whatsmars-spring-boot/src/main/resources/spring/motan_demo_server.xml.bak rename to whatsmars-motan-demo/src/main/resources/spring/demo_motan_server.xml index cbb76d429ca7e251ed3c5411d3e8c70332672835..27d02efd871fe135c466d55e941b30e82a42a853 100644 --- a/whatsmars-spring-boot/src/main/resources/spring/motan_demo_server.xml.bak +++ b/whatsmars-motan-demo/src/main/resources/spring/demo_motan_server.xml @@ -22,7 +22,7 @@ http://api.weibo.com/schema/motan http://api.weibo.com/schema/motan.xsd"> - + - + - + diff --git a/whatsmars-motan/pom.xml b/whatsmars-motan/pom.xml index c1d9e45b32174a1cd217270cb9d52bd8f84f75c4..2305a5487cb310f22fa6d7eac6469a94386b9824 100644 --- a/whatsmars-motan/pom.xml +++ b/whatsmars-motan/pom.xml @@ -9,7 +9,7 @@ - com.itlong.whatsmars.spring.boot.App + com.weibo.motan.demo.service.App 0.1.1 diff --git a/whatsmars-motan/src/main/java/com/weibo/motan/demo/service/DemoRpcServer.java b/whatsmars-motan/src/main/java/com/weibo/motan/demo/service/DemoRpcServer.java deleted file mode 100644 index b834a728a0f5b11dd8343ff6a614740875cbbb4f..0000000000000000000000000000000000000000 --- a/whatsmars-motan/src/main/java/com/weibo/motan/demo/service/DemoRpcServer.java +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright 2009-2016 Weibo, Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.weibo.motan.demo.service; - -import com.weibo.api.motan.common.MotanConstants; -import com.weibo.api.motan.util.MotanSwitcherUtil; -import org.springframework.context.ApplicationContext; -import org.springframework.context.support.ClassPathXmlApplicationContext; - -public class DemoRpcServer { - - public static void main(String[] args) throws InterruptedException { - ApplicationContext applicationContext = new ClassPathXmlApplicationContext(new String[] {"classpath*:spring/motan_demo_server.xml"}); - MotanSwitcherUtil.setSwitcherValue(MotanConstants.REGISTRY_HEARTBEAT_SWITCHER, true); - System.out.println("server start..."); - - } - -} diff --git a/whatsmars-spring-boot/pom.xml b/whatsmars-spring-boot/pom.xml index 8902bf71522eb677a2080ece9a95d201b3b63f18..92d33d15fc2b341f77e66d8606be9333d8aa99c5 100644 --- a/whatsmars-spring-boot/pom.xml +++ b/whatsmars-spring-boot/pom.xml @@ -117,41 +117,6 @@ 1.0.31 - - - com.weibo - motan-core - ${motan.version} - - - com.weibo - motan-transport-netty - ${motan.version} - - - com.weibo - motan-registry-consul - ${motan.version} - - - com.weibo - motan-registry-zookeeper - ${motan.version} - - - - - com.weibo - motan-springsupport - ${motan.version} - - - - org.springframework.boot - whatsmars-motan - 1.5.2.RELEASE - - diff --git a/whatsmars-spring-boot/src/main/java/com/itlong/whatsmars/spring/boot/App.java b/whatsmars-spring-boot/src/main/java/com/itlong/whatsmars/spring/boot/App.java index 582bdefbbbf884a1edace08004296b47a949fc3d..811f1563c526312c147f2029e193718bd2d7ca67 100644 --- a/whatsmars-spring-boot/src/main/java/com/itlong/whatsmars/spring/boot/App.java +++ b/whatsmars-spring-boot/src/main/java/com/itlong/whatsmars/spring/boot/App.java @@ -1,8 +1,6 @@ package com.itlong.whatsmars.spring.boot; import com.itlong.whatsmars.spring.boot.config.UserConfig; -import com.weibo.api.motan.common.MotanConstants; -import com.weibo.api.motan.util.MotanSwitcherUtil; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.EnableAutoConfiguration; import org.springframework.boot.autoconfigure.SpringBootApplication; @@ -18,10 +16,6 @@ public class App { public static void main(String[] args) { SpringApplication.run(App.class, args); - - // motan - MotanSwitcherUtil.setSwitcherValue(MotanConstants.REGISTRY_HEARTBEAT_SWITCHER, true); - System.out.println("server start..."); } } \ No newline at end of file diff --git a/whatsmars-spring-boot/src/main/java/com/itlong/whatsmars/spring/boot/controller/DemoRpcClient.java b/whatsmars-spring-boot/src/main/java/com/itlong/whatsmars/spring/boot/controller/DemoRpcClient.java deleted file mode 100644 index 9cd689f41d9071b647123d30c08e68c6b93b7161..0000000000000000000000000000000000000000 --- a/whatsmars-spring-boot/src/main/java/com/itlong/whatsmars/spring/boot/controller/DemoRpcClient.java +++ /dev/null @@ -1,38 +0,0 @@ -/* - * Copyright 2009-2016 Weibo, Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.itlong.whatsmars.spring.boot.controller; - -import com.weibo.motan.demo.service.MotanDemoService; -import org.springframework.context.ApplicationContext; -import org.springframework.context.support.ClassPathXmlApplicationContext; - -public class DemoRpcClient { - - public static void main(String[] args) throws InterruptedException { - - ApplicationContext ctx = new ClassPathXmlApplicationContext(new String[]{"classpath:spring/motan_demo_client.xml"}); - - MotanDemoService service = (MotanDemoService) ctx.getBean("motanDemoReferer"); - for (int i = 0; i < Integer.MAX_VALUE; i++) { - System.out.println(service.hello("motan" + i)); - Thread.sleep(500); - } - System.out.println("motan demo is finish."); - System.exit(0); - } - -} diff --git a/whatsmars-spring-boot/src/main/java/com/itlong/whatsmars/spring/boot/controller/SampleController.java b/whatsmars-spring-boot/src/main/java/com/itlong/whatsmars/spring/boot/controller/SampleController.java index 787c4cb6f72169f77e262ea0990744f335f81b80..e52bc0e8b1f02591002a4c53025f4cb46e149e2f 100644 --- a/whatsmars-spring-boot/src/main/java/com/itlong/whatsmars/spring/boot/controller/SampleController.java +++ b/whatsmars-spring-boot/src/main/java/com/itlong/whatsmars/spring/boot/controller/SampleController.java @@ -2,11 +2,8 @@ package com.itlong.whatsmars.spring.boot.controller; import com.itlong.whatsmars.spring.boot.config.UserConfig; import com.itlong.whatsmars.spring.boot.common.LocaleService; -import com.weibo.motan.demo.service.MotanDemoService; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.context.ApplicationContext; import org.springframework.context.annotation.Bean; -import org.springframework.context.support.ClassPathXmlApplicationContext; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.ResponseBody; @@ -14,7 +11,6 @@ import org.springframework.web.servlet.LocaleResolver; import org.springframework.web.servlet.i18n.AbstractLocaleResolver; import org.springframework.web.servlet.i18n.SessionLocaleResolver; -import javax.annotation.Resource; import javax.servlet.http.HttpServletRequest; import java.util.Locale; import java.util.Map; @@ -31,9 +27,6 @@ public class SampleController { @Autowired private LocaleService localeService; - @Resource(name = "motanDemoService") - private MotanDemoService motanDemoService; - /** * 设置区域解析器 (default is AcceptHeaderLocaleResolver) */ @@ -63,10 +56,10 @@ public class SampleController { return "index"; } - @RequestMapping("/motan") + @RequestMapping("/do") @ResponseBody public String motan() { - return userConfig.getWelcome() + motanDemoService.hello("motan"); + return userConfig.getWelcome(); } } diff --git a/whatsmars-spring-boot/src/main/java/com/itlong/whatsmars/spring/boot/motan/MotanDemoService.java b/whatsmars-spring-boot/src/main/java/com/itlong/whatsmars/spring/boot/motan/MotanDemoService.java deleted file mode 100644 index 3073fc84ec31a1f085a0d13063d59b9fcf724857..0000000000000000000000000000000000000000 --- a/whatsmars-spring-boot/src/main/java/com/itlong/whatsmars/spring/boot/motan/MotanDemoService.java +++ /dev/null @@ -1,10 +0,0 @@ -/** - * Created by shenhongxi on 2017/3/27. - */ - -package com.itlong.whatsmars.spring.boot.motan; - -public interface MotanDemoService { - String hello(String name); - -} diff --git a/whatsmars-spring-boot/src/main/resources/application-test.properties b/whatsmars-spring-boot/src/main/resources/application-test.properties index 146eccbfe4242f1470db332c04366048ad88366b..3a400df23e48601705d68dc424d8e0879451af6d 100644 --- a/whatsmars-spring-boot/src/main/resources/application-test.properties +++ b/whatsmars-spring-boot/src/main/resources/application-test.properties @@ -1,4 +1,4 @@ -server.port: 80 +server.port: 8083 spring.session.store-type=redis server.session.timeout=14400