Skip to content

Latest commit

History

23 Commits

Folders and files

NameName
Last commit message
Last commit date

Repository files navigation

Brisk - Lightweight RPC for Scala

  • minimalistic, less is more
  • BSON and Mongo style objects + syntactic sugar
  • clustering supported, no external tools needed (e.g. Zookeeper)
  • based on Netty, async/sync mode
  • Scala 2.10 ready (Future/Promise/Try, Dynamics)

Example

Basic single node scenario:

importutil.{Failure, Success}
objectBasicBriskExampleextendsApp {
valserver=newBrisk(8080) {
service("foo") {
in =>Message("status"->200, "time"->System.currentTimeMillis())
}
}
server.start()
valclient=Clients.create("localhost", 8080)
//sync invocation
client.invokeSync("foo") match {
caseSuccess(out) => {
println(out.status)
println(out.time)
}
caseFailure(e) =>throw e
}
//async invocationvalfuture= client.invoke("foo")
//....Await.result(future, 5 seconds) match {
caseSuccess(out) => {
println(out.status)
println(out.time)
}
caseFailure(e) =>throw e
}
server.stop()
client.destroy()
}

Clustered scenario:

objectClusteredBriskExampleextendsApp {
vals1=newClusteredBrisk(8080, "test-cluster") {
service("foo") {
in =>Message("node"->1, "status"->100, "time"->System.currentTimeMillis())
}
}
vals2=newClusteredBrisk(8081, "test-cluster") {
service("foo") {
in =>Message("node"->2, "status"->100, "time"->System.currentTimeMillis())
}
}
valservers=List(s1, s2)
servers.foreach(_.start())
valclient=Clients.clustered("test-cluster")
//by default it is round-robin
invoke()
invoke()
invoke()
client.destroy()
servers.foreach(_.stop())
definvoke() {
//sync invocation
client.invokeSync("foo") match {
caseSuccess(out) => {
println("node: "+ out.node)
}
caseFailure(e) =>throw e
}
}
}

See the source

Other examples:

//invoke across all serversvalall= client.invokeAll("foo")
//blocking await
all.foreach(Await.result(_, 5 seconds))

Predicates:

//async call across multiple servers//completion predicate -> at least 2 results collected//server predicate -> take all serversvalresult= client.invokeSpecific("foo", Message(), CountPredicate(2).atLeast, all)
...
valfoo= client.invokeSpecific("foo", Message(), CountPredicate(2).atLeastThat(message => message.status ==200, all)

See the tests

Install

sbt

Dependencies:

"com.github.brisk" %% "brisk" % "1.0-SNAPSHOT"

Repos:

"sonatype-snapshots" at "https://oss.sonatype.org/content/groups/public"

About

Lightweight RPC for Scala

Resources

Stars

16 stars

Watchers

3 watching

Forks

Releases

Packages

Contributors

Languages