当前位置: 首页 > news >正文

STORM_0007_Multi-Lang protocol of Storm/多语言协议的翻译

原始地址:

http://storm.apache.org/releases/1.0.1/Multilang-protocol.html
这个协议试用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内容
      2. {
            "conf": {
                "topology.message.timeout.secs": 3,
                // 各种的配置信息,可以按照上面的格式去写
            },
            "pidDir": "...",
            "context": {
                "task->component": {
                    "1": "example-spout",
                    "2": "__acker",
                    "3": "example-bolt1",
                    "4": "example-bolt2"
                },
                "taskid": 3,
                // 下面的设置仅仅试用0.10.0之后的版本
                "componentid": "example-bolt"
                "stream->target->grouping": {
                    "default": {
                        "example-bolt2": {
                            "type": "SHUFFLE"}}},
                "streams": ["default"],
                "stream->outputfields": {"default": ["word"]},
                "source->stream->grouping": {
                    "example-spout": {
                        "default": {
                            "type": "FIELDS",
                            "fields": ["word"]
                        }
                    }
                }
                "source->stream->fields": {
                    "example-spout": {
                        "default": ["word"]
                    }
                }
            }
        }
      3. 脚本应当能创建出一个名字为PID的空文件,这个文件使得supervisor知道PID可以在随后关闭进程
      4. 自从0.10.0之后的版本的shell组件能配置的context被提高了,基本上包含了所有的方面的内容,可以被JVM使用。重要的特征是:stream->target->grouping和source->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像这样
        {
            "command": "emit",
            // The id for the tuple. Leave this out for an unreliable emit. The id can
            // be a string or a number.
            "id": "1231231",
            // The id of the stream this tuple was emitted to. Leave this empty to emit to default stream.
            "stream": "1",
            // If doing an emit direct, indicate the task to send the tuple to
            "task": 9,
            // All the values in this tuple
            "tuple": ["field1", 2, 3]
        }
      3. logs像这样
        {
            "command": "log",
            // the message to log
            "msg": "hello world!"
        }
    4. 对STDOUT
      1. 用sync命令去使得发射和打日志停止
        {"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
      {
          // The tuple's id - this is a string to support languages lacking 64-bit precision
          "id": "-6955786537413359385",
          // The id of the component that created this tuple
          "comp": "1",
          // The id of the stream this tuple was emitted to
          "stream": "1",
          // The id of the task that created this tuple
          "task": 9,
          // All the values in this tuple
          "tuple": ["snow white and the seven dwarfs", "field2", 3]
      }
    3. 对STDOUT:是一个ack,fail,log,或者emit。
      1. 下面是个emit的例子
        {
            "command": "emit",
            // The ids of the tuples this output tuples should be anchored to
            "anchors": ["1231231", "-234234234"],
            // The id of the stream this tuple was emitted to. Leave this empty to emit to default stream.
            "stream": "1",
            // If doing an emit direct, indicate the task to send the tuple to
            "task": 9,
            // All the values in this tuple
            "tuple": ["field1", 2, 3]
        }
        如果不立即发射的话,你将接收到,发射流的task id。因为异步的特性,在读之后发射的话,可能收不到task id,可能会读取到上一个发射的task id或者新的发射进程。但是不管怎样,你将会按照发射的顺序接收到task id。
      2. ack的样子
        {
            "command": "ack",
            // the id of the tuple to ack
            "id": "123123"
        }
      3. fail的样子
        {
            "command": "fail",
            // the id of the tuple to fail
            "id": "123123"
        }
      4. log的样子
        {
            "command": "log",
            // the message to log
            "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总是定期的发送心跳包,格式如下
        {
            "id": "-6955786537413359385",
            "comp": "1",
            "stream": "__heartbeat",
            // this shell bolt's system task id
            "task": -1,
            "tuple": []
        }
        当子进程接收到心跳tuple的时候,会发送sync给ShellBolt

转载于:https://www.cnblogs.com/kongchung/p/5552091.html

相关文章:

  • Jquery 中map()函数的用法
  • 大公司都有哪些开源项目~~~简化版
  • Java 网络IO编程总结(BIO、NIO、AIO均含完整实例代码)
  • Arm开发板+Qt学习之路-multiple definition of
  • 清除windows系统垃圾文件简易脚本(bat)
  • 1225 八数码难题
  • ES6初探,什么是ES6
  • who命令
  • Android 采用Layout Inflater创建一个View对象
  • VS 类快捷键
  • /etc/motd and /etc/issue
  • java中的异常处理机制_函数覆盖时的异常特点
  • 关于狄克斯特拉算法(dijkstra)总结
  • CSS3实现两行或三行文字,然后多出的部分省略号代替
  • 函数与类
  • 《Java8实战》-第四章读书笔记(引入流Stream)
  • 11111111
  • 2017前端实习生面试总结
  • C语言笔记(第一章:C语言编程)
  • ES6核心特性
  • Java面向对象及其三大特征
  • Python实现BT种子转化为磁力链接【实战】
  • react 代码优化(一) ——事件处理
  • Redis提升并发能力 | 从0开始构建SpringCloud微服务(2)
  • RxJS: 简单入门
  • Traffic-Sign Detection and Classification in the Wild 论文笔记
  • Vue--数据传输
  • Webpack入门之遇到的那些坑,系列示例Demo
  • 给新手的新浪微博 SDK 集成教程【一】
  • 简单数学运算程序(不定期更新)
  • 解决jsp引用其他项目时出现的 cannot be resolved to a type错误
  • 适配iPhoneX、iPhoneXs、iPhoneXs Max、iPhoneXr 屏幕尺寸及安全区域
  • 微信小程序实战练习(仿五洲到家微信版)
  • 新手搭建网站的主要流程
  • 学习笔记:对象,原型和继承(1)
  • 译有关态射的一切
  • 优秀架构师必须掌握的架构思维
  • 主流的CSS水平和垂直居中技术大全
  • Prometheus VS InfluxDB
  • 通过调用文摘列表API获取文摘
  • ​ 全球云科技基础设施:亚马逊云科技的海外服务器网络如何演进
  • ​一帧图像的Android之旅 :应用的首个绘制请求
  • #if #elif #endif
  • #WEB前端(HTML属性)
  • #使用清华镜像源 安装/更新 指定版本tensorflow
  • #我与虚拟机的故事#连载20:周志明虚拟机第 3 版:到底值不值得买?
  • $.extend({},旧的,新的);合并对象,后面的覆盖前面的
  • ()、[]、{}、(())、[[]]等各种括号的使用
  • (C语言版)链表(三)——实现双向链表创建、删除、插入、释放内存等简单操作...
  • (echarts)echarts使用时重新加载数据之前的数据存留在图上的问题
  • (Python) SOAP Web Service (HTTP POST)
  • (草履虫都可以看懂的)PyQt子窗口向主窗口传递参数,主窗口接收子窗口信号、参数。
  • (附源码)计算机毕业设计ssm基于Internet快递柜管理系统
  • (免费领源码)Python#MySQL图书馆管理系统071718-计算机毕业设计项目选题推荐
  • (篇九)MySQL常用内置函数