Samza任务类必须实现StreamTask,可选 InitableTask, ClosableTask,WindowableTask
StreamTask
|
|
IncomingMessageEnvelop
代表接收到的消息的封装,表示StreamTask收到一个分区的一个特定的输入流。包括:
- message
- key
- 消息来源(system+stream+partition)12345678910public class IncomingMessageEnvelope {/** A deserialized message. */Object getMessage() { ... }/** A deserialized key. */Object getKey() { ... }/** The stream and partition that this message came from. */SystemStreamPartition getSystemStreamPartition() { ... }}
SystemStreamPartition
消息来源包括:
- 消息来源system名
- 消息来源stream/topic/queue名
- 消息流的分区1234567891011121314/** A triple of system name, stream name and partition. */public class SystemStreamPartition extends SystemStream {/** The name of the system which provides this stream. It isdefined in the Samza job's configuration. */public String getSystem() { ... }/** The name of the stream/topic/queue within the system. */public String getStream() { ... }/** The partition within the stream. */public Partition getPartition() { ... }}
MessageCollector
为了发送一个消息, 你会创建一个OutgoingMessageEnvelop对象并且把它传递给消息收集器。它至少会确定你想要发送的消息、系统和数据流名字再发送出去。你也可以确定分区的key和另一些参数。
注意:
请只在process()方法里使用MessageCollector对象。如果你保持住一个MessageCollector实例并且之后再次使用它,你的消息可能会错误地发送出去。
OutgoingMessageEnvelope
|
|
InitableTask
用来处理初始化工作,init 函数会首先被调用
ClosableTask
|
|
WindowableTask
|
|
实例
有一个简单的任务,它把每个输入的消息拆成单词,并且发送每一个单词作为一个消息
参考:
https://samza.apache.org/learn/documentation/0.10/
https://github.com/feuyeux/hello-samza/blob/master/doc/0.hello_samza.md
http://wdxtub.com/vault/cc-21.html
http://www.infoq.com/cn/articles/linkedin-samza
http://blog.csdn.net/colorant/article/details/12082145
https://wyyhzc.gitbooks.io/hadoop2x/content/samzacontainer.html