用HTTP方式调用gearman任务处理
本来以为是个挺美好的东西,结果。。。
这样的方式非常不安全,尤其是假设暴露在公网地址,非常easy被攻击,并且gearman的http服务远没有专业的webserver健壮。
攻击方式非常easy:telnet host 8080,连接成功后,随便输入点内容,如:aaa,gearman日志就不停的出现例如以下错误信息:
bad request line:aaa
简直就是死循环,gearmand就顶不住了,系统内存也一会就被耗尽,说明http这块实现的有BUG。
只是能够通过改动源代码来修复这个BUG:
You can open file libgearman-server/plugins/protocol/http/protocol.cc , find 'bad request line:' and 'bad method:',
then chang 'GEARMAND_SUCCESS' to 'GEARMAND_INVALID_PACKET' after them. This way is quick for this bug.
也能够下载以下的补丁,对源patch:
https://bugs.launchpad.net/gearmand/+bug/1348865/+attachment/4182968/+files/gearmand-1.1.12.patch
gearmand-1.1.12源代码安装文件夹下运行:patch -p0 < ../gearmand-1.1.12.patch
该补丁攻克了上面的错误,同一时候也添加了对get方法的支持
bug信息參见:https://bugs.launchpad.net/gearmand/+bug/1348865
原文:
This protocol plugin allows you to map HTTP requests to Gearman jobs. It only provides client job submission currently, but it may be extended to support other request types in the future. The plugin can handle both GET and POST data, the latter being used
to send a workload to the job server. The URL being requested is translated into the function being called.
For example, the request:
POST /reverse HTTP/1.1
Content-Length: 12 Hello world!
Is translated into a job submission request for the function “reverse” and workload “Hello world!”. This will respond with:
HTTP/1.0 200 OK
X-Gearman-Job-Handle: H:lap:4
Content-Length: 12
Server: Gearman/0.8 !dlrow olleH
The following headers can be passed to change the behavior of the job:
* X-Gearman-Unique: <unique key>
* X-Gearman-Background: true
* X-Gearman-Priority: <high|low>
For example, to run a low priority background job, the following request can be sent:
POST /reverse HTTP/1.1
Content-Length: 12
X-Gearman-Background: true
X-Gearman-Priority: low Hello world!
The response for this request will not have any data associated with it since it was a background job:
HTTP/1.0 200 OK
X-Gearman-Job-Handle: H:lap:6
Content-Length: 0
Server: Gearman/0.8
The HTTP protocol should be considered experimental.
应用场景:
开启gearman http监听功能,让前端以web api方式调用gearman job
起用方式:
在gearmand的起动參数中加上:
/usr/local/gearman/sbin/gearmand \
-l /usr/local/gearman/log/trace.log \
--verbose INFO -p 4730 -u root -d -t 4 \
--http-port 8080 \
-r http
--http-port=8080 指定监听端口号
-r http 起用http协议模块
调用方式:
眼下http协议仅仅支持任务提交类接口,其他类型的暂不支持。
按官方文档上说,http支持GET和POS两种方式调用,可是GET方式我还没弄清楚如何携带数据,POST方式实验过是能够的
http://172.16.18.116:8080/reverse
reverse就为函数名,假如POST的数据内容为:“Hello world!”,返回结果为:“!dlrow olleH”
在http的header头中能够设置一些任务參数:
* X-Gearman-Unique: <unique key>
* X-Gearman-Background: true
* X-Gearman-Priority: <high|low>
这样的使用方式,实际上gearmand监听着两个端,原来的4730端还是能够接收正常的gearman协议client的请求,另外的8080port则监听着http协议的请求,两种方式共同工作,http服务前端如移动端调用,gearman服务内部的其他模块的调用。
用HTTP方式调用gearman任务处理的更多相关文章
- Atitit 动态调用webservice与客户端代理方式调用
Atitit 动态调用webservice与客户端代理方式调用 方式1: 使用call.invoke 直接调用WSDL,缺点:麻烦,不推荐--特别是JAVA调用.NET的WS时,会有不少的问题需要解 ...
- YbSoftwareFactory 代码生成插件【二十五】:Razor视图中以全局方式调用后台方法输出页面代码的三种方法
上一篇介绍了 MVC中实现动态自定义路由 的实现,本篇将介绍Razor视图中以全局方式调用后台方法输出页面代码的三种方法. 框架最新的升级实现了一个页面部件功能,其实就是通过后台方法查询数据库内容,把 ...
- HttpClient Get/Post方式调用Http接口
本节摘要:本节主要分别介绍如何用get方式.post方式向http接口发送数据. preparation 1. 项目环境如下: myeclipse6.5 .tomcat5.0.system:xp.JD ...
- C#以post方式调用struts rest-plugin service的问题
struts2: 玩转 rest-plugin一文中,学习了用struts2开发restful service的方法,发现用c#以post方式调用时各种报错,但java.ajax,包括firefox ...
- 反射-优化及程序集等(用委托的方式调用需要反射调用的方法(或者属性、字段),而不去使用Invoke方法)
反射-优化及程序集等(用委托的方式调用需要反射调用的方法(或者属性.字段),而不去使用Invoke方法) 创建Delegate (1).Delegate.CreateDelegate(Type, ...
- Matlab与C/C++联合编程之Matlab以MEX方式调用C代码(五)完整过程加示
如下为本人亲证代码: 一: 编译器的安装与配置(环境不同,显示结果不同) 要使用MATLAB编译器,用户计算机上应用事先安装与MATLAB适配的以下任何一种ANSI C/C++编译器: 5.0.6.0 ...
- JS方式调用本地的可执行文件
看到一个方法,有些用,先存下来,有用的时候再用. 前几天,在IE,FIREFOX中实现了用JS方式调用本地的可执行文件.地址:www.yihaomen.com/article/js/211.htm , ...
- AutoCAD.NET 不使用P/Invoke方式调用acad.exe或accore.dll中的接口(如acedCommand、acedPostCommand等)
使用C#进行AutoCAD二次开发,有时候由于C#接口不够完善,或者低版本AutoCAD中的接口缺少,有些工作不能直接通过C#接口来实现,所以需要通过P/Invoke的方式调用AutoCAD的其他DL ...
- 以WCF安全认证方式调用通用权限管理系统获取基础信息资料
在B/S开发中,涉及到获取系统基础资料的问题,因为是在不同平台下的开发,采用了WCF方式获取. 下面是一个调用通用权限管理系统(吉日嘎拉)基础信息资料的一个demo供参考 调用原理图: web.con ...
随机推荐
- oracle 表复制
1. 复制表结构及其数据: create table table_name_new as select * from table_name_old 2. 只复制表结构: ; 或者 create tab ...
- 基于visual Studio2013解决C语言竞赛题之0614递归大元素
题目 解决代码及点评 /************************************************************************/ /* 14. 编一个程 ...
- boost库中thread多线程详解2——mutex与lock
1. mutex对象类 mutex类主要有两种:独占式与共享式的互斥量.▲ 独占式互斥量:mutex: 独占式的互斥量,是最简单最常用的一种互斥量类型try_mutex: 它是mutex的同义词,为了 ...
- Collections在sort()简单分析法源
Collections的sort方法代码: public static <T> void sort(List<T> list, Comparator<? super T& ...
- 配置SAP 采购合同审批
需求: 采购合同类型是MK,采购组织是POSC,采购组PGC,标识:估计价格是空,总价有值0.00 - 9999999999.00 RMB 满足以上条件的时候需要审批该合同. 配置: spro-> ...
- jquery Deferred使用经验
这周做了个小活动(http://aoqi.100bt.com/zt-2016duanzi/index.html),刚开始时候没看好需求,逻辑都写一块了 最后各种坑要填补,从中也获取了些经验和教训,下面 ...
- Linux权限操作 [转]
Linux权限操作 本文内容来自<鸟哥linux私房菜>读后个人做的笔记,该书实为学习linux的很好入门教材 一.文件属性 ls ls -al列出所有的档案属性 ls是List的意思 档 ...
- rowid结构浅析
select rowid from dual AAAAB0AABAAAAOhAAA rowid结构如下: 对象号 文件号 块号 行号 XXXXXX XXX XXXXXX X ...
- Qt图片显示效率的比较 转
转http://blog.sina.com.cn/s/blog_5c70dfc80100r257.html 在Qt中处理图片一般都要用到QImage类,但是QImage的对象不能够直接显示出来,要想能 ...
- HDU 4350 Card
打表找规律,比赛应付了一下,其实还可以把内存再优化一半掉,下面的0都是手动填充的,可以优化掉 题意: T个测试数据 下面52个数字表示 从栈顶到栈底的52个数 n l r表示 从栈顶下数 [l,r] ...