海运的博客

Debian7安装队列服务HTTPSQS

发布时间:December 31, 2013 // 分类:消息队列 // No Comments

aptitude install gcc make zlib1g-dev libbz2-dev
yum install gcc zlib-devel bzip2-devel
wget https://github.com/downloads/libevent/libevent/libevent-2.0.21-stable.tar.gz
tar zxvf libevent-2.0.21-stable.tar.gz 
cd libevent-2.0.21-stable/
./configure --prefix=/usr/local/libevent-2.0.21-stable/
make && make install
cd ../

wget http://fallabs.com/tokyocabinet/tokyocabinet-1.4.48.tar.gz
tar zxvf tokyocabinet-1.4.48.tar.gz
cd tokyocabinet-1.4.48/
./configure --prefix=/usr/local/tokyocabinet-1.4.48/
make && make install
cd ../

wget http://httpsqs.googlecode.com/files/httpsqs-1.7.tar.gz
tar zxvf httpsqs-1.7.tar.gz
cd httpsqs-1.7/
sed -i 's/12/21/g' Makefile
sed -i 's/47/48/g' Makefile
make && make install

修改源码添加出多个队列支持:

/* 出多个队列 */
else if (strcmp(httpsqs_input_opt, "mget") == 0 && httpsqs_input_num >= 0 && httpsqs_input_num <= 10000) 
{
    int i;
    for( i=0; i<httpsqs_input_num; i++ )
    {
        int queue_get_value = 0;
        queue_get_value = httpsqs_now_getpos((char *)httpsqs_input_name);
        if (queue_get_value == 0) {
            evbuffer_add_printf(buf, "%s", "HTTPSQS_GET_END");
            break;
        } else {
            char queue_name[300] = {0}; /* 队列名称的总长度,用户输入的队列长度少于256字节 */
            sprintf(queue_name, "%s:%d", httpsqs_input_name, queue_get_value);
            char *httpsqs_output_value;
            httpsqs_output_value = tcbdbget2(httpsqs_db_tcbdb, queue_name);
            if (httpsqs_output_value) {
                memset(queue_name, '\0', 300);
                sprintf(queue_name, "%d", queue_get_value);    
                evhttp_add_header(req->output_headers, "Pos", queue_name);
                evbuffer_add_printf(buf, "%s\n", httpsqs_output_value);
                free(httpsqs_output_value);
            } else {
                evbuffer_add_printf(buf, "%s", "HTTPSQS_GET_END");
                break;
            }
        }
    }
}

源码分析:

将队列读取点和写入点保存为key:queue:getpos/putpos的值,队列内容key为queue:1/queue:2形式
通过httpsqs_read_putpos获取写入/读取点值
读取队列内容时httpsqs_now_read_pos对值判断及更新值,对key:queue:+1
通过tcbdbput2/tcbdget2写入/读取队列内容

更多:http://blog.s135.com/httpsqs/

标签:none

评论已关闭

分类
最新文章
最近回复
  • liyk: 这个方法获取的IPv6大概20分钟之后就会失效,默认路由先消失,然后Global IPV6再消失
  • 海运: 不好意思,没有。
  • zongboa: 您好,請問一下有immortalwrt設定guest Wi-Fi的GUI教學嗎?感謝您。
  • 海运: 恩山有很多。
  • swsend: 大佬可以分享一下固件吗,谢谢。
  • Jimmy: 方法一 nghtp3步骤需要改成如下才能编译成功: git clone https://git...
  • 海运: 地址格式和udpxy一样,udpxy和msd_lite能用这个就能用。
  • 1: 怎么用 编译后的程序在家里路由器内任意一台设备上运行就可以吗?比如笔记本电脑 m参数是笔记本的...
  • 孤狼: ups_status_set: seems that UPS [BK650M2-CH] is ...
  • 孤狼: 擦。。。。apcupsd会失联 nut在冲到到100的时候会ONBATT进入关机状态,我想想办...