原始地址:

这个协议试用0.7.1之后的版本
 
通过ShellBolt和ShellSpout和ShellProcess类实现了对多中语言的支持
这些类实现了IBolt和ISpout接口,也实现了通过shell使用java的ProcessBuilder类执行脚本或者程序的协议
 
在java中使用这个协议的时候需要创建继承ShellBolt的的bolt也要使用declareOutputFields声明output fields
 
一个简单的协议,可以通过能按照JSON格式解码的STDIN和STDOUT描述
这样可以支持绝大多数的语言
 
要想在集群上运行shell脚本,这个脚本要位于提交的jar包的resources/目录下
但是在本地模式开发和测试的时候,shell资源的地址可以只是在classpath中
 
  • 所有的协议的结束都使用一种line-reading机制,所以确保从输入修剪掉新行,并附加到输出上
  • 所有的JSON类型的输入和输出都被任何一行含有end的行终结,确保不要出现在JSON中被解析出来。
 
下面的一些点事简单的STDIN和STDOUT描述的需要注意的地方
  1. Initial Handshake
    1. 初始化握手适合各种类型的shell组件
    2. 对STDIN:设置一些info
      1. 这是一个JSON对象,包含配置,PID目录,和一个topo内容
        1. {
        2. "conf": {
        3. "topology.message.timeout.secs": 3,
        4. // 各种的配置信息,可以按照上面的格式去写
        5. },
        6. "pidDir": "...",
        7. "context": {
        8. "task->component": {
        9. "1": "example-spout",
        10. "2": "__acker",
        11. "3": "example-bolt1",
        12. "4": "example-bolt2"
        13. },
        14. "taskid": 3,
        15. // 下面的设置仅仅试用0.10.0之后的版本
        16. "componentid": "example-bolt"
        17. "stream->target->grouping": {
        18. "default": {
        19. "example-bolt2": {
        20. "type": "SHUFFLE"}}},
        21. "streams": ["default"],
        22. "stream->outputfields": {"default": ["word"]},
        23. "source->stream->grouping": {
        24. "example-spout": {
        25. "default": {
        26. "type": "FIELDS",
        27. "fields": ["word"]
        28. }
        29. }
        30. }
        31. "source->stream->fields": {
        32. "example-spout": {
        33. "default": ["word"]
        34. }
        35. }
        36. }
        37. }
        1. 脚本应当能创建出一个名字为PID的空文件,这个文件使得supervisor知道PID可以在随后关闭进程
        1. 自从0.10.0之后的版本的shell组件能配置的context被提高了,基本上包含了所有的方面的内容,可以被JVM使用。重要的特征是:stream->target->groupingsource->stream->grouping可以分别可以决定输入源和输出目标
    3. STDOUT:使用{"pid":1234}可以将PID打日志到log中。
  2. Spouts
    1. Shell Spout是同步的,要是没有输入就一直在while循环中休息
    2. 对STDIN
      1. next是ISpout的nextTuple,这样使用:{"command":"next"}
      2. ack这样使用{"command":"ack","id":"1231231"}
      3. fail这样使用{"command":"fail","id":"1231231"}
    3. 对STDOUT
      1. 结果可能是发射的东西或者是logs序列
      2. emit像这样
        1. {
        2. "command": "emit",
        3. // The id for the tuple. Leave this out for an unreliable emit. The id can
        4. // be a string or a number.
        5. "id": "1231231",
        6. // The id of the stream this tuple was emitted to. Leave this empty to emit to default stream.
        7. "stream": "1",
        8. // If doing an emit direct, indicate the task to send the tuple to
        9. "task": 9,
        10. // All the values in this tuple
        11. "tuple": ["field1", 2, 3]
        12. }
      3. logs像这样
        1. {
        2. "command": "log",
        3. // the message to log
        4. "msg": "hello world!"
        5. }
    4. 对STDOUT
      1. 用sync命令去使得发射和打日志停止

        1. {"command": "sync"}

        直到发送另外的next或者ack或者fail指令的时候,ShellSpout才读取你的输出 和ISpout一样,如果没有流要发射的时候,应该在sync之前sleep一下,因为ShellSpout不会自动的sleep

  3. Bolts
    1. Shell Bolt协议是异步的,一旦STDIN的流可用时候你将收到这个流,你可以在任何时候写到STDOUT上,通过发射,ack,fail,log等
    2. 对STDIN:是一个tuple但是是JSON类型的tuple
      1. {
      2. // The tuple's id - this is a string to support languages lacking 64-bit precision
      3. "id": "-6955786537413359385",
      4. // The id of the component that created this tuple
      5. "comp": "1",
      6. // The id of the stream this tuple was emitted to
      7. "stream": "1",
      8. // The id of the task that created this tuple
      9. "task": 9,
      10. // All the values in this tuple
      11. "tuple": ["snow white and the seven dwarfs", "field2", 3]
      12. }
    3. 对STDOUT:是一个ack,fail,log,或者emit。
      1. 下面是个emit的例子

        1. {
        2. "command": "emit",
        3. // The ids of the tuples this output tuples should be anchored to
        4. "anchors": ["1231231", "-234234234"],
        5. // The id of the stream this tuple was emitted to. Leave this empty to emit to default stream.
        6. "stream": "1",
        7. // If doing an emit direct, indicate the task to send the tuple to
        8. "task": 9,
        9. // All the values in this tuple
        10. "tuple": ["field1", 2, 3]
        11. }

        如果不立即发射的话,你将接收到,发射流的task id。因为异步的特性,在读之后发射的话,可能收不到task id,可能会读取到上一个发射的task id或者新的发射进程。但是不管怎样,你将会按照发射的顺序接收到task id。

      2. ack的样子
        1. {
        2. "command": "ack",
        3. // the id of the tuple to ack
        4. "id": "123123"
        5. }
      3. fail的样子
        1. {
        2. "command": "fail",
        3. // the id of the tuple to fail
        4. "id": "123123"
        5. }
      4. log的样子
        1. {
        2. "command": "log",
        3. // the message to log
        4. "msg": "hello world!"
        5. }
  4. Handling Heartbeats(0.9.3之后的版本)
    1. 在storm0.9.3中,心跳已经被使用在ShellSpout或者ShellBolt和他们的多语言的子进程中,去监测这些子进程的hanging和zombie
    2. 对于Spout
      1. 因为是同步的,子进程总是在next()的最后发送sync,所以不用做太多去支持心跳的检测。但是在next()中不能让子进程sleep的时间超过timeout。
    3. 对于bolt
      1. 因为是异步的,所以ShellBolt总是定期的发送心跳包,格式如下

        1. {
        2. "id": "-6955786537413359385",
        3. "comp": "1",
        4. "stream": "__heartbeat",
        5. // this shell bolt's system task id
        6. "task": -1,
        7. "tuple": []
        8. }

        当子进程接收到心跳tuple的时候,会发送sync给ShellBolt

