use of org.nustaq.kontraktor.reactivestreams.KxReactiveStreams in project kontraktor by RuedigerMoeller.
the class AkkaInterop method kontraktorRemoteKontraktor.
@Test
public void kontraktorRemoteKontraktor() throws InterruptedException {
Log.setLevel(Log.DEBUG);
final int NUM_MSG = 20_000_000;
KxReactiveStreams kxStreams = KxReactiveStreams.get();
RateMeasure rm = new RateMeasure("rate");
CountDownLatch count = new CountDownLatch(NUM_MSG);
Iterable it = () -> IntStream.range(0, NUM_MSG).mapToObj(x -> x).iterator();
Publisher<Integer> pub = kxStreams.produce(it.iterator());
kxStreams.asKxPublisher(pub).serve(new WebSocketPublisher().hostName("localhost").port(6789).urlPath("not_akka"));
// subscribe with akka client
KxPublisher<Integer> remotedPublisher = new KxReactiveStreams(true).connect(Integer.class, new WebSocketConnectable().url("ws://localhost:6789/not_akka"));
remotedPublisher.subscribe((res, err) -> {
if (Actors.isResult(err)) {
rm.count();
count.countDown();
}
});
int secondsWait = 50;
while (count.getCount() > 0 && secondsWait-- > 0) {
System.out.println("count:" + count.getCount());
Thread.sleep(1000);
}
Assert.assertTrue(count.getCount() == 0);
// give time closing stuff
Thread.sleep(1000);
}
use of org.nustaq.kontraktor.reactivestreams.KxReactiveStreams in project kontraktor by RuedigerMoeller.
the class AkkaInterop method kontraktorConsumes.
@Test
public void kontraktorConsumes() throws InterruptedException {
final int NUM_MSG = 50_000_000;
final ActorSystem system = ActorSystem.create("reactive-interop");
final Materializer mat = ActorMaterializer.create(system);
KxReactiveStreams kxStreams = KxReactiveStreams.get();
RateMeasure rm = new RateMeasure("rate");
CountDownLatch count = new CountDownLatch(NUM_MSG);
Iterable it = () -> IntStream.range(0, NUM_MSG).mapToObj(x -> x).iterator();
Publisher<Integer> pub = (Publisher<Integer>) Source.from(it).runWith(Sink.publisher(), mat);
kxStreams.asKxPublisher(pub).subscribe((res, err) -> {
if (Actors.isResult(err)) {
rm.count();
count.countDown();
}
});
int secondsWait = 50;
while (count.getCount() > 0 && secondsWait-- > 0) {
System.out.println("count:" + count.getCount());
Thread.sleep(1000);
}
system.shutdown();
Assert.assertTrue(count.getCount() == 0);
// give time closing stuff
Thread.sleep(1000);
}
Aggregations