writing an api client with akka http

Stockfighter is a CTF (short for Capture the Flag) game that I first heard about at Microconf 2015, but haven’t gotten a chance to play up until very recently. I plan on posting more about my impressions of the game later, but very shortly: it is a series of programming challenges based on the concept of stock exchanges and ways to manipulate stock exchanges. Along with the web UI, a public json API is exposed as a mechanism for interacting with the game. There did not seem to be any Scala clients floating around, so I took this as a chance to play around with akka-http.

Read more

Akka Streaming学习

时至今日,我们从因特尔上消遣服务包含许多流媒体数据(streaming data),包括下载、上传、点对点的数据传送。把数据整体看做是一个元素集合的流(a stream of elements),对我们计算机发送和接收这些数据起了很大帮助,因为数据变得越来越庞大,以“流”的方式处理数据显得很有必要。

Actors看起来也可以处理“流”:它们顺序地接收一系列消息,并对消息进行传输。但我们发现,在actor之间要实现一个stable streaming,会显得冗余乏味(tedious)和易出错(error-prone),因为在处理发送(sending)和接收(receiving)时,我们还需要担心buffer溢出或邮箱溢出问题。另外一个陷阱(pitfall)是,Actor的消息会丢失,对丢失的消息要进行转发,以免stream一直停留在receiving的那一方。当处理完streams,Actor不能担保不会有连接(wiring)错误的出现。

Read more

Akka Reactive Streams

Akka Streams have these key properties:

  • They implement the Reactive Streams specification, whose three main goals backpressure, async and non-blocking boundaries and interoperability between different implementations do fully apply for Akka Streams too.
  • They provide an abstraction for an evaluation engine for the streams, which is called Materializer.
  • Programs are formulated as reusable building blocks, which are represented as the three main types Source, Sink and Flow. The building blocks form a graph whose evaluation is based on the Materializer and needs to be explicitly triggered.
    In the following a deeper introduction in how to use the three main types shall be given.
Read more

Scala中的Future和ExecutionContext

Scala 这个语言可以用得很复杂、也可以用得很简洁。它在 Java 并发和 OO 之上做了进一步的抽象,将代码量大大降低。
最近流行的很多项目都使用 Scala,比如 Akka,Spark,Kafka,Spray,Play Framework,足见它是一门生产力很高的语言。
这里主要总结了下一些并发模式和并发线程池需要注意的地方。

Read more