STORM_0007_Multi-Lang protocol of Storm/多语言协议的翻译的更多相关文章

  1. IMAP(Internet Mail Access Protocol,Internet邮件访问协议)以前称作交互邮件访问协议(Interactive Mail Access Protocol)。

    IMAP(Internet Mail Access Protocol,Internet邮件访问协议)以前称作交互邮件访问协议(Interactive Mail Access Protocol).IMA ...

  2. Caused by: java.lang.ClassNotFoundException: backtype.storm.topology.IRichSpout

    1:初次运行Strom程序出现如下所示的错误,贴一下,方便脑补,也希望帮助到看到的小伙伴: 错误如下所示,主要问题是刚开始使用maven获取jar包的时候需要写<scope>provide ...

  3. TFTP(Trivial File Transfer Protocol,简单文件传输协议)

    TFTP(Trivial File Transfer Protocol,简单文件传输协议),是 TCP/IP 协议族中用来在客户机和服务器之间进行简单文件传输的协议,开销很小.这时候有人可能会纳闷,既 ...

  4. ICMP(Internet Control Message Protocol)网际控制报文协议初识

    ICMP是(Internet Control Message Protocol)Internet控制报文协议.它是TCP/IP协议族的一个子协议,用于在IP主机.路由器之间传递控制消息.控制消息是指网 ...

  5. 多点触摸(MT)协议(翻译)

    参考: http://www.kernel.org/doc/Documentation/input/multi-touch-protocol.txt 转自:http://www.arm9home.ne ...

  6. yaml语言在线可视化翻译

    yaml语言在线可视化翻译 https://editor.swagger.io/

  7. Impala SQL 语言元素(翻译)[转载]

    原 Impala SQL 语言元素(翻译) 本文来源于http://my.oschina.net/weiqingbin/blog/189413#OSC_h2_2 摘要 http://www.cloud ...

  8. Go语言使用百度翻译api

    Go语言使用百度翻译api 之前做过一个使用百度翻译api的工具,这个工具用于用户的自动翻译功能,是使用C#调用百度翻译api接口,既然在学习Go语言,那必然也是要使用Go来玩耍一番.这里我是这么安排 ...

  9. 在centos 6.9下Protocol Buffers数据传输及存储协议的使用(python)

    我们知道Protocol Buffers是Google定义的一种跨语言.跨平台.可扩展的数据传输及存储的协议,因为将字段协议分别放在传输两端,传输数据中只包含数据本身,不需要包含字段说明,所以传输数据 ...

