WAMP - Web Application Messaging Protocol implementation written with Akka
Scala Java
Latest commit c40c7c6 Jan 14, 2017 @angiolep committed on GitHub Delete publish.sh

README.md

Akka Wamp

Build Status CodeCov Status Gitter

Akka Wamp is a WAMP - Web Application Messaging Protocol implementation written to let both Scala and Java developers build the next generation of reactive web services on top of Akka abstractions.

Akka Wamp provides you with:

  • Simple Client APIs designed to be used with Akka actors, futures and streams.
  • Object-oriented representations of all WAMP Messages,
  • Akka IO extenson driver for the WAMP Protocol.
  • Basic Router you can embed in your applications or launch as standalone process.

Usage

Easy to download as dependency from Maven central:

libraryDependencies ++= Seq(
  "com.github.angiolep" % "akka-wamp_2.12" % "0.13.0"
)

Docs

  • User's guide, code fragments and dozens of examples are published here.
  • API doc is published here

Client APIs

Connect to a router, open a session, subscribe to a topic, consume events, register a remote procedure and call it in few lines of Scala or Java code.

  • Actors, Futures and Streams based APIs.
  • Lambda consumers and handlers support.
  • Lazy and pluggable deserializers.
  • Java 8 support.
  • ... and much more!

Please, read the docs for further details

Java client

Though written in Scala, Akka Wamp provides simple client APIs for Java developers as well. Compared to other WAMP implementations, Akka Wamp will let you write less code for much more functionalities!

import akka.actor.*;
import akka.wamp.client.japi.*;

import static java.util.Array.asList;
import static java.lang.System.out;

public class JavaClient {
  public static void main(String[] arr) {
    ActorSystem actorSystem = ActorSystem.create();

    Client client = Client.create(actorSystem);
    client.connect("default").thenAccept(c -> {
      c.open("myrealm").thenAccept(s -> {

        s.publish("mytopic", asList("Ciao!"));

        s.subscribe("mytopic", (event) -> {
          event.args().thenAccept(args -> {
            out.println("got " + args.get(0));
          });
        });

        s.register("myproc", (invoc) -> {
          return invoc.args().thenApply(args -> {
            Integer a = (Integer) args.get(0);
            Integer b = (Integer) args.get(1);
            Integer result = a + b;
            return Payload.create(asList(result));
          });
        });

        s.call("myproc", asList(20, 55)).thenAccept(res -> {
          res.args().thenAccept(args -> {
            out.println("20 * 55 = " + args.get(0));  
          });
        });
      });
    });
  }
}

Scala client

Akka Wamp provides Scala developer with great support to let them write "no boilerplate code" at all! Just few statements and here it is a fully capable reactive WAMP client ;-)

import akka.actor._
import akka.wamp.client._

object ScalaClient extends App {

  val system = ActorSystem()
  val client = Client(system)
  implicit val executionContext = system.dispatcher

  client.connect(transport = "default").map { c =>
    c.open(realm = "hello").map { implicit s =>

      subscribe("mytopic", (arg: Int) => {
        println(s"got $arg")
      })

      publish("mytopic", List("Ciao!"))

      call("myproc", List(20, 55)).foreach { res =>
        res.args.foreach { args =>
          println(s"20 * 55 = ${args(0)}")
        }
      }

      register("myproc", (a: Int, b: Int) => {
        a + b
      })
    }
  }
}

Router

Download

Akka Wamp provides you with a basic router that can be either embedded into your application or launched as standalone server process.

Download the latest router version, extract, configure and run it as standalone application:

curl https://dl.bintray.com/angiolep/universal/akka-wamp-0.13.0.tgz
tar xvfz akka-wamp-0.13.0.tar.gz
cd akka-wamp-0.13.0
vim ./conf/application.conf
./bin/akka-wamp -Dakka.loglevel=DEBUG

Limitations

  • Java >= 1.8.0
  • Scala >= 2.12.1
  • WebSocket transport only (no raw TCP and no SSL/TLS yet)
  • WAMP Basic Profile only (none of the Advanced Profile features yet)
  • JSON serialization only (no MsgPack yet)
  • Not yet ready for production

Changelog

Please, read CHANGELOG.md

Contributing

Please, read CONTRIBUTING.md

Licence

This software comes with Apache License 2.0

Disclaimer

This SOFTWARE PRODUCT is provided by THE PROVIDER "as is" and "with all faults." THE PROVIDER makes no representations or warranties of any kind concerning the safety, suitability, lack of viruses, inaccuracies, typographical errors, or other harmful components of this SOFTWARE PRODUCT. There are inherent dangers in the use of any software, and you are solely responsible for determining whether this SOFTWARE PRODUCT is compatible with your equipment and other software installed on your equipment. You are also solely responsible for the protection of your equipment and backup of your data, and THE PROVIDER will not be liable for any damages you may suffer in connection with using, modifying, or distributing this SOFTWARE PRODUCT