Search in sources :

Example 6 with KxReactiveStreams

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);
}
Also used : IntStream(java.util.stream.IntStream) ActorMaterializerSettings(akka.stream.ActorMaterializerSettings) PublisherSink(akka.stream.impl.PublisherSink) Publisher(org.reactivestreams.Publisher) Source(akka.stream.javadsl.Source) Sink(akka.stream.javadsl.Sink) Materializer(akka.stream.Materializer) Test(org.junit.Test) KxPublisher(org.nustaq.kontraktor.reactivestreams.KxPublisher) KxReactiveStreams(org.nustaq.kontraktor.reactivestreams.KxReactiveStreams) SubscriberSink(akka.stream.impl.SubscriberSink) WebSocketPublisher(org.nustaq.kontraktor.remoting.http.undertow.WebSocketPublisher) RateMeasure(org.nustaq.kontraktor.util.RateMeasure) CountDownLatch(java.util.concurrent.CountDownLatch) ActorMaterializer(akka.stream.ActorMaterializer) RxReactiveStreams(rx.RxReactiveStreams) Ignore(org.junit.Ignore) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) ActorSystem(akka.actor.ActorSystem) Log(org.nustaq.kontraktor.util.Log) Actors(org.nustaq.kontraktor.Actors) WebSocketConnectable(org.nustaq.kontraktor.remoting.websockets.WebSocketConnectable) Assert(org.junit.Assert) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) WebSocketPublisher(org.nustaq.kontraktor.remoting.http.undertow.WebSocketPublisher) KxReactiveStreams(org.nustaq.kontraktor.reactivestreams.KxReactiveStreams) RateMeasure(org.nustaq.kontraktor.util.RateMeasure) CountDownLatch(java.util.concurrent.CountDownLatch) WebSocketConnectable(org.nustaq.kontraktor.remoting.websockets.WebSocketConnectable) Test(org.junit.Test)

Example 7 with KxReactiveStreams

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);
}
Also used : ActorSystem(akka.actor.ActorSystem) IntStream(java.util.stream.IntStream) ActorMaterializerSettings(akka.stream.ActorMaterializerSettings) PublisherSink(akka.stream.impl.PublisherSink) Publisher(org.reactivestreams.Publisher) Source(akka.stream.javadsl.Source) Sink(akka.stream.javadsl.Sink) Materializer(akka.stream.Materializer) Test(org.junit.Test) KxPublisher(org.nustaq.kontraktor.reactivestreams.KxPublisher) KxReactiveStreams(org.nustaq.kontraktor.reactivestreams.KxReactiveStreams) SubscriberSink(akka.stream.impl.SubscriberSink) WebSocketPublisher(org.nustaq.kontraktor.remoting.http.undertow.WebSocketPublisher) RateMeasure(org.nustaq.kontraktor.util.RateMeasure) CountDownLatch(java.util.concurrent.CountDownLatch) ActorMaterializer(akka.stream.ActorMaterializer) RxReactiveStreams(rx.RxReactiveStreams) Ignore(org.junit.Ignore) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) ActorSystem(akka.actor.ActorSystem) Log(org.nustaq.kontraktor.util.Log) Actors(org.nustaq.kontraktor.Actors) WebSocketConnectable(org.nustaq.kontraktor.remoting.websockets.WebSocketConnectable) Assert(org.junit.Assert) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) KxReactiveStreams(org.nustaq.kontraktor.reactivestreams.KxReactiveStreams) RateMeasure(org.nustaq.kontraktor.util.RateMeasure) Publisher(org.reactivestreams.Publisher) KxPublisher(org.nustaq.kontraktor.reactivestreams.KxPublisher) WebSocketPublisher(org.nustaq.kontraktor.remoting.http.undertow.WebSocketPublisher) CountDownLatch(java.util.concurrent.CountDownLatch) Materializer(akka.stream.Materializer) ActorMaterializer(akka.stream.ActorMaterializer) Test(org.junit.Test)

Aggregations

CountDownLatch (java.util.concurrent.CountDownLatch)7 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)7 KxReactiveStreams (org.nustaq.kontraktor.reactivestreams.KxReactiveStreams)7 RateMeasure (org.nustaq.kontraktor.util.RateMeasure)7 ActorSystem (akka.actor.ActorSystem)6 ActorMaterializer (akka.stream.ActorMaterializer)6 ActorMaterializerSettings (akka.stream.ActorMaterializerSettings)6 Materializer (akka.stream.Materializer)6 PublisherSink (akka.stream.impl.PublisherSink)6 SubscriberSink (akka.stream.impl.SubscriberSink)6 Sink (akka.stream.javadsl.Sink)6 Source (akka.stream.javadsl.Source)6 IntStream (java.util.stream.IntStream)6 Assert (org.junit.Assert)6 Ignore (org.junit.Ignore)6 Test (org.junit.Test)6 Actors (org.nustaq.kontraktor.Actors)6 KxPublisher (org.nustaq.kontraktor.reactivestreams.KxPublisher)6 WebSocketPublisher (org.nustaq.kontraktor.remoting.http.undertow.WebSocketPublisher)6 WebSocketConnectable (org.nustaq.kontraktor.remoting.websockets.WebSocketConnectable)6