package client
Contains classes, traits, types and functions to be used to implement WAMP clients in Scala.
Please refer to the official Akka Wamp User's Guide published online for further details.
Actors
Is the low level Client API.
Futures
Is the high level Client API
import akka.actor._ import akka.wamp.client._ import com.typesafe.config._ val config = ConfigFactory.load("my.conf") val system = ActorSystem("myapp", config) val client = Client(system) client.connect("myrouter").foreach { conn => conn.open("myrealm").foreach { implicit s => publish("mytopic", List("paolo", 99)) subscribe("mytopic", (name: String, age: Int) = { println(s"$name is $age years old") } call("myprocedure", List("paolo", 99)) register("myprocedure", (name: String, age: Int) => { name.length + age }) } }
Streams
TBD
- See also
akka.wamp.client.japi for Java API
- Alphabetic
- By Inheritance
- client
- AnyRef
- Any
- Hide All
- Show All
- Public
- All
Type Members
-
class
Client
extends Peer
Represents a client.
Represents a client.
Instances can be created using its companion object.
val client = ... val session = for { conn <- client.connect("myrouter") session <- conn.open("myrealm") } yield(session)
- See also
- trait ClientActor extends Actor with SessionIdScope
-
case class
ClientException
(message: String, cause: Throwable) extends Throwable with Product with Serializable
Represents an error
-
class
Connection
extends wamp.Connection
Represents a connection established by a client to a router.
Represents a connection established by a client to a router.
Instances can be obtained by invoking the Client!.connect()* method.
val client = ... val conn = client.connect("myrouter")
Named transports can be configured as follows:
akka.wamp.client.transport { myrouter { url = "wss://router.host.net:8443/wamp" format = "msgpack" min-backoff = 3 seconds max-backoff = 30 seconds random-factor = 0.2 } }
Once connected you can open a Session.
val session = conn.flatMap(c => c.open("myrealm"))
-
class
Publication
extends AnyRef
Is an acknowledged publication.
Is an acknowledged publication.
Instance are obtained by invoking the Session.publish method
val publication: Future[Subscription] = session.flatMap { s => s.publishAck("mytopic", List("paolo", 40)) } publication.onComplete { case Success(pb) => log.info("Published to {} with {}", pb.topic, pb.id) case Failure(ex) => log.warning("Not published because of {}", ex.getMessage) }
-
class
Registration
extends AnyRef
Represents an acknowledged registration.
Represents an acknowledged registration.
Instance are obtained by invoking the Session.register method
val registration: Future[Registration] = session.flatMap { s => s.register("myprocedure", invocation => { // handle invocation ... // return future of payload ... }) } registration.onComplete { case Success(rg) => log.info("Registered {} with {}", rg.procedure, rg.id) case Failure(ex) => log.warning("Not registered because of {}", ex.getMessage) }
-
class
Session
extends wamp.Session with SessionIdScope
Represents a session attached to a realm.
Represents a session attached to a realm.
Open
Instances are created either by invoking the Connection.open or the Client.open method
val conn: Future[Connection] = ... val session: Future[Session] = conn.flatMap(c => c.open("myrealm"))
Topics
Once the session is open, you can publish to topics.
val publication: Future[Publication] = session.flatMap { s => s.publish("mytopic", List("paolo", 40)) }
Or you can subscribe event consumers to topics.
val subscription: Future[Subscription] = session.flatMap { s => s.subscribe("mytopic", event => { val publicationId = event.publicationId val subscriptionId = event.subscriptionId val details = event.details val payload = event.payload // consume payload content ... }) }
Procedures
Once opened, you can call procedures.
val result: Future[Result] = session.flatMap(s => s.call("myprocedure", List("paolo", 99)))
Or you can register invocation handlers as procedures.
val registration: Future[Registration] = session.flatMap { s => s.register("myprocedure", invocation => { val registrationId = invocation.registrationId val details = event.details val payload = event.payload // handle payload content ... // return future of payload ... }) }
Macros
You can subscribe/register lambda consumers/handlers to make your code look more functional ;-)
val subscription: Future[Subscription] = session.flatMap { implicit s => publish("mytopic", List("paolo", 40)) subscribe("mytopic", (name: String, age: Int) => { println(s"$name is $age years old") }) register("myprocedure", (name: String, age: Int) => { name.length + age }) }
-
class
Subscription
extends AnyRef
Represents an acknowledged subscription.
Represents an acknowledged subscription.
Instance are obtained by invoking the Session.subscribe method
val subscription: Future[Subscription] = session.flatMap { s => s.subscribe("mytopic", event => { // consume event ... }) } subscription.onComplete { case Success(sb) => log.info("Subscribed to {} with {}", sb.topic, sb.id) case Failure(ex) => log.warning("Not subscribed because of {}", ex.getMessage) }
Value Members
-
def
call(procedure: Uri, kwargs: Map[String, Any])(implicit session: Session): Future[Result]
Calls the given procedure with the given dictionary of named arguments
Calls the given procedure with the given dictionary of named arguments
- procedure
is the procedure to be called
- kwargs
the dictionary of named arguments
- session
is the session
- returns
the (future of) result
-
def
call(procedure: Uri, args: List[Any])(implicit session: Session): Future[Result]
Calls the given procedure with the given list of indexed arguments
Calls the given procedure with the given list of indexed arguments
- procedure
is the procedure to be called
- args
the list of indexed arguments
- session
is the session
- returns
the (future of) result
-
def
call(procedure: Uri)(implicit session: Session): Future[Result]
Calls the given procedure
Calls the given procedure
- procedure
is the procedure to be called
- session
is the session
- returns
the (future of) result
-
def
publish(topic: Uri, args: List[Any])(implicit session: Session): Unit
Publish to a topic (fire and forget)
Publish to a topic (fire and forget)
- topic
is the topic to publish to
- args
is the list of indexed arguments to be published
-
def
publish(topic: Uri, kwargs: Map[String, Any])(implicit session: Session): Unit
Publish to a topic (fire and forget)
Publish to a topic (fire and forget)
- topic
is the topic to publish to
- kwargs
is the dictionary of named arguments to be published
-
def
publish(topic: Uri)(implicit session: Session): Unit
Publish to a topic (fire and forget)
Publish to a topic (fire and forget)
- topic
is the topic to publish to
-
macro
def
register[T1, T2, T3, T4, R](procedure: Uri, lambda: (T1, T2, T3, T4) ⇒ R): Future[Registration]
Subscribe a 4-parameters lambda handler as the given procedure.
Subscribe a 4-parameters lambda handler as the given procedure.
- procedure
is the procedure to register as
- lambda
is the lambda handler to register
- returns
the (future) of registration
-
macro
def
register[T1, T2, T3, R](procedure: Uri, lambda: (T1, T2, T3) ⇒ R): Future[Registration]
Subscribe a 3-parameters lambda handler as the given procedure.
Subscribe a 3-parameters lambda handler as the given procedure.
- procedure
is the procedure to register as
- lambda
is the lambda handler to register
- returns
the (future) of registration
-
macro
def
register[T1, T2, R](procedure: Uri, lambda: (T1, T2) ⇒ R): Future[Registration]
Subscribe a 2-parameters lambda handler as the given procedure.
Subscribe a 2-parameters lambda handler as the given procedure.
- procedure
is the procedure to register as
- lambda
is the lambda handler to register
- returns
the (future) of registration
-
macro
def
register[T1, R](procedure: Uri, lambda: (T1) ⇒ R): Future[Registration]
Subscribe a 1-parameter lambda handler as the given procedure.
Subscribe a 1-parameter lambda handler as the given procedure.
- procedure
is the procedure to register as
- lambda
is the lambda handler to register
- returns
the (future) of registration
-
macro
def
register[R](procedure: Uri, lambda: () ⇒ R): Future[Registration]
Subscribe a 0-parameters lambda handler as the given procedure.
Subscribe a 0-parameters lambda handler as the given procedure.
- procedure
is the procedure to register as
- lambda
is the lambda handler to register
- returns
the (future) of registration
-
macro
def
subscribe[T1, T2, T3, T4](topic: Uri, lambda: (T1, T2, T3, T4) ⇒ Unit): Future[Subscription]
Subscribe a 4-parameters lambda consumer to the given topic.
Subscribe a 4-parameters lambda consumer to the given topic.
- topic
is the topic to subscribe to
- lambda
is the lambda consumer to subscribe
- returns
the (future) of subscription
-
macro
def
subscribe[T1, T2, T3](topic: Uri, lambda: (T1, T2, T3) ⇒ Unit): Future[Subscription]
Subscribe a 3-parameters lambda consumer to the given topic.
Subscribe a 3-parameters lambda consumer to the given topic.
- topic
is the topic to subscribe to
- lambda
is the lambda consumer to subscribe
- returns
the (future) of subscription
-
macro
def
subscribe[T1, T2](topic: Uri, lambda: (T1, T2) ⇒ Unit): Future[Subscription]
Subscribe a 2-parameters lambda consumer to the given topic.
Subscribe a 2-parameters lambda consumer to the given topic.
- topic
is the topic to subscribe to
- lambda
is the lambda consumer to subscribe
- returns
the (future) of subscription
-
macro
def
subscribe[T](topic: Uri, lambda: (T) ⇒ Unit): Future[Subscription]
Subscribe a 1-parameter lambda consumer to the given topic.
Subscribe a 1-parameter lambda consumer to the given topic.
- topic
is the topic to subscribe to
- lambda
is the lambda consumer to subscribe
- returns
the (future) of subscription
-
macro
def
subscribe(topic: Uri, lambda: () ⇒ Unit): Future[Subscription]
Subscribe a 0-parameters lambda consumer to the given topic.
Subscribe a 0-parameters lambda consumer to the given topic.
- topic
is the topic to subscribe to
- lambda
is the lambda consumer to subscribe
- returns
the (future) of subscription
-
object
Client
Factory for Client instances.
Factory for Client instances.
import akka.actor._ import akka.wamp.client._ import com.typesafe.config._ val config = ConfigFactory.load("my.conf") val system = ActorSystem("myapp", config) val client = Client(system)
The client factory requires you to pass an ActorSystem properly named and configured via a Configuration.
- See also
-
object
Macros
Provides implementations for macros
Provides implementations for macros
Subscribe
val session: Future[Session] = .... session.flatMap { implicit s => subscribe("mytopic", (name: String, age: Int) => { println(s"$name is $age years old") }) }
Register
val session: Future[Session] = .... session.flatMap { implicit s => register("myprocedure", (name: String, age: Int) => { name.length + age }) }