微服务框架:Colossus
Colossus 是 Tumblr 出品的一个轻量级的框架用来构建高性能的应用,使用非堵塞网络 I/O。Colossus 主要侧重于开发低延迟、无状态的微服务,这个服务可以是一个简单的数据库或者缓存的抽象。Colossus 通过简单化实现最大化的性能需求。
Clean Event-based Programming
Built directly on NIO, Colossus is a modern take on event-based programming that fully leverages the functional and object-oriented features of Scala. Write powerful applications with minimal boilerplate.
Seamless Integration with Akka
Written entirely as Akka actors, Colossus makes it easy to connect your low-level event-handling code with external actors. Colossus also comes with a fully actor-based API if you wish to keep all your code inside actors.
Real-time Metrics
Colossus comes with a metrics aggregation and reporting system that makes it easy to track events in real-time. Common metrics like request rates and latency are built into services out of the box, and it's easy to add your own. A SQL-like DSL allows you to filter and aggregate over these metrics, while a reporting module lets you package and export metrics to an external database like OpenTSDB.
Write More than Just Services
While Colossus has primarily been built with microservices in mind, at the heart is a simple wrapper on NIO that is fully accessible for you to write your own custom servers and clients. Furthermore, Colossus Tasks let you write arbitrary code inside event loops when you need to do I/O outside the context of a server.
一个简单的服务:
import colossus._ import service._ import protocols.http._ import UrlParsing._ import HttpMethod._ object Main extends App { implicit val io_system = IOSystem() Service.become[Http]("http-echo", 9000){ case request @ Get on Root => request.ok("Hello world!") case request @ Get on Root / "echo" / str => request.ok(str) } }