Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
caopu16
whatsmars
提交
94bb8fc1
W
whatsmars
项目概览
caopu16
/
whatsmars
与 Fork 源项目一致
Fork自
武汉红喜 / whatsmars
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
W
whatsmars
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
94bb8fc1
编写于
6月 30, 2017
作者:
武汉红喜
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
motan demo
上级
f731d906
变更
7
隐藏空白更改
内联
并排
Showing
7 changed file
with
86 addition
and
19 deletion
+86
-19
whatsmars-motan/src/main/java/com/weibo/motan/demo/service/App.java
...motan/src/main/java/com/weibo/motan/demo/service/App.java
+5
-0
whatsmars-motan/src/main/java/com/weibo/motan/demo/service/DemoRpcServer.java
...main/java/com/weibo/motan/demo/service/DemoRpcServer.java
+33
-0
whatsmars-spring-boot/src/main/java/com/itlong/whatsmars/spring/boot/App.java
...t/src/main/java/com/itlong/whatsmars/spring/boot/App.java
+7
-1
whatsmars-spring-boot/src/main/java/com/itlong/whatsmars/spring/boot/controller/SampleController.java
...ng/whatsmars/spring/boot/controller/SampleController.java
+4
-5
whatsmars-spring-boot/src/main/resources/spring/motan.xml
whatsmars-spring-boot/src/main/resources/spring/motan.xml
+32
-0
whatsmars-spring-boot/src/main/resources/spring/motan_demo_client.xml
...ring-boot/src/main/resources/spring/motan_demo_client.xml
+2
-5
whatsmars-spring-boot/src/main/resources/spring/motan_demo_server.xml.bak
...-boot/src/main/resources/spring/motan_demo_server.xml.bak
+3
-8
未找到文件。
whatsmars-motan/src/main/java/com/weibo/motan/demo/service/App.java
浏览文件 @
94bb8fc1
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
whatsmars-motan/src/main/java/com/weibo/motan/demo/service/DemoRpcServer.java
0 → 100644
浏览文件 @
94bb8fc1
/*
* 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..."
);
}
}
whatsmars-spring-boot/src/main/java/com/itlong/whatsmars/spring/boot/App.java
浏览文件 @
94bb8fc1
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
whatsmars-spring-boot/src/main/java/com/itlong/whatsmars/spring/boot/controller/SampleController.java
浏览文件 @
94bb8fc1
...
...
@@ -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"
);
}
}
whatsmars-spring-boot/src/main/resources/spring/motan
_demo_client_direct
.xml
→
whatsmars-spring-boot/src/main/resources/spring/motan.xml
浏览文件 @
94bb8fc1
...
...
@@ -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>
whatsmars-spring-boot/src/main/resources/spring/motan_demo_client.xml
浏览文件 @
94bb8fc1
...
...
@@ -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=
"motanDemo
Referer
"
<motan:referer
id=
"motanDemo
Service
"
interface=
"com.weibo.motan.demo.service.MotanDemoService"
connectTimeout=
"300"
requestTimeout=
"300"
basicReferer=
"motantestClientBasicConfig"
/>
...
...
whatsmars-spring-boot/src/main/resources/spring/motan_demo_server.xml
→
whatsmars-spring-boot/src/main/resources/spring/motan_demo_server.xml
.bak
浏览文件 @
94bb8fc1
...
...
@@ -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:800
2
"
<motan:basicService
export=
"demoMotan:800
3
"
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:800
1
"
basicService=
"serviceBasicConfig"
>
ref=
"motanDemoServiceImpl"
export=
"demoMotan:800
3
"
basicService=
"serviceBasicConfig"
>
</motan:service>
<motan:service
interface=
"com.itlong.whatsmars.spring.boot.motan.MotanDemoService"
ref=
"motanDemoServiceImpl"
export=
"demoMotan:800
2
"
basicService=
"serviceBasicConfig"
>
ref=
"motanDemoServiceImpl"
export=
"demoMotan:800
4
"
basicService=
"serviceBasicConfig"
>
</motan:service>
</beans>
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录