随机推荐

  1. TI CC254x BLE教程 2

    连接更新请求(connection update request) 如果slave不满意现有的连接参数, 比如间隔, 延迟等等, 可以向master提出自己希望的参数范围 连接终止(connectio ...

  2. php的ssh2扩展安装

    折腾半天,结论如下: 1.先需要openssl 用which openssl看是否已安装 2.然后libssh2 用rpm -ql libssh2查看 3.下载源码的shh2x.x.x.tgz的包 4 ...

  3. iptables的四表五链

    iptables只是Linux防火墙的管理工具而已,位于/sbin/iptables.真正实现防火墙功能的是netfilter,它是Linux内核中实现包过滤的内部结构. iptables包含4个表, ...

  4. mount源码分析 【转】

    转自:http://blog.chinaunix.net/uid-10769062-id-3230811.html Busybox- 在util-linux/mount.c的line:1609行首先映 ...

  5. ant 使用指南---java模块化编译【转】

    转自:http://www.cnblogs.com/hoojo/archive/2013/06/14/java_ant_project_target_task_run.html 一.概述 ant 是一 ...

  6. 在CentOS之上搭建VMware Player 7

    1.下载VMware-Player-7.1.2安装包 百度网盘下载地址: 链接:http://pan.baidu.com/s/1nudfo6H 密码:oemc 直接下载地址: https://down ...

  7. sqlite加密

    一直使用sqlite来管理本地的数据,但是Xcode中的SDK中集成的sqlite是免费的,不提供加密模块,但是程序中用到的很多数据,有时候是不想让别人看到,一开始虑修改sqlite的源码,自己重新编 ...

  8. 为ecshop红包增加”转赠”功能

    ecshop促销中使用红包激励用户购物,要想炒热活动,红包就需要有物以稀为贵的感觉.有人求有人送,这样红包之间的转赠有助于拉动第二梯队的顾客.但是如果已经把红包添加到自己的账户了怎么办?如果ecsho ...

  9. 字符编码的过滤器Filter(即输入的汉字,能在页面上正常显示,不会出现乱码)

    自定义抽象的 HttpFilter类, 实现自 Filter 接口 package com.lanqiao.javaweb; import java.io.IOException; import ja ...

  10. hiho 第119周 最大权闭合子图

    描述 周末,小Hi和小Ho所在的班级决定举行一些班级建设活动. 根据周内的调查结果,小Hi和小Ho一共列出了N项不同的活动(编号1..N),第i项活动能够产生a[i]的活跃值. 班级一共有M名学生(编 ...