Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
武汉红喜
whatsmars
提交
2dd015b0
W
whatsmars
项目概览
武汉红喜
/
whatsmars
通知
3
Star
0
Fork
1
代码
文件
提交
分支
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,体验更适合开发者的 AI 搜索 >>
提交
2dd015b0
编写于
1月 06, 2018
作者:
武汉红喜
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
异步调用
上级
21d8378c
变更
6
隐藏空白更改
内联
并排
Showing
6 changed file
with
123 addition
and
1 deletion
+123
-1
whatsmars-dubbo/whatsmars-dubbo-api/src/main/java/org/hongxi/whatsmars/dubbo/demo/api/BarService.java
.../java/org/hongxi/whatsmars/dubbo/demo/api/BarService.java
+12
-0
whatsmars-dubbo/whatsmars-dubbo-api/src/main/java/org/hongxi/whatsmars/dubbo/demo/api/vo/Bar.java
...main/java/org/hongxi/whatsmars/dubbo/demo/api/vo/Bar.java
+51
-0
whatsmars-dubbo/whatsmars-dubbo-consumer/src/main/java/org/hongxi/whatsmars/dubbo/demo/consumer/DemoConsumer.java
...rg/hongxi/whatsmars/dubbo/demo/consumer/DemoConsumer.java
+27
-1
whatsmars-dubbo/whatsmars-dubbo-consumer/src/main/resources/META-INF/spring/dubbo-demo-consumer.xml
...rc/main/resources/META-INF/spring/dubbo-demo-consumer.xml
+8
-0
whatsmars-dubbo/whatsmars-dubbo-provider/src/main/java/org/hongxi/whatsmars/dubbo/demo/provider/BarServiceImpl.java
.../hongxi/whatsmars/dubbo/demo/provider/BarServiceImpl.java
+23
-0
whatsmars-dubbo/whatsmars-dubbo-provider/src/main/resources/META-INF/spring/dubbo-demo-provider.xml
...rc/main/resources/META-INF/spring/dubbo-demo-provider.xml
+2
-0
未找到文件。
whatsmars-dubbo/whatsmars-dubbo-api/src/main/java/org/hongxi/whatsmars/dubbo/demo/api/BarService.java
0 → 100644
浏览文件 @
2dd015b0
/**
* Created by shenhongxi on 2017/6/21.
*/
package
org.hongxi.whatsmars.dubbo.demo.api
;
import
org.hongxi.whatsmars.dubbo.demo.api.vo.Bar
;
public
interface
BarService
{
Bar
findBar
(
String
barId
);
}
\ No newline at end of file
whatsmars-dubbo/whatsmars-dubbo-api/src/main/java/org/hongxi/whatsmars/dubbo/demo/api/vo/Bar.java
0 → 100644
浏览文件 @
2dd015b0
package
org.hongxi.whatsmars.dubbo.demo.api.vo
;
import
java.io.Serializable
;
public
class
Bar
implements
Serializable
{
private
static
final
long
serialVersionUID
=
-
5809782578272943999L
;
private
String
barId
;
private
String
name
;
private
String
address
;
public
Bar
()
{}
public
Bar
(
String
barId
,
String
name
,
String
address
)
{
this
.
barId
=
barId
;
this
.
name
=
name
;
this
.
address
=
address
;
}
public
String
getBarId
()
{
return
barId
;
}
public
void
setBarId
(
String
barId
)
{
this
.
barId
=
barId
;
}
public
String
getName
()
{
return
name
;
}
public
void
setName
(
String
name
)
{
this
.
name
=
name
;
}
public
String
getAddress
()
{
return
address
;
}
public
void
setAddress
(
String
address
)
{
this
.
address
=
address
;
}
@Override
public
String
toString
()
{
return
"barId:"
+
barId
+
",name:"
+
name
+
",address"
+
address
;
}
}
whatsmars-dubbo/whatsmars-dubbo-consumer/src/main/java/org/hongxi/whatsmars/dubbo/demo/consumer/DemoConsumer.java
浏览文件 @
2dd015b0
...
@@ -3,17 +3,25 @@
...
@@ -3,17 +3,25 @@
*/
*/
package
org.hongxi.whatsmars.dubbo.demo.consumer
;
package
org.hongxi.whatsmars.dubbo.demo.consumer
;
import
com.alibaba.dubbo.rpc.RpcContext
;
import
com.alibaba.dubbo.rpc.service.EchoService
;
import
com.alibaba.dubbo.rpc.service.EchoService
;
import
org.hongxi.whatsmars.dubbo.demo.api.BarService
;
import
org.hongxi.whatsmars.dubbo.demo.api.DemoService
;
import
org.hongxi.whatsmars.dubbo.demo.api.DemoService
;
import
org.hongxi.whatsmars.dubbo.demo.api.vo.Bar
;
import
org.springframework.context.support.ClassPathXmlApplicationContext
;
import
org.springframework.context.support.ClassPathXmlApplicationContext
;
import
java.util.concurrent.Future
;
public
class
DemoConsumer
{
public
class
DemoConsumer
{
public
static
void
main
(
String
[]
args
)
{
public
static
void
main
(
String
[]
args
)
throws
Exception
{
ClassPathXmlApplicationContext
context
=
new
ClassPathXmlApplicationContext
(
new
String
[]{
"META-INF/spring/dubbo-demo-consumer.xml"
});
ClassPathXmlApplicationContext
context
=
new
ClassPathXmlApplicationContext
(
new
String
[]{
"META-INF/spring/dubbo-demo-consumer.xml"
});
context
.
start
();
context
.
start
();
// 异步调用
async
(
context
);
// dubbo protocol
// dubbo protocol
DemoService
demoService
=
(
DemoService
)
context
.
getBean
(
"demoService"
);
// 获取远程服务代理
DemoService
demoService
=
(
DemoService
)
context
.
getBean
(
"demoService"
);
// 获取远程服务代理
String
hello
=
demoService
.
sayHello
(
"dubbo"
);
// 执行远程方法
String
hello
=
demoService
.
sayHello
(
"dubbo"
);
// 执行远程方法
...
@@ -39,6 +47,24 @@ public class DemoConsumer {
...
@@ -39,6 +47,24 @@ public class DemoConsumer {
Object
status
=
echoService
.
$echo
(
"OK"
);
Object
status
=
echoService
.
$echo
(
"OK"
);
System
.
out
.
println
(
"回声测试:"
+
status
.
equals
(
"OK"
));
System
.
out
.
println
(
"回声测试:"
+
status
.
equals
(
"OK"
));
System
.
out
.
println
(
"#######################ALL SUCCESSFUL##########################"
);
}
}
private
static
void
async
(
ClassPathXmlApplicationContext
context
)
throws
Exception
{
// 异步调用
DemoService
demoService5
=
(
DemoService
)
context
.
getBean
(
"demoService5"
);
demoService5
.
sayHello
(
"aysc"
);
Future
<
String
>
helloFuture
=
RpcContext
.
getContext
().
getFuture
();
BarService
barService
=
(
BarService
)
context
.
getBean
(
"barService"
);
barService
.
findBar
(
"m123456"
);
Future
<
Bar
>
barFuture
=
RpcContext
.
getContext
().
getFuture
();
String
hello5
=
helloFuture
.
get
();
Bar
bar
=
barFuture
.
get
();
System
.
out
.
println
(
hello5
);
System
.
out
.
println
(
bar
);
}
}
}
\ No newline at end of file
whatsmars-dubbo/whatsmars-dubbo-consumer/src/main/resources/META-INF/spring/dubbo-demo-consumer.xml
浏览文件 @
2dd015b0
...
@@ -22,4 +22,12 @@
...
@@ -22,4 +22,12 @@
<dubbo:reference
id=
"demoService4"
group=
"new"
interface=
"org.hongxi.whatsmars.dubbo.demo.api.DemoService"
/>
<dubbo:reference
id=
"demoService4"
group=
"new"
interface=
"org.hongxi.whatsmars.dubbo.demo.api.DemoService"
/>
<dubbo:reference
id=
"demoService5"
interface=
"org.hongxi.whatsmars.dubbo.demo.api.DemoService"
>
<dubbo:method
name=
"sayHello"
async=
"true"
/>
</dubbo:reference>
<dubbo:reference
id=
"barService"
interface=
"org.hongxi.whatsmars.dubbo.demo.api.BarService"
>
<dubbo:method
name=
"findBar"
async=
"true"
/>
</dubbo:reference>
</beans>
</beans>
\ No newline at end of file
whatsmars-dubbo/whatsmars-dubbo-provider/src/main/java/org/hongxi/whatsmars/dubbo/demo/provider/BarServiceImpl.java
0 → 100644
浏览文件 @
2dd015b0
/**
* Created by shenhongxi on 2017/6/21.
*/
package
org.hongxi.whatsmars.dubbo.demo.provider
;
import
org.hongxi.whatsmars.dubbo.demo.api.BarService
;
import
org.hongxi.whatsmars.dubbo.demo.api.vo.Bar
;
import
org.springframework.stereotype.Service
;
@Service
(
"barService"
)
public
class
BarServiceImpl
implements
BarService
{
@Override
public
Bar
findBar
(
String
barId
)
{
try
{
Thread
.
sleep
(
1000
);
}
catch
(
Exception
e
)
{
}
return
new
Bar
(
barId
,
"芝根芝底"
,
"酒仙桥302号"
);
}
}
\ No newline at end of file
whatsmars-dubbo/whatsmars-dubbo-provider/src/main/resources/META-INF/spring/dubbo-demo-provider.xml
浏览文件 @
2dd015b0
...
@@ -29,4 +29,6 @@
...
@@ -29,4 +29,6 @@
<!-- 类似group的还有version="2.0.0" -->
<!-- 类似group的还有version="2.0.0" -->
<dubbo:service
group=
"new"
interface=
"org.hongxi.whatsmars.dubbo.demo.api.DemoService"
ref=
"demoService2"
/>
<dubbo:service
group=
"new"
interface=
"org.hongxi.whatsmars.dubbo.demo.api.DemoService"
ref=
"demoService2"
/>
<dubbo:service
interface=
"org.hongxi.whatsmars.dubbo.demo.api.BarService"
ref=
"barService"
/>
</beans>
</beans>
\ No newline at end of file
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录