akka-wamp
akka-wamp copied to clipboard
WAMP - Web Application Messaging Protocol implementation written with Akka
Akka Wamp
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.15.1"
)
Docs
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("endpoint").thenAccept(c -> {
c.open("realm").thenAccept(s -> {
s.publish("topic", asList("Ciao!"));
s.subscribe("topic", (event) -> {
out.println("got " + event.args().get(0));
});
s.register("procedure", (invoc) -> {
Integer a = (Integer) invoc.args().get(0);
Integer b = (Integer) invoc.args().get(1);
return a + b;
});
s.call("procedure", asList(20, 55)).thenAccept(res -> {
out.println("20 * 55 = " + res.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("endpoint").map { conn =>
conn.open("realm").map { implicit session =>
subscribe("topic", (arg: Int) => {
println(s"got $arg")
})
publish("topic", List("Ciao!"))
call("procedure", List(20, 55)).foreach { res =>
println(s"20 * 55 = ${res.args(0)}")
}
register("procedure", (a: Int, b: Int) => {
a + b
})
}
}
}
Router
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.15.2.tgz
tar xvfz akka-wamp-0.15.2.tar.gz
cd akka-wamp-0.15.2
vim ./conf/application.conf
./bin/akka-wamp -Dakka.loglevel=DEBUG
Limitations
- Java >= 1.8.0
- Scala >= 2.12.0
- Akka >= 2.5.0
- WebSocket transport only (no raw TCP)
- 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