pangiole / akka-wamp

WAMP - Web Application Messaging Protocol implementation written with Akka
Other
47 stars 12 forks source link

Provide dynamic invocation with kwargs deserialization #41

Open pangiole opened 7 years ago

pangiole commented 7 years ago

You can register a procedure URI with a partially applied function as handler.

val registration: Future[Registration] = session.flatMap(
  _.register(
    procedure = "myapp.procedure.sum",
    handler = sum _ ))

Akka Wamp will dinamically invoke the partially applied function you provide (e.g. sum _) upon receiving invocations addressed to the registered procedure URI (e.g. "myapp.procedure.sum"). It will lazily deserialize the args list from incoming payloads by using its default type bindings.

Notice
Lazy deserialization from incoming kwargs and dynamic invocation passing input values to named arguments is not yet supported

pangiole commented 7 years ago

Having the following registration in place:

def sum(a: Int, b: Int) = a + b

val registration: Future[Registration] = session.flatMap(
  _.register(
    procedure = "myapp.procedure.sum",
    handler = sum _ ))

// registration.id == 4

The the following JSON invocation message:

[68,9,4,{},[],{"a":45,"b":25}]

would make AkkaWamp invoke sum(45, 25)