微服務框架:Colossus

jopen 10年前發布 | 23K 次閱讀 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)
  }
}

項目主頁:http://www.baiduhome.net/lib/view/home/1416387161305

 本文由用戶 jopen 自行上傳分享,僅供網友學習交流。所有權歸原作者,若您的權利被侵害,請聯系管理員。
 轉載本站原創文章,請注明出處,并保留原始鏈接、圖片水印。
 本站是一個以用戶分享為主的開源技術平臺,歡迎各類分享!