Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
thythm
ribbon
提交
4fbdadf7
R
ribbon
项目概览
thythm
/
ribbon
与 Fork 源项目一致
从无法访问的项目Fork
通知
3
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
R
ribbon
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
提交
4fbdadf7
编写于
4月 28, 2014
作者:
A
Allen Wang
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Modified examples.
上级
18772728
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
28 addition
and
245 deletion
+28
-245
ribbon-examples/src/main/java/com/netflix/ribbon/examples/netty/http/EntityDeserializationExample.java
...bon/examples/netty/http/EntityDeserializationExample.java
+0
-88
ribbon-examples/src/main/java/com/netflix/ribbon/examples/netty/http/HttpResponseDeserialization.java
...bbon/examples/netty/http/HttpResponseDeserialization.java
+0
-53
ribbon-examples/src/main/java/com/netflix/ribbon/examples/netty/http/LoadBalancingExample.java
...flix/ribbon/examples/netty/http/LoadBalancingExample.java
+28
-16
ribbon-examples/src/main/java/com/netflix/ribbon/examples/netty/http/PostExample.java
...a/com/netflix/ribbon/examples/netty/http/PostExample.java
+0
-32
ribbon-examples/src/main/java/com/netflix/ribbon/examples/netty/http/SeverSentEventExample.java
...lix/ribbon/examples/netty/http/SeverSentEventExample.java
+0
-56
未找到文件。
ribbon-examples/src/main/java/com/netflix/ribbon/examples/netty/http/EntityDeserializationExample.java
已删除
100644 → 0
浏览文件 @
18772728
package
com.netflix.ribbon.examples.netty.http
;
import
com.netflix.ribbon.examples.ExampleAppWithLocalResource
;
public
class
EntityDeserializationExample
extends
ExampleAppWithLocalResource
{
@Override
public
void
run
()
throws
Exception
{
/*
HttpClientRequest<ByteBuf> request = HttpClientRequest.createGet(SERVICE_URI + "testAsync/person");
NettyHttpClient observableClient = NettyHttpClientBuilder.newBuilder()
.build();
// deserialize using the default Jackson deserializer
observableClient.createEntityObservable("localhost", port, request, TypeDef.fromClass(Person.class), null).toBlockingObservable().forEach(new Action1<Person>() {
@Override
public void call(Person t1) {
try {
System.out.println("Person: " + t1);
} catch (Exception e) {
e.printStackTrace();
}
}
});
// deserialize as Map using the default Jackson deserializer
observableClient.createEntityObservable("localhost", port, request, new TypeDef<Map<String, Object>>(){}, null)
.toBlockingObservable()
.forEach(new Action1<Map<String, Object>>() {
@Override
public void call(Map<String, Object> t1) {
try {
System.out.println("Map: " + t1);
} catch (Exception e) {
e.printStackTrace();
}
}
});
// deserialize using Xml deserializer
IClientConfig requestConfig = DefaultClientConfigImpl.getEmptyConfig()
.setPropertyWithType(IClientConfigKey.CommonKeys.Deserializer, XmlCodec.<Person>getInstance());
request = HttpRequest.createGet(SERVICE_URI + "testAsync/getXml");
observableClient.createEntityObservable("localhost", port, request, TypeDef.fromClass(Person.class), requestConfig)
.toBlockingObservable()
.forEach(new Action1<Person>() {
@Override
public void call(Person t1) {
try {
System.out.println("Person: " + t1);
} catch (Exception e) {
e.printStackTrace();
}
}
});
// URI does not exist, will get UnexpectedResponseException
request = HttpRequest.createGet(SERVICE_URI + "testAsync/NotFound");
observableClient.createEntityObservable("localhost", port, request, TypeDef.fromClass(Person.class), null)
.subscribe(new Action1<Person>() {
@Override
public void call(Person t1) {
try {
System.out.println("Person: " + t1);
} catch (Exception e) {
e.printStackTrace();
}
}
}, new Action1<Throwable>() {
@Override
public void call(Throwable t1) {
if (t1 instanceof UnexpectedHttpResponseException) {
UnexpectedHttpResponseException ex = (UnexpectedHttpResponseException) t1;
System.out.println(ex.getStatusCode());
}
}
});
Thread.sleep(2000);
*/
}
public
static
void
main
(
String
[]
args
)
throws
Exception
{
new
EntityDeserializationExample
().
runApp
();
}
}
ribbon-examples/src/main/java/com/netflix/ribbon/examples/netty/http/HttpResponseDeserialization.java
已删除
100644 → 0
浏览文件 @
18772728
package
com.netflix.ribbon.examples.netty.http
;
import
com.netflix.ribbon.examples.ExampleAppWithLocalResource
;
public
class
HttpResponseDeserialization
extends
ExampleAppWithLocalResource
{
@Override
public
void
run
()
throws
Exception
{
// TODO Auto-generated method stub
}
/*
@Override
public void run() throws Exception {
HttpRequest<ByteBuf> request = HttpRequest.createGet(SERVICE_URI + "testAsync/getXml");
NettyHttpClient observableClient = NettyHttpClientBuilder.newBuilder()
.build();
observableClient.createFullHttpResponseObservable("localhost", port, request)
.flatMap(new Func1<HttpResponse<ByteBuf>, Observable<Person>>() {
@Override
public Observable<Person> call(HttpResponse<ByteBuf> t1) {
return t1.getContent().map(new Func1<ByteBuf, Person>() {
@Override
public Person call(ByteBuf t1) {
try {
return XmlCodec.<Person>getInstance().deserialize(new ByteBufInputStream(t1), TypeDef.fromClass(Person.class));
} catch (IOException e) {
throw new RuntimeException(e);
}
}
});
}
}).toBlockingObservable()
.forEach(new Action1<Person>() {
@Override
public void call(Person t1) {
try {
System.out.println(t1);
} catch (Exception e) {
e.printStackTrace();
}
}
});
}
public static void main(String[] args) throws Exception {
new HttpResponseDeserialization().runApp();
}
*/
}
ribbon-examples/src/main/java/com/netflix/ribbon/examples/netty/http/LoadBalancingExample.java
浏览文件 @
4fbdadf7
package
com.netflix.ribbon.examples.netty.http
;
package
com.netflix.ribbon.examples.netty.http
;
import
io.netty.buffer.ByteBuf
;
import
io.reactivex.netty.protocol.http.client.HttpClientRequest
;
import
io.reactivex.netty.protocol.http.client.HttpClientResponse
;
import
java.util.List
;
import
java.util.concurrent.CountDownLatch
;
import
rx.Observer
;
import
com.google.common.collect.Lists
;
import
com.netflix.client.netty.http.NettyHttpClient
;
import
com.netflix.loadbalancer.BaseLoadBalancer
;
import
com.netflix.loadbalancer.LoadBalancerBuilder
;
import
com.netflix.loadbalancer.Server
;
public
class
LoadBalancingExample
{
public
class
LoadBalancingExample
{
/*
public
static
void
main
(
String
[]
args
)
throws
Exception
{
public
static
void
main
(
String
[]
args
)
throws
Exception
{
NettyHttpLoadBalancingClient client = NettyHttpClientBuilder.newBuilder()
List
<
Server
>
servers
=
Lists
.
newArrayList
(
new
Server
(
"www.google.com:80"
),
new
Server
(
"www.examples.com:80"
),
new
Server
(
"www.wikipedia.org:80"
));
.withFixedServerList(Lists.newArrayList(new Server("www.google.com:80"), new Server("www.microsoft.com:80"), new Server("www.yahoo.com:80")))
BaseLoadBalancer
lb
=
LoadBalancerBuilder
.
newBuilder
()
.build();
.
buildFixedServerListLoadBalancer
(
servers
);
final CountDownLatch latch = new CountDownLatch(3);
Observer<HttpResponse<ByteBuf>> observer = new Observer<HttpResponse<ByteBuf>>() {
NettyHttpClient
<
ByteBuf
,
ByteBuf
>
client
=
NettyHttpClient
.
createDefaultHttpClient
(
lb
);
final
CountDownLatch
latch
=
new
CountDownLatch
(
servers
.
size
());
Observer
<
HttpClientResponse
<
ByteBuf
>>
observer
=
new
Observer
<
HttpClientResponse
<
ByteBuf
>>()
{
@Override
@Override
public
void
onCompleted
()
{
public
void
onCompleted
()
{
}
}
...
@@ -19,20 +35,16 @@ public class LoadBalancingExample {
...
@@ -19,20 +35,16 @@ public class LoadBalancingExample {
}
}
@Override
@Override
public void onNext(HttpResponse<ByteBuf> args) {
public
void
onNext
(
Http
Client
Response
<
ByteBuf
>
args
)
{
latch
.
countDown
();
latch
.
countDown
();
System.
err
.println("Got response: " + args.getStatus());
System
.
out
.
println
(
"Got response: "
+
args
.
getStatus
());
}
}
};
};
for (int i = 0; i < 3; i++) {
for
(
int
i
=
0
;
i
<
servers
.
size
();
i
++)
{
// The request is not reusable in RxNetty as its state will be altered. Hence create new
HttpClientRequest
<
ByteBuf
>
request
=
HttpClientRequest
.
createGet
(
"/"
);
// request for each server before the issue is addressed in RxNetty
client
.
submit
(
request
).
subscribe
(
observer
);
HttpRequest<ByteBuf> request = HttpRequest.createGet("/");
client.createFullHttpResponseObservable(request, null, null).subscribe(observer);
}
}
latch
.
await
();
latch
.
await
();
NettyHttpLoadBalancingClient lbClient = (NettyHttpLoadBalancingClient) client;
System
.
out
.
println
(
lb
.
getLoadBalancerStats
());
System.out.println(((AbstractLoadBalancer) lbClient.getLoadBalancer()).getLoadBalancerStats());
}
}
*/
}
}
ribbon-examples/src/main/java/com/netflix/ribbon/examples/netty/http/PostExample.java
已删除
100644 → 0
浏览文件 @
18772728
package
com.netflix.ribbon.examples.netty.http
;
import
com.netflix.ribbon.examples.ExampleAppWithLocalResource
;
public
class
PostExample
extends
ExampleAppWithLocalResource
{
@Override
public
void
run
()
throws
Exception
{
/*
Person myPerson = new Person("netty", 5);
HttpRequest<ByteBuf> request = HttpRequest.createPost(SERVICE_URI + "testAsync/person").withHeader("Content-type", "application/json")
.withContent(SerializationUtils.serializeToBytes(JacksonCodec.getInstance(), myPerson, null));
NettyHttpClient observableClient = NettyHttpClientBuilder.newBuilder().withClientConfig(DefaultClientConfigImpl.getClientConfigWithDefaultValues()
.setPropertyWithType(IClientConfigKey.CommonKeys.ReadTimeout, 10000)
.setPropertyWithType(IClientConfigKey.CommonKeys.ConnectTimeout, 2000))
.build();
observableClient.createEntityObservable("localhost", port, request, TypeDef.fromClass(Person.class), null).toBlockingObservable().forEach(new Action1<Person>() {
@Override
public void call(Person t1) {
try {
System.out.println(t1);
} catch (Exception e) { // NOPMD
}
}
}); */
}
public
static
void
main
(
String
[]
args
)
throws
Exception
{
new
PostExample
().
runApp
();
}
}
ribbon-examples/src/main/java/com/netflix/ribbon/examples/netty/http/SeverSentEventExample.java
已删除
100644 → 0
浏览文件 @
18772728
package
com.netflix.ribbon.examples.netty.http
;
import
com.netflix.ribbon.examples.ExampleAppWithLocalResource
;
public
class
SeverSentEventExample
extends
ExampleAppWithLocalResource
{
@Override
public
void
run
()
throws
Exception
{
/*
// Get the events and parse each data line using Jackson deserializer
IClientConfig overrideConfig = new DefaultClientConfigImpl().setPropertyWithType(CommonClientConfigKey.Deserializer, JacksonCodec.getInstance());
HttpRequest<ByteBuf> request = HttpRequest.createGet(SERVICE_URI + "testAsync/personStream");
NettyHttpClient observableClient = NettyHttpClientBuilder.newBuilder().build();
final List<Person> result = Lists.newArrayList();
observableClient.createServerSentEventEntityObservable("localhost", port, request, TypeDef.fromClass(Person.class), overrideConfig)
.subscribe(new Action1<ServerSentEventWithEntity<Person>>() {
@Override
public void call(ServerSentEventWithEntity<Person> t1) {
// System.out.println(t1);
result.add(t1.getEntity());
}
}, new Action1<Throwable>() {
@Override
public void call(Throwable t1) {
t1.printStackTrace();
}
});
Thread.sleep(2000);
System.out.println(result);
// Get the events as raw string
request = HttpRequest.createGet(SERVICE_URI + "testAsync/stream");
observableClient.createServerSentEventObservable("localhost", port, request)
.flatMap(new Func1<HttpResponse<ServerSentEvent>, Observable<ServerSentEvent>>() {
@Override
public Observable<ServerSentEvent> call(
HttpResponse<ServerSentEvent> t1) {
return t1.getContent();
}
}).toBlockingObservable()
.forEach(new Action1<ServerSentEvent>(){
@Override
public void call(ServerSentEvent t1) {
System.out.println(t1);
}
}); */
}
public
static
void
main
(
String
[]
args
)
throws
Exception
{
new
SeverSentEventExample
().
runApp
();
}
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录