• Stars
    star
    118
  • Rank 299,866 (Top 6 %)
  • Language
    Java
  • License
    Apache License 2.0
  • Created about 10 years ago
  • Updated about 8 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

RxJava bindings for Apache HTTP

rxjava-apache-http

Observable API for Apache HttpAsyncClient

It is aware of Content-Type text/event-stream and will stream each event via Observer.onNext.

Other Content-Types will be returned as a single call to Observer.onNext.

Main Classes:

Binaries

Binaries and dependency information for Maven, Ivy, Gradle and others can be found at http://search.maven.org.

Example for Maven:

<dependency>
    <groupId>com.netflix.rxjava</groupId>
    <artifactId>rxjava-apache-http</artifactId>
    <version>x.y.z</version>
</dependency>

and for Ivy:

<dependency org="com.netflix.rxjava" name="rxjava-apache-http" rev="x.y.z" />

Sample Usage

Create a Request

ObservableHttp.createGet("http://www.wikipedia.com", httpClient).toObservable();
ObservableHttp.createRequest(HttpAsyncMethods.createGet("http://www.wikipedia.com"), httpClient).toObservable();

Http Client

A basic default client:

CloseableHttpAsyncClient httpClient = HttpAsyncClients.createDefault();

or a custom client with configuration options:

final RequestConfig requestConfig = RequestConfig.custom()
        .setSocketTimeout(3000)
        .setConnectTimeout(500).build();
final CloseableHttpAsyncClient httpclient = HttpAsyncClients.custom()
        .setDefaultRequestConfig(requestConfig)
        .setMaxConnPerRoute(20)
        .setMaxConnTotal(50)
        .build();

Normal Http GET

Execute a request and transform the byte[] reponse to a String:

        ObservableHttp.createRequest(HttpAsyncMethods.createGet("http://www.wikipedia.com"), client)
        .toObservable()
        .flatMap({ ObservableHttpResponse response ->
                return response.getContent().map({ byte[] bb ->
                        return new String(bb);
                });
        })
        .toBlockingObservable()
        .forEach({ String resp -> 
                // this will be invoked once with the response
                println(resp);
        });

Streaming Http GET with Server-Sent Events (text/event-stream) Response

Execute a request and transform the byte[] response of each event to a String:

        ObservableHttp.createRequest(HttpAsyncMethods.createGet("http://hostname/event.stream"), client)
        .toObservable()
        .flatMap({ ObservableHttpResponse response ->
                return response.getContent().map({ byte[] bb ->
                        return new String(bb);
                });
        })
        .toBlockingObservable()
        .forEach({ String resp -> 
                // this will be invoked for each event
                println(resp);
        });

An example event-stream is from Hystrix used for streaming metrics. An example webapp can be used to test.

Output looks like:

data: {"type":"HystrixCommand","name":"CreditCardCommand","group":"CreditCard","currentTime":1379823924934,"isCircuitBreakerOpen":false,"errorPercentage":0,"errorCount":0,"requestCount":0,"rollingCountCollapsedRequests":0,"rollingCountExceptionsThrown":0,"rollingCountFailure":0,"rollingCountFallbackFailure":0,"rollingCountFallbackRejection":0,"rollingCountFallbackSuccess":0,"rollingCountResponsesFromCache":0,"rollingCountSemaphoreRejected":0,"rollingCountShortCircuited":0,"rollingCountSuccess":0,"rollingCountThreadPoolRejected":0,"rollingCountTimeout":0,"currentConcurrentExecutionCount":0,"latencyExecute_mean":0,"latencyExecute":{"0":0,"25":0,"50":0,"75":0,"90":0,"95":0,"99":0,"99.5":0,"100":0},"latencyTotal_mean":0,"latencyTotal":{"0":0,"25":0,"50":0,"75":0,"90":0,"95":0,"99":0,"99.5":0,"100":0},"propertyValue_circuitBreakerRequestVolumeThreshold":20,"propertyValue_circuitBreakerSleepWindowInMilliseconds":5000,"propertyValue_circuitBreakerErrorThresholdPercentage":50,"propertyValue_circuitBreakerForceOpen":false,"propertyValue_circuitBreakerForceClosed":false,"propertyValue_circuitBreakerEnabled":true,"propertyValue_executionIsolationStrategy":"THREAD","propertyValue_executionIsolationThreadTimeoutInMilliseconds":3000,"propertyValue_executionIsolationThreadInterruptOnTimeout":true,"propertyValue_executionIsolationThreadPoolKeyOverride":null,"propertyValue_executionIsolationSemaphoreMaxConcurrentRequests":10,"propertyValue_fallbackIsolationSemaphoreMaxConcurrentRequests":10,"propertyValue_metricsRollingStatisticalWindowInMilliseconds":10000,"propertyValue_requestCacheEnabled":true,"propertyValue_requestLogEnabled":true,"reportingHosts":1}
data: {"type":"HystrixCommand","name":"GetPaymentInformationCommand","group":"PaymentInformation","currentTime":1379823924934,"isCircuitBreakerOpen":false,"errorPercentage":0,"errorCount":0,"requestCount":0,"rollingCountCollapsedRequests":0,"rollingCountExceptionsThrown":0,"rollingCountFailure":0,"rollingCountFallbackFailure":0,"rollingCountFallbackRejection":0,"rollingCountFallbackSuccess":0,"rollingCountResponsesFromCache":0,"rollingCountSemaphoreRejected":0,"rollingCountShortCircuited":0,"rollingCountSuccess":0,"rollingCountThreadPoolRejected":0,"rollingCountTimeout":0,"currentConcurrentExecutionCount":0,"latencyExecute_mean":0,"latencyExecute":{"0":0,"25":0,"50":0,"75":0,"90":0,"95":0,"99":0,"99.5":0,"100":0},"latencyTotal_mean":0,"latencyTotal":{"0":0,"25":0,"50":0,"75":0,"90":0,"95":0,"99":0,"99.5":0,"100":0},"propertyValue_circuitBreakerRequestVolumeThreshold":20,"propertyValue_circuitBreakerSleepWindowInMilliseconds":5000,"propertyValue_circuitBreakerErrorThresholdPercentage":50,"propertyValue_circuitBreakerForceOpen":false,"propertyValue_circuitBreakerForceClosed":false,"propertyValue_circuitBreakerEnabled":true,"propertyValue_executionIsolationStrategy":"THREAD","propertyValue_executionIsolationThreadTimeoutInMilliseconds":1000,"propertyValue_executionIsolationThreadInterruptOnTimeout":true,"propertyValue_executionIsolationThreadPoolKeyOverride":null,"propertyValue_executionIsolationSemaphoreMaxConcurrentRequests":10,"propertyValue_fallbackIsolationSemaphoreMaxConcurrentRequests":10,"propertyValue_metricsRollingStatisticalWindowInMilliseconds":10000,"propertyValue_requestCacheEnabled":true,"propertyValue_requestLogEnabled":true,"reportingHosts":1}

More Repositories

1

RxJava

RxJava – Reactive Extensions for the JVM – a library for composing asynchronous and event-based programs using observable sequences for the Java VM.
Java
47,865
star
2

rxjs

A reactive programming library for JavaScript
TypeScript
30,686
star
3

RxSwift

Reactive Programming in Swift
Swift
24,267
star
4

RxAndroid

RxJava bindings for Android
Java
19,889
star
5

RxKotlin

RxJava bindings for Kotlin
Kotlin
7,036
star
6

RxGo

Reactive Extensions for the Go language.
Go
4,921
star
7

RxPY

ReactiveX for Python
Python
4,775
star
8

rxdart

The Reactive Extensions for Dart
Dart
3,338
star
9

RxCpp

Reactive Extensions for C++
C++
3,008
star
10

RxPHP

Reactive extensions for PHP
PHP
1,685
star
11

learnrx

A series of interactive exercises for learning Microsoft's Reactive Extensions Library for Javascript.
JavaScript
1,403
star
12

RxNetty

Reactive Extension (Rx) Adaptor for Netty
Java
1,384
star
13

IxJS

The Interactive Extensions for JavaScript
TypeScript
1,297
star
14

RxRuby

Reactive Extensions for Ruby
Ruby
957
star
15

RxScala

RxScala – Reactive Extensions for Scala – a library for composing asynchronous and event-based programs using observable sequences
Scala
888
star
16

RxJavaFX

RxJava bindings for JavaFX
Java
520
star
17

RxRust

The Reactive Extensions for the Rust Programming Language
Rust
488
star
18

RxClojure

RxJava bindings for Clojure
Clojure
362
star
19

rxjs-tslint

TSLint rules targeting RxJS
TypeScript
309
star
20

RxJavaReactiveStreams

Adapter between RxJava and ReactiveStreams
Java
235
star
21

RxJavaDebug

Java
161
star
22

rxjs-docs

The home for new work on the new RxJS docs (RxJS v 5 and up). New to this space? Say hi here: https://github.com/ReactiveX/rxjs-docs/issues/24. Want to find out what's up? We're chatting here. https://github.com/ReactiveX/rxjs-docs/issues/4
TypeScript
160
star
23

RxGroovy

RxJava bindings for Groovy
Groovy
158
star
24

reactivex.github.io

ReactiveX Website
JavaScript
139
star
25

RxJavaAsyncUtil

Java
132
star
26

RxJavaString

Java
129
star
27

RxJavaJoins

Java
100
star
28

RxSwing

RxJava bindings for Swing
Java
98
star
29

RxJavaMath

Math operators for RxJava.
Java
96
star
30

rxjs-advent-2018

RxJS 2018 Advent Calendar
TypeScript
89
star
31

rxjs-core-notes

Notes from RxJS core meetings
77
star
32

RxJavaFileUtils

File utilities with RxJava
Java
62
star
33

RxJavaComputationExpressions

Java
60
star
34

RxJavaGuava

Java
54
star
35

RxJavaParallel

Experimental Parallel Extensions for RxJava
Java
54
star
36

RxJRuby

RxJava bindings for JRuby
Ruby
38
star
37

Rx.NET

Rx.NET – Reactive Extensions for .NET – a library for composing asynchronous and event-based programs using observable sequences for the CLR.
31
star
38

RxQuasar

RxJava bindings for Quasar
Java
16
star
39

RxRoboVM

RxJava bindings for iOS
Java
7
star
40

BuildInfrastructure

Test project for the new build system.
Groovy
5
star
41

RxSwing2

Reactive bindings for Java 8 Swing on top of RxJava 2
4
star