Search in sources :

Example 6 with WebSocketConnectable

use of org.nustaq.kontraktor.remoting.websockets.WebSocketConnectable in project kontraktor by RuedigerMoeller.

the class MyServiceClient method main.

public static void main(String[] args) {
    if (args == null || args.length == 0) {
        MyServiceClient cl = AsActor(MyServiceClient.class);
        cl.init(new WebSocketConnectable().url("ws://localhost:6667/myservice/v1/bin").serType(SerializerType.FSTSer).actorClass(IMyService.class)).then((r, e) -> {
            if (e != null) {
                Log.Error(MyServiceClient.class, (Throwable) e);
            }
        });
    } else {
        MyServiceClient cl = AsActor(MyServiceClient.class);
        cl.init(new WebSocketConnectable().url("ws://localhost:6667/myservice/v1/json").serType(SerializerType.JsonNoRef).actorClass(IMyService.class)).then((r, e) -> {
            if (e != null) {
                Log.Error(MyServiceClient.class, (Throwable) e);
            }
        });
    }
}
Also used : WebSocketConnectable(org.nustaq.kontraktor.remoting.websockets.WebSocketConnectable)

Example 7 with WebSocketConnectable

use of org.nustaq.kontraktor.remoting.websockets.WebSocketConnectable in project kontraktor by RuedigerMoeller.

the class UntypedGreeterClient method main.

// NOTE: due to a temporary bug in 4.03, untyped java clients DO NOT WORK
// with Java-implemented Servers. Use typed clients meanwhile
public static void main(String[] args) {
    Actor remote = (Actor) new WebSocketConnectable().actorClass(Actor.class).url("ws://localhost:3999").serType(SerializerType.JsonNoRef).connect((x, y) -> System.out.println("disconnect " + x + " " + y)).await();
    remote.ask("greet", "Kontraktor", 1000).then((r, e) -> System.out.println(r));
}
Also used : Actor(org.nustaq.kontraktor.Actor) WebSocketConnectable(org.nustaq.kontraktor.remoting.websockets.WebSocketConnectable)

Example 8 with WebSocketConnectable

use of org.nustaq.kontraktor.remoting.websockets.WebSocketConnectable in project kontraktor by RuedigerMoeller.

the class MyService method main.

public static void main(String[] args) {
    MyServiceArgs conf = new MyServiceArgs();
    JCommander.newBuilder().addObject(conf).build().parse(args);
    MyService serv = AsActor(MyService.class);
    serv.init();
    conf.connectUrls.forEach(url -> {
        Routing.registerService(new WebSocketConnectable().url(url).serType(url.endsWith("/bin") ? SerializerType.FSTSer : SerializerType.JsonNoRef), serv, x -> serv.disconnedtedCB(x), true).then((r, e) -> {
            if (e != null) {
                Log.Info(MyService.class, "error connecting krouter " + e);
                if (e instanceof Throwable)
                    Log.Info(MyService.class, (Throwable) e);
            } else
                Log.Info(MyService.class, "MyService connected krouter " + url);
        });
    });
}
Also used : java.util(java.util) SerializerType(org.nustaq.kontraktor.remoting.encoding.SerializerType) JCommander(com.beust.jcommander.JCommander) ChangeMessage(microservice.pub.ChangeMessage) Local(org.nustaq.kontraktor.annotations.Local) IMyService(microservice.pub.IMyService) Callback(org.nustaq.kontraktor.Callback) IPromise(org.nustaq.kontraktor.IPromise) Routing(org.nustaq.kontraktor.routers.Routing) Item(microservice.pub.Item) Actor(org.nustaq.kontraktor.Actor) Log(org.nustaq.kontraktor.util.Log) WebSocketConnectable(org.nustaq.kontraktor.remoting.websockets.WebSocketConnectable) IMyService(microservice.pub.IMyService) WebSocketConnectable(org.nustaq.kontraktor.remoting.websockets.WebSocketConnectable)

Example 9 with WebSocketConnectable

use of org.nustaq.kontraktor.remoting.websockets.WebSocketConnectable in project kontraktor by RuedigerMoeller.

the class RemotingTest method testWSJSR.

// fixme: add connect-from-actor tests
// fixme: add minbin tests
// fixme: increase basic test coverage
@Test
@Ignore
public void testWSJSR() throws Exception {
    checkSequenceErrors = true;
    RemotingTestService service = Actors.AsActor(RemotingTestService.class, Q_SIZE);
    ActorServer publisher = _JSR356ServerConnector.Publish(service, "ws://localhost:8081/ws", null).await();
    RemotingTestService client = (RemotingTestService) new WebSocketConnectable(RemotingTestService.class, "ws://localhost:8081/ws").connect().await(9999999);
    CountDownLatch latch = new CountDownLatch(1);
    runWithClient(client, latch);
    latch.await();
    // wait for outstanding callbacks
    Thread.sleep(2000);
    publisher.close();
}
Also used : ActorServer(org.nustaq.kontraktor.remoting.base.ActorServer) CountDownLatch(java.util.concurrent.CountDownLatch) WebSocketConnectable(org.nustaq.kontraktor.remoting.websockets.WebSocketConnectable) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 10 with WebSocketConnectable

use of org.nustaq.kontraktor.remoting.websockets.WebSocketConnectable in project kontraktor by RuedigerMoeller.

the class AkkaInterop method serveAkka_RemoteToKontraktor.

@Test
public void serveAkka_RemoteToKontraktor() 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).serve(new WebSocketPublisher().hostName("localhost").port(6790).urlPath("akka"));
    // subscribe with kontraktor client
    new KxReactiveStreams(true).connect(Integer.class, new WebSocketConnectable().url("ws://localhost:6790/akka")).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) 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) WebSocketConnectable(org.nustaq.kontraktor.remoting.websockets.WebSocketConnectable) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) WebSocketPublisher(org.nustaq.kontraktor.remoting.http.undertow.WebSocketPublisher) KxReactiveStreams(org.nustaq.kontraktor.reactivestreams.KxReactiveStreams) Materializer(akka.stream.Materializer) ActorMaterializer(akka.stream.ActorMaterializer) Test(org.junit.Test)

Aggregations

WebSocketConnectable (org.nustaq.kontraktor.remoting.websockets.WebSocketConnectable)25 Test (org.junit.Test)10 WebSocketPublisher (org.nustaq.kontraktor.remoting.http.undertow.WebSocketPublisher)10 CountDownLatch (java.util.concurrent.CountDownLatch)9 RateMeasure (org.nustaq.kontraktor.util.RateMeasure)7 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)6 SerializerType (org.nustaq.kontraktor.remoting.encoding.SerializerType)6 Log (org.nustaq.kontraktor.util.Log)6 Assert (org.junit.Assert)5 Ignore (org.junit.Ignore)5 Actor (org.nustaq.kontraktor.Actor)5 Actors (org.nustaq.kontraktor.Actors)5 KxPublisher (org.nustaq.kontraktor.reactivestreams.KxPublisher)5 KxReactiveStreams (org.nustaq.kontraktor.reactivestreams.KxReactiveStreams)5 HttpConnectable (org.nustaq.kontraktor.remoting.http.HttpConnectable)5 Publisher (org.reactivestreams.Publisher)5 RxReactiveStreams (rx.RxReactiveStreams)5 ActorSystem (akka.actor.ActorSystem)4 ActorMaterializer (akka.stream.ActorMaterializer)4 ActorMaterializerSettings (akka.stream.ActorMaterializerSettings)4