-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
47 additions
and
57 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,49 +1,43 @@ | ||
package com.rolandkuhn.rsinterop; | ||
|
||
import org.reactivestreams.Publisher; | ||
|
||
|
||
|
||
import akka.actor.ActorSystem; | ||
import akka.stream.FlowMaterializer; | ||
import akka.stream.javadsl.Sink; | ||
import akka.stream.javadsl.Source; | ||
import org.reactivestreams.Publisher; | ||
import ratpack.http.ResponseChunks; | ||
import ratpack.rx.RxRatpack; | ||
import ratpack.test.embed.EmbeddedApp;import reactor.rx.Stream; | ||
import ratpack.test.embed.EmbeddedApp; | ||
import reactor.rx.Stream; | ||
import reactor.rx.Streams; | ||
import rx.Observable; | ||
import rx.RxReactiveStreams; | ||
|
||
|
||
public class JavaMain { | ||
|
||
public static void main(String[] args) { | ||
final ActorSystem system = ActorSystem.create("InteropTest"); | ||
final FlowMaterializer mat = FlowMaterializer.create(system); | ||
RxRatpack.initialize(); | ||
|
||
EmbeddedApp.fromHandler(ctx -> { | ||
final Integer[] ints = new Integer[10]; | ||
for (int i = 0; i < ints.length; ++i) { | ||
ints[i] = i; | ||
} | ||
// RxJava Observable | ||
final Observable<Integer> intObs = Observable.from(ints); | ||
// Reactive Streams Publisher | ||
final Publisher<Integer> intPub = RxReactiveStreams.toPublisher(intObs); | ||
// Akka Streams Source | ||
final Source<String> stringSource = Source.from(intPub).map(Object::toString); | ||
// Reactive Streams Publisher | ||
final Publisher<String> stringPub = stringSource.runWith(Sink.<String>fanoutPublisher(1, 1), mat); | ||
// Reactor Stream | ||
final Stream<String> linesStream = Streams.create(stringPub).map(i -> i + "\n"); | ||
// and now render the HTTP response | ||
ctx.render(ResponseChunks.stringChunks(linesStream)); | ||
}).test(client -> { | ||
final String text = client.getText(); | ||
System.out.println(text); | ||
system.shutdown(); | ||
});; | ||
} | ||
public static void main(String... args) throws Exception { | ||
ActorSystem system = ActorSystem.create("InteropTest"); | ||
FlowMaterializer mat = FlowMaterializer.create(system); | ||
RxRatpack.initialize(); | ||
|
||
EmbeddedApp.fromHandler(ctx -> { | ||
final Integer[] ints = new Integer[10]; | ||
for (int i = 0; i < ints.length; ++i) { | ||
ints[i] = i; | ||
} | ||
// RxJava Observable | ||
final Observable<Integer> intObs = Observable.from(ints); | ||
// Reactive Streams Publisher | ||
final Publisher<Integer> intPub = RxReactiveStreams.toPublisher(intObs); | ||
// Akka Streams Source | ||
final Source<String> stringSource = Source.from(intPub).map(Object::toString); | ||
// Reactive Streams Publisher | ||
final Publisher<String> stringPub = stringSource.runWith(Sink.<String>fanoutPublisher(1, 1), mat); | ||
// Reactor Stream | ||
final Stream<String> linesStream = Streams.create(stringPub).map(i -> i + "\n"); | ||
// and now render the HTTP response | ||
ctx.render(ResponseChunks.stringChunks(linesStream)); | ||
}).test(client -> | ||
System.out.println(client.getText()) | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters