[文章作者:张宴 本文版本:v1.0 最后修改:2011.07.26 转载请注明原文链接:http://blog.zyan.cc/httpsqs_1_7/]

  HTTPSQS(HTTP Simple Queue Service)是一款基于 HTTP GET/POST 协议的轻量级开源简单消息队列服务,使用 Tokyo Cabinet 的 B+Tree Key/Value 数据库来做数据的持久化存储。

  项目网址http://code.google.com/p/httpsqs/
  使用文档http://blog.zyan.cc/httpsqs/
  使用环境:Linux(同时支持32位、64位操作系统,推荐使用64位操作系统)
  软件作者:张宴



  HTTPSQS 1.7 版本更新内容:

  下面的内容不只是介绍 HTTPSQS 1.7 更新了哪些东西,更多的介绍在于:如何绕开 Libevent 2.0.x evhttp 使用过程中,无法正常处理包含“|”字符的 URI 参数的问题;提供了一份比 Libevent 官方网站更新的在线文档;Linux 下如何动态编译程序,运行时不用在 /etc/ld.so.conf 文件中添加动态链接库路径。

  1、针对 Libevent 2.0.x 版本 evhttp_parse_query 函数的 BUG。

  网友发邮件,反应了一个 HTTPSQS 的 BUG,见下图,data 的值为NULL。我查找发现,这不是 HTTPSQS 的 BUG,而是 Libevent 2.0.x 版本的 BUG。在 Libevent 1.4.14b 版本中,evhttp_parse_query 函数是能够正常处理包含“|”字符的 URI 的,而在 Libevent 2.0.12 版本中,同样使用 evhttp_parse_query 函数,包含“|”字符的 URI  处理后的结果是 NULL。

  点击在新窗口中浏览此图片

  对比 Libevent 2.0.12 和 1.4.14b 版本的 evhttp_parse_query 函数代码,发现在 2.0.12 版本中,evhttp_parse_query(const char *uri, struct evkeyvalq *headers) 实际变成了调用 evhttp_parse_query_impl(uri, headers, 1) 函数,该函数内再调用的一个 2.0.x 版本新增的函数 evhttp_uri_parse(const char *source_uri),逻辑处理代码在 evhttp_uri_parse_with_flags(const char *source_uri, unsigned flags) 函数中。evhttp_uri_parse(const char *source_uri) 无法正确解析含有“|”的URL,遇到类似“http://127.0.0.1:1218/?opt=get&name=aaa|bbb”的URL,直接返回NULL,也就是 BUG 所在。

  libevent-2.0.12-stable/http.c
  点击在新窗口中浏览此图片

  点击在新窗口中浏览此图片

  点击在新窗口中浏览此图片

  不建议修改第三方库,这个 BUG 还是留给 Libevent 自己去解决吧。使用 Libevent 2.0.x evhttp 作开发的同学,遇到URI参数中包含“|”的问题,注意一下吧。

  我修改了 HTTPSQS 代码,在 HTTPSQS 1.7 版本,采用以下方式来绕开evhttp_uri_parse(const char *source_uri)函数,解决这个问题。其中用到了 Libevent 2.0.x  evhttp_request 结构体中新增的 struct evhttp_uri *uri_elems,以及新增的函数 evhttp_parse_query_str (const char *uri, struct evkeyvalq *headers)。

  Libevent 的官方文档只有 1.4.10-stable2.0.1-alpha 版本的,2.0.1x 很多新增的函数、结构体都没有。

  我这里提供一份最新的 Libevent 在线文档: http://blog.zyan.cc/book/libevent/



  2、静态编译改为动态编译,并指定程序运行时查找的动态链接库路径

  一些网友反映,CentOS 6.0、Fedora 等系统没有默认安装lz、lbz2、lrt、...等静态链接库,出现无法编译HTTPSQS的情况:
gcc -o httpsqs httpsqs.c prename.c -L/usr/local/libevent-2.0.10-stable/lib/ -levent -L/usr/local/tokyocabinet-1.4.47/lib/ -ltokyocabinet -I/usr/local/libevent-2.0.10-stable/include/ -I/usr/local/tokyocabinet-1.4.47/include/ -lz -lbz2 -lrt -lpthread -lm -lc -O2 -g --static  
/usr/bin/ld: cannot find -lz  
/usr/bin/ld: cannot find -lbz2  
/usr/bin/ld: cannot find -lrt  
/usr/bin/ld: cannot find -lpthread  
/usr/bin/ld: cannot find -lm  
/usr/bin/ld: cannot find -lc  
/usr/bin/ld: cannot find -lc  
collect2: ld 返回 1  
make: *** [httpsqs] 错误 1


  HTTPSQS 1.7 版本改为动态编译,编译时使用“-Wl,-rpath”参数指定了程序运行时的动态库搜索路径。这样就不需要在 /etc/ld.so.conf 中 添加 HTTPSQS 程序运行时需要的 libevent、tokyocabinet 动态链接库路径了,可以避免与其他软件(例如:Memcached、TT)使用的 libevent、tokyocabinet 动态链接库版本相冲突。详情请见 Makefile 文件:
# Makefile for httpsqs
CC=gcc
CFLAGS=-Wl,-rpath,/usr/local/libevent-2.0.12-stable/lib/:/usr/local/tokyocabinet-1.4.47/lib/ -L/usr/local/libevent-2.0.12-stable/lib/ -levent -L/usr/local/tokyocabinet-1.4.47/lib/ -ltokyocabinet -I/usr/local/libevent-2.0.12-stable/include/ -I/usr/local/tokyocabinet-1.4.47/include/ -lz -lbz2 -lrt -lpthread -lm -lc -O2 -g

httpsqs: httpsqs.c
  $(CC) -o httpsqs httpsqs.c prename.c $(CFLAGS)
  @echo ""
  @echo "httpsqs build complete."
  @echo ""  

clean: httpsqs
  rm -f httpsqs

install: httpsqs
  install $(INSTALL_FLAGS) -m 4755 -o root httpsqs $(DESTDIR)/usr/bin


  用 ldd 命令查看一下 HTTPSQS 使用的动态链接库:
[root@ibm1 httpsqs-1.7]# ldd ./httpsqs
        linux-vdso.so.1 =>  (0x00007fff0ebff000)
        libevent-2.0.so.5 => /usr/local/libevent-2.0.12-stable/lib/libevent-2.0.so.5 (0x00007f5157979000)
        libtokyocabinet.so.9 => /usr/local/tokyocabinet-1.4.47/lib/libtokyocabinet.so.9 (0x00007f51576f6000)
        libz.so.1 => /lib64/libz.so.1 (0x00000038a1400000)
        libbz2.so.1 => /lib64/libbz2.so.1 (0x00000038a8800000)
        librt.so.1 => /lib64/librt.so.1 (0x00000038a2000000)
        libpthread.so.0 => /lib64/libpthread.so.0 (0x00000038a1000000)
        libm.so.6 => /lib64/libm.so.6 (0x00000038a1800000)
        libc.so.6 => /lib64/libc.so.6 (0x00000038a0c00000)
        /lib64/ld-linux-x86-64.so.2 (0x00000038a0400000)

  发现,libevent 和 libtokyocabinet 使用的是我们指定 lib 路径中的动态链接库。



  HTTPSQS 的详细使用说明,请访问: http://blog.zyan.cc/httpsqs/





技术大类 » Cache与存储 | 评论(86) | 引用(0) | 阅读(67526)
ELEVEN Email
2012-4-1 17:26
你好。HttpSQS V1.7版本,有一个疑问:初始化对列时,可以放满数据。但第一圈全部get完之后,再put数据只能是(长度-1),为何?例:1 初始化队列,长度设为1002 put 100个数据3 get 100个数据4 再put时,只能put99个。以上。望回复。
hgjgh Email Homepage
2012-4-30 18:17
水泥袋缝包机
编织袋缝包机
水泥袋缝纫机
水泥袋自动缝纫机
水泥袋缝包机
编织袋缝包机
水泥袋缝纫机
Abercrombie Email Homepage
2012-5-9 10:35
Cependant, le plus rapidement, même en dépit Abercrombie du fait que vous vous rendez compte les avantages et comment relaxant c'est encore, malgré le fait que vous tend encore bien au sein de l'intérieur de la sauvegarde et de luxe dans votre maison à tout moment appartenant vers le soir ou le soir manquante de l'acquisition de crapahuter dans les un magasin à un autre essayer de localiser l'inconfort que vous essayez de trouver, vous allez vite être acheter pour le net seulement pour vos spécifications indépendamment de pas un problème c'est peut-être aAbercrombie de sortie que vous essayez de découvrir ou de tout autre type de Abercrombiesortie de vêtements d'achat en plus des vêtements finition unique spéciale robuste.
Hogan Email Homepage
2012-5-10 17:45
Ci sono diversi motivi principali per cui si può sicuramente trovare sul proprio volere le soluzioni contabili che coinvolgono tutta Stansted, anche se alcune persone potrebbero uomini e donne, probabilmente si dovrà disporre di soluzioni contabili rispetto con la gente. Stai con me per scoprire di più su molti dei motivi per prendere in considerazione l'impiego contabili in tutta Hogan Stansted. Costruire un businessIf vi capita di essere in funzione, è abbastanza possibile che si può fare uso di soluzioni contabili. Non date per scontato tutte le società hanno abbastanza soldi per utilizzare a tempo pieno il personale fiscali, così utilizzando una conditi insieme con l'agenzia affidabile che coinvolge tutta commercialisti Stansted potrebbe rendere meno difficili problemi.
hogan280 Email
2012-5-10 18:00
Nove mesi dopo, nell'agosto 2009, il Crown Prosecution Service ha deciso di non caricare i due uomini, come la Hogan ragazza avrebbe fatto un "testimone inattendibile" e l'avvocato dubitava alcuna giuria avrebbe creduto.
vivienne westwood sale Email Homepage
2012-6-11 23:35
<p>Truly  <strong>vivienne westwood sale</strong>  speaking, you will be able would your wonderful trunk  <strong>vivienne westwood bags</strong>  yet you the why are your woman working in you the worldwide within you the moment. virtually Vivienne Westwood Melissa you will  <strong>Vivienne Westwood Jewellery</strong>  you should be magnificently written upward with your very important weapons yet workouts working in your you are in manner. you will be able would your your own without the trunk you to turns up working in you should without the types yet tones yet you the what to wear women. ,Look more related about <strong>vivienne westwood sale</strong>:http://www.ukviviennewestwoodhandbags.com/ </br></p>
Boorley
2012-6-13 19:28
Modern çocuk odası dekorasyonu konusunda yanda örneklerini gördüğünüz çalışmalar dışında istekleriniz doğrultusunda özel tasarım ve imalat da bünyemizde yapılmaktadır. Çocuk odası modelleri biri mutlaka çocuğunuz için.
cheaperoakleysunglasses Email Homepage
2012-6-30 09:33
If you are not a movement, but would like a pair of sunglasses that will capture others attention, discount oakley sunglasses is still option is ideal for you. You like sports style was low-key and vintage look, if I decide to buy oakley sunglasses will give you every option in the Sun. Once you know that Oakley Active Sunglasses protect you from the Sun's glare, you can style and fashion--you decide, it is at the top of Oakley Asian Fit Sunglasses in this market.
Celine handbags Email Homepage
2012-7-2 16:09
Celine handbags,
Women handbag is state right into a lot of women who wear them.
Celine bag,
With regards to cheap Celine women's handbags, you will find endless solutions.
Celine luggage tote,
These women handbag varieties may be the dream of work in general and then any type of company meetings.
Oakley vault Email Homepage
2012-7-2 16:13
When the term sunglasses come up in any conversation, it is generally very quickly followed by the brand name of Oakley Vault. They have been one of the leading manufacturers of Oakley Sunglasses for years and they are by far the most popular brand that is sought after on Oakleyvault20l2.com today.
CC
2012-8-11 13:57
vet medicine Email Homepage
2012-8-13 16:10
哇,有点复杂哎,不懂
lirourou77 Email Homepage
2012-9-5 13:01
in a new mechanism of system to replace the old in medicine have medical mechanism, which is the cheap designer handbags      
cattle nets", and click "online voting" found that, the original vote is paid, 1 yuan 1 ticket.

"If you have to vote online, by pay treasure, net silver or cell phone pays fee." HeXianSheng cheap designer clothes        
said, let people will choose the doctors like this is a good thing, but if will pay it is stale, "so, mean who's money, who can election?"

【 operation 】 can buy tickets into batch quantity
discount designer handbags        

According to HeXianSheng provide web site, reporter found "purple cattle nets", "popular activities" column in the article 1 is: ningxiang county "open the door the medical" advanced unit and "top ten doctors, top ten nurses, top ten technicians" selection activities to officiall
分组 Email Homepage
2012-9-6 21:49
额...我得研究一下!
Coach Email Homepage
2012-11-3 14:41
"The Coach Outletengines that will likely power the J-31 we do know a bit mor.Coach Outlet  Those engines were actually revealed at the Zhuhai showCoach Outlet in 2008," Fisher said referring to an annual China air show. He beCoach Outletlieves the new J-31 engine is undergoing preliminary
North Face UK Email Homepage
2012-11-13 22:28
<a href="http://www.buynorthfaceuk.co.uk/">North Face UK</a> store has selling North Face jackets with over 10 years of time. All our customers are all very great about our <a href="http://www.buynorthfaceuk.co.uk/">North Face Outlet</a> jacket. As the winter coming, <a href="http://www.buynorthfaceuk.co.uk/">Buy North Face</a> jackets here can enjoy lowest price.
North Face UK Email Homepage
2012-11-13 22:30
<a href="http://www.buynorthfaceuk.co.uk/">North Face UK</a> store has selling North Face jackets with over 10 years of time. All our customers are all very great about our <a href="http://www.buynorthfaceuk.co.uk/">North Face Outlet</a> jacket. As the winter coming, <a href="http://www.buynorthfaceuk.co.uk/">Buy North Face</a> jackets here can enjoy lowest price.
Christian Louboutin Shoes Email Homepage
2012-11-13 22:30
Ladies who want to be sexy and charming need a brace of fashion <a href="http://www.onlinechristianlouboutinuk.co.uk/">Christian Louboutin Shoes</a>. For all women, put on <a href="http://www.onlinechristianlouboutinuk.co.uk/">Christian Louboutin Heels</a> will be very attractive and outstanding in any place. Shoes from <a href="http://www.onlinechristianlouboutinuk.co.uk/">Christian Louboutin UK</a> store are all very cheap and excellent. Take a look!
分页: 3/5 第一页 上页 1 2 3 4 5 下页 最后页
发表评论
表情
emotemotemotemotemot
emotemotemotemotemot
emotemotemotemotemot
emotemotemotemotemot
emotemotemotemotemot
打开HTML
打开UBB
打开表情
隐藏
记住我
昵称   密码   游客无需密码
网址   电邮   [注册]