package com.dubbo.api;
/**
* @version 1.0
* @author: fuqs
*/
import com.dubbo.model.Order;
import org.apache.dubbo.rpc.RpcContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import javax.ws.rs.client.Client;
import javax.ws.rs.client.ClientBuilder;
import javax.ws.rs.client.WebTarget;
import javax.ws.rs.core.Response;
/**
* @author éé
¸èHaC | WebSiteð¶ : https://rain.baimuxym.cn
* @date 2021/11/22
* @Description consumerå¯å¨ç±»
*/
public class Consumer {
public static void main(String[] args) throws Exception {
ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(new String[]{"spring/dubbo-consumer.xml"});
context.start();
System.out.println("consumer start.....");
// dubbo
OrderService orderService1 = context.getBean("orderServiceImpl", OrderService.class);
// hessian
OrderService orderService2 = context.getBean("orderServiceImpl2", OrderService.class);
// rest
OrderRESTService2 orderRESTService2 = context.getBean("orderRESTService2", OrderRESTService2.class);
while (true) {
System.in.read();
RpcContext rpcContext = RpcContext.getContext();
// System.out.println("SUCCESS: got order list " + orderService1.getOrderInfo(1L));
// System.out.println("SUCCESS: got order list" + orderService2.getOrderInfo(1L));
System.out.println("SUCCESS: got order " + orderRESTService2.getOrderInfo(1L));
// rest
String port = "7777";
getOrder("http://localhost:" + port + "/services/order/2");
}
}
/**
* èµ°httpè°ç¨
* @param url
*/
private static void getOrder(String url) {
Client client = ClientBuilder.newClient();
WebTarget target = client.target(url);
Response response = target.request().get();
try {
if (response.getStatus() != 200) {
throw new RuntimeException("Failed with HTTP error code : " + response.getStatus());
}
System.out.println("SUCCESS: got result: " + response.readEntity(Order.class));
} finally {
response.close();
client.close();
}
}
}
没有合适的资源?快使用搜索试试~ 我知道了~
资源推荐
资源详情
资源评论
收起资源包目录
dubbo-rest-hessian.zip (56个子文件)
dubbo-rest-hessian
dubbo-rest-hessian.iml 156B
pom.xml 3KB
src
test
java
main
resources
java
.idea
jarRepositories.xml 880B
uiDesigner.xml 9KB
qaplug_profiles.xml 41KB
workspace.xml 9KB
misc.xml 1KB
inspectionProfiles
Project_Default.xml 1KB
compiler.xml 1KB
.gitignore 184B
sonarlint
issuestore
e
b
eb233b85a7f51a2c374f973ab409bca0160ba4ce 0B
c
d
cdff054870efc0dfa7da1ae2d12796abb80d1d79 0B
index.pb 2KB
a
e
aea0ccfeb405aab579256faaad1facb0e5c69fd7 0B
6
a63026968c3e782397c7d8966f4cc96bfc75b39e 0B
9
1
91d2e18e9265140c1f5473ec8f9ce306a17651ae 0B
1
3
136eb60084ef9cb849357834ea0c130a80e8d069 0B
2
c
2c00d5749757a19625a5348d0ad0687f83978bb3 160B
f
2fbfd4f08db32ec482a975019e6b9475aba39559 1KB
6
1
61007eeb10f63bb1be042a4207ea10a5c2f9d05c 0B
4
4
442292b8a7efeabbe4cc176709b833b1792140ec 0B
b
d
bdcf6319d8acdf4f6792032b3bc02f546c511a0e 0B
0
b08b362f48be4e3b2c8448730a79e8e2ac0fe7dd 0B
1
b1e55beb759832079a1f5748e41af94abe41a323 0B
3
f
3fa30c25ef7c04897a57606ab0d4882da40207c2 0B
$PROJECT_FILE$ 364B
dubbo-samples-xml-consumer
pom.xml 4KB
dubbo-samples-xml-consumer.iml 296B
src
test
java
main
resources
spring
dubbo-consumer.xml 1KB
java
com
dubbo
api
Consumer.java 2KB
target
classes
spring
dubbo-consumer.xml 1KB
com
dubbo
api
Consumer.class 3KB
generated-sources
annotations
tomcat.8080
work
Tomcat
localhost
ROOT
dubbo-samples-xml-api
pom.xml 1KB
src
test
java
main
resources
java
com
dubbo
api
OrderRESTService2.java 613B
OrderService.java 213B
OrderRESTService.java 178B
model
Order.java 409B
target
classes
com
dubbo
api
OrderRESTService.class 194B
OrderRESTService2.class 575B
OrderService.class 231B
model
Order.class 2KB
generated-sources
annotations
dubbo-samples-xml-api.iml 156B
dubbo-samples-xml-provider
dubbo-samples-xml-provider.iml 296B
pom.xml 4KB
src
test
java
main
resources
spring
dubbo-provider.xml 2KB
java
com
dubbo
api
impl
rest
OrderRESTServiceImpl2.java 984B
OrderRESTServiceImpl.java 2KB
OrderServiceImpl2.java 1KB
OrderServiceImpl.java 1KB
Provider.java 549B
target
classes
spring
dubbo-provider.xml 2KB
com
dubbo
api
Provider.class 985B
impl
rest
OrderRESTServiceImpl2.class 1KB
OrderRESTServiceImpl.class 2KB
OrderServiceImpl2.class 2KB
OrderServiceImpl.class 2KB
generated-sources
annotations
共 56 条
- 1
资源评论
生如夏花_fqsong
- 粉丝: 1
- 资源: 5
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功