15

Akka入门系列(七):akka kafka Producer

 3 years ago
source link: http://edisonxu.com/2018/11/30/akka-kafka-producer.html
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

Akka Stream

在用Akka去对接Kafka之前,有必要先简单了解下Akka Stream,它是基于Reactive Stream(Akka是其创立成员之一)的。Akka Stream中,将流的拓扑处理逻辑命名为Graph,拓扑中每个操作命名为Operator
它将流式处理抽象为几个核心API:

  • Source : 有且仅有一个Output的operator,对应数据的来源,将数据反序列化后发送给下游逻辑。
  • Sink : 有且仅有一个Input的operator,对应最终数据的去向,常用于结果存储。
  • Flow : 有且仅有一个Input和Output的operator,用于定义数据的处理逻辑。
  • RunnableGraph : 一个对接了SourceSink,并且已经准备好run()Flow。一般用source.to(sink)source.runWith(sink, materializer)构成一个RunnableGraph,可通过via(flow)添加其他flow
  • Materializer : 这个SPI(Service Provider Interface)是根据前面定义的graph进行资源申请,生成相应Actor类,然后进行执行的。这篇博文从源码级对它的原理进行了阐述,写的相当透彻,就不再重复了。

Akka Kafka核心API

如果您觉得文章不错,可以请我喝一杯咖啡!
actor, akka, kafka, 分布式, 并发

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK