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

motan demo

上级 f731d906
package com.weibo.motan.demo.service;
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;
......@@ -12,6 +14,9 @@ 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
/*
* 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...");
}
}
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;
......@@ -11,11 +13,15 @@ import org.springframework.context.annotation.ImportResource;
// 加上exclude=DataSource..后,不会连接数据库,同时@Mapper也不会起作用
@EnableAutoConfiguration//(exclude={DataSourceAutoConfiguration.class})
@EnableConfigurationProperties({UserConfig.class})
//@ImportResource(locations={"classpath*:spring/*server.xml"})
@ImportResource(locations={"classpath*:spring/*.xml"})
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
......@@ -2,6 +2,7 @@ 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;
......@@ -30,8 +31,8 @@ public class SampleController {
@Autowired
private LocaleService localeService;
// @Resource(name = "motanDemoService")
// private MotanDemoService motanDemoService;
@Resource(name = "motanDemoService")
private MotanDemoService motanDemoService;
/**
* 设置区域解析器 (default is AcceptHeaderLocaleResolver)
......@@ -65,9 +66,7 @@ public class SampleController {
@RequestMapping("/motan")
@ResponseBody
public String motan() {
ApplicationContext ctx = new ClassPathXmlApplicationContext(new String[]{"classpath:spring/motan_demo_client.xml"});
com.weibo.motan.demo.service.MotanDemoService service = (com.weibo.motan.demo.service.MotanDemoService) ctx.getBean("motanDemoReferer");
return userConfig.getWelcome() + service.hello("motan");
return userConfig.getWelcome() + motanDemoService.hello("motan");
}
}
......@@ -16,27 +16,17 @@
-->
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:motan="http://api.weibo.com/schema/motan"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:motan="http://api.weibo.com/schema/motan"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
http://api.weibo.com/schema/motan http://api.weibo.com/schema/motan.xsd">
<import resource="classpath*:spring/configloader.xml"/>
<!-- 注册中心配置 -->
<motan:registry regProtocol="local" name="motanDemo" />
<!-- motan协议配置 -->
<motan:protocol default="true" name="motan" haStrategy="failover"
loadbalance="activeWeight" maxClientConnection="10" minClientConnection="2"/>
<!-- 通用referer基础配置 -->
<motan:basicReferer requestTimeout="200" accessLog="false"
retries="2" group="motan-demo-rpc" module="motan-demo-rpc"
application="myMotanDemo" protocol="motan" registry="motanDemo"
id="motantestClientBasicConfig" throwException="false" check="true" />
<!-- 注册中心配置 使用不同注册中心需要依赖对应的jar包。如果不使用注册中心,可以把check属性改为false,忽略注册失败。-->
<!--<motan:registry regProtocol="local" name="registry" />-->
<!--<motan:registry regProtocol="consul" name="registry" address="127.0.0.1:8500"/>-->
<motan:registry regProtocol="zookeeper" name="registry" address="127.0.0.1:2181"/>
<!-- 具体referer配置。使用方通过beanid使用服务接口类 -->
<motan:referer id="motanDemoReferer"
directUrl="localhost:8002"
interface="com.weibo.motan.demo.service.MotanDemoService"
connectTimeout="300" requestTimeout="300" basicReferer="motantestClientBasicConfig" />
</beans>
\ No newline at end of file
</beans>
......@@ -20,10 +20,7 @@
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
http://api.weibo.com/schema/motan http://api.weibo.com/schema/motan.xsd">
<!-- 注册中心配置 使用不同注册中心需要依赖对应的jar包。-->
<!--<motan:registry regProtocol="local" name="registry"/>-->
<!--<motan:registry regProtocol="consul" name="registry" address="127.0.0.1:8500"/>-->
<motan:registry regProtocol="zookeeper" name="registry" address="127.0.0.1:2181"/>
<!-- motan协议配置 -->
<motan:protocol default="true" name="motan" haStrategy="failover"
......@@ -36,7 +33,7 @@
id="motantestClientBasicConfig" throwException="false" check="true"/>
<!-- 具体referer配置。使用方通过beanid使用服务接口类 -->
<motan:referer id="motanDemoReferer"
<motan:referer id="motanDemoService"
interface="com.weibo.motan.demo.service.MotanDemoService"
connectTimeout="300" requestTimeout="300" basicReferer="motantestClientBasicConfig"/>
......
......@@ -24,27 +24,22 @@
<!-- 业务具体实现类 -->
<bean id="motanDemoServiceImpl" class="com.itlong.whatsmars.spring.boot.motan.MotanDemoServiceImpl"/>
<!-- 注册中心配置 使用不同注册中心需要依赖对应的jar包。如果不使用注册中心,可以把check属性改为false,忽略注册失败。-->
<!--<motan:registry regProtocol="local" name="registry" />-->
<!--<motan:registry regProtocol="consul" name="registry" address="127.0.0.1:8500"/>-->
<motan:registry regProtocol="zookeeper" name="registry" address="127.0.0.1:2181"/>
<!-- 协议配置。为防止多个业务配置冲突,推荐使用id表示具体协议。-->
<motan:protocol id="demoMotan" default="true" name="motan"
maxServerConnection="80000" maxContentLength="1048576"
maxWorkerThread="800" minWorkerThread="20"/>
<!-- 通用配置,多个rpc服务使用相同的基础配置. group和module定义具体的服务池。export格式为“protocol id:提供服务的端口”-->
<motan:basicService export="demoMotan:8002"
<motan:basicService export="demoMotan:8003"
group="motan-demo-rpc" accessLog="false" shareChannel="true" module="motan-demo-rpc"
application="myMotanDemo" registry="registry" id="serviceBasicConfig"/>
<!-- 具体rpc服务配置,声明实现的接口类。-->
<motan:service interface="com.itlong.whatsmars.spring.boot.motan.MotanDemoService"
ref="motanDemoServiceImpl" export="demoMotan:8001" basicService="serviceBasicConfig">
ref="motanDemoServiceImpl" export="demoMotan:8003" basicService="serviceBasicConfig">
</motan:service>
<motan:service interface="com.itlong.whatsmars.spring.boot.motan.MotanDemoService"
ref="motanDemoServiceImpl" export="demoMotan:8002" basicService="serviceBasicConfig">
ref="motanDemoServiceImpl" export="demoMotan:8004" basicService="serviceBasicConfig">
</motan:service>
</beans>
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册