提交 da3b80bd 编写于 作者: 武汉红喜's avatar 武汉红喜

whatsmars-motan-demo

上级 94bb8fc1
......@@ -15,5 +15,7 @@ rocketmq-console rocketmq管理后台<br />
whatsmars-rpc 常用rpc<br />
whatsmars-spring-boot springboot果然很方便<br />
whatsmars-redis Cache Service & Redis Cluster <br />
whatsmars-motan weibo分布式RPC框架 demo server <br />
whatsmars-motan-demo weibo分布式RPC框架 demo server&client <br />
# 技术生态 java.toutiao.im
\ No newline at end of file
......@@ -29,6 +29,7 @@
<module>rocketmq-console</module>
<module>whatsmars-redis</module>
<module>whatsmars-motan</module>
<module>whatsmars-motan-demo</module>
</modules>
<properties>
......
先启动zookeeper(port:2181)和whatsmars-motan
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<artifactId>whatsmars-motan-demo</artifactId>
<properties>
<!-- The main class to start by executing java -jar -->
<start-class>com.itlong.motan.demo.App</start-class>
<motan.version>0.1.1</motan.version>
</properties>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.5.2.RELEASE</version>
</parent>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<!--weibo motan-->
<dependency>
<groupId>com.weibo</groupId>
<artifactId>motan-core</artifactId>
<version>${motan.version}</version>
</dependency>
<dependency>
<groupId>com.weibo</groupId>
<artifactId>motan-transport-netty</artifactId>
<version>${motan.version}</version>
</dependency>
<dependency>
<groupId>com.weibo</groupId>
<artifactId>motan-registry-consul</artifactId>
<version>${motan.version}</version>
</dependency>
<dependency>
<groupId>com.weibo</groupId>
<artifactId>motan-registry-zookeeper</artifactId>
<version>${motan.version}</version>
</dependency>
<!-- dependencies blow were only needed for spring-based features -->
<dependency>
<groupId>com.weibo</groupId>
<artifactId>motan-springsupport</artifactId>
<version>${motan.version}</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>whatsmars-motan</artifactId>
<version>1.5.2.RELEASE</version>
</dependency>
</dependencies>
<build>
<finalName>${project.artifactId}</finalName>
<resources>
<resource>
<directory>src/main/resources</directory>
<!--<includes>
<include>**/*.properties</include>
<include>**/*.xml</include>
<include>**/*.html</include>
</includes>-->
<filtering>true</filtering>
</resource>
</resources>
<plugins>
<!-- 该插件会使package打出一个可直接运行的jar包,即该jar包包含了依赖的所有jar包 -->
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<dependencies>
<!-- 使用SpringLoaded热部署 -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>springloaded</artifactId>
<version>1.2.6.RELEASE</version>
</dependency>
</dependencies>
<!-- POM不是继承spring-boot-starter-parent的话,需要下面的指定 -->
<!--<configuration>
<mainClass>${start-class}</mainClass>
<layout>ZIP</layout>
</configuration>
<executions>
<execution>
<goals>
<goal>repackage</goal>
</goals>
</execution>
</executions>-->
</plugin>
</plugins>
</build>
</project>
\ No newline at end of file
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
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);
}
}
......@@ -2,9 +2,9 @@
* Created by shenhongxi on 2017/3/27.
*/
package com.itlong.whatsmars.spring.boot.motan;
package com.itlong.motan.demo;
public interface MotanDemoService {
public interface DemoMotanService {
String hello(String name);
}
......@@ -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);
......
server.port: 8088
\ No newline at end of file
#
# 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
......@@ -22,7 +22,7 @@
http://api.weibo.com/schema/motan http://api.weibo.com/schema/motan.xsd">
<!-- 业务具体实现类 -->
<bean id="motanDemoServiceImpl" class="com.itlong.whatsmars.spring.boot.motan.MotanDemoServiceImpl"/>
<bean id="demoMotanService" class="com.itlong.motan.demo.DemoMotanServiceImpl"/>
<!-- 协议配置。为防止多个业务配置冲突,推荐使用id表示具体协议。-->
<motan:protocol id="demoMotan" default="true" name="motan"
......@@ -35,11 +35,11 @@
application="myMotanDemo" registry="registry" id="serviceBasicConfig"/>
<!-- 具体rpc服务配置,声明实现的接口类。-->
<motan:service interface="com.itlong.whatsmars.spring.boot.motan.MotanDemoService"
ref="motanDemoServiceImpl" export="demoMotan:8003" basicService="serviceBasicConfig">
<motan:service interface="com.itlong.motan.demo.DemoMotanService"
ref="demoMotanService" export="demoMotan:8003" basicService="serviceBasicConfig">
</motan:service>
<motan:service interface="com.itlong.whatsmars.spring.boot.motan.MotanDemoService"
ref="motanDemoServiceImpl" export="demoMotan:8004" basicService="serviceBasicConfig">
<motan:service interface="com.itlong.motan.demo.DemoMotanService"
ref="demoMotanService" export="demoMotan:8004" basicService="serviceBasicConfig">
</motan:service>
</beans>
......@@ -9,7 +9,7 @@
<properties>
<!-- The main class to start by executing java -jar -->
<start-class>com.itlong.whatsmars.spring.boot.App</start-class>
<start-class>com.weibo.motan.demo.service.App</start-class>
<motan.version>0.1.1</motan.version>
</properties>
......
/*
* 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...");
}
}
......@@ -117,41 +117,6 @@
<version>1.0.31</version>
</dependency>
<!--weibo motan-->
<dependency>
<groupId>com.weibo</groupId>
<artifactId>motan-core</artifactId>
<version>${motan.version}</version>
</dependency>
<dependency>
<groupId>com.weibo</groupId>
<artifactId>motan-transport-netty</artifactId>
<version>${motan.version}</version>
</dependency>
<dependency>
<groupId>com.weibo</groupId>
<artifactId>motan-registry-consul</artifactId>
<version>${motan.version}</version>
</dependency>
<dependency>
<groupId>com.weibo</groupId>
<artifactId>motan-registry-zookeeper</artifactId>
<version>${motan.version}</version>
</dependency>
<!-- dependencies blow were only needed for spring-based features -->
<dependency>
<groupId>com.weibo</groupId>
<artifactId>motan-springsupport</artifactId>
<version>${motan.version}</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>whatsmars-motan</artifactId>
<version>1.5.2.RELEASE</version>
</dependency>
</dependencies>
......
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
/*
* 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);
}
}
......@@ -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();
}
}
server.port: 80
server.port: 8083
spring.session.store-type=redis
server.session.timeout=14400
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册