Slide 8
Slide 8 text
Communication Client – RPC approach
• RPC approach
• Define interfaces in internal DSL (e.g. Traits and
annotations), and generate client/server codes
automatically
• Pros
• Straightforward and intuitive for Scalaist
• Less efforts
• Cons
• Implicit HTTP request/response
• Not Human-friendly
• Hard to incorporate HTTP ecosystem
(monitoring, load-balancing, authz/authn, etc.)
• Example
• autowire, OutWatch, airframe-rpc, etc.
case class Person(id: Int, name: String)
@RPC
trait MyService {
def hello(person: Person): String
}
class MyServiceImpl extends MyService {
override def hello(person: Person): String =
s"Hello ${person.name} (id=${person.id})!"
}
val client = new ServiceSyncClient(Http.client.newSyncClient(
"localhost:8080"))
client.myService.hello(Person(id=1, name="leo"))
Interface
Server
Client