很简单使用了一个openresty 的lua 模块

环境准备

 
version: "3"
services:
  demo:
    image: artefactual/gearmand:latest 
    command: --queue-type=redis --redis-server=redis --redis-port=6379 --verbose=DEBUG
    ports:
    - "4731:4730"
  redis:
    image: redis
    ports:
    - "6379:6379"
  prometheus:
    image: prom/prometheus
    volumes:
    - "./prometheus/prometheus.yml:/etc/prometheus/prometheus.yml"
    ports:
    - "9090:9090"
  app:
    image: appscode/gearmand:0.5.2
    command: run --v=3 --storage-dir=/my-dir --addr="0.0.0.0:4730"
    volumes:
    - "./db:/my-dir"
    ports:
    - "4730:4730"
    - "3000:3000"
  client:
    image: dalongrong/client-demo
    build:
     context: ./client
  worker:
    image: dalongrong/worker-demo
    build:
     context: ./worker
  nginx:
   build: 
     context: ./openresty
   ports:
   - "8080:80"
   volumes:
   - "./openresty/app/:/opt/app/"
   - "./openresty/nginx.conf:/usr/local/openresty/nginx/conf/nginx.conf"
  admin:
    image: dalongrong/admin-demo
    build:
     context: ./admin
 
 
  • nginx 配置
    openresty/nignx.conf
 
worker_processes 1;
user root;  
events {
    worker_connections 1024;
}
http {
    include mime.types;
    default_type application/octet-stream;
    sendfile on;
    keepalive_timeout 65;
    lua_code_cache off;
    gzip on;
    resolver 127.0.0.11;          
    real_ip_header X-Forwarded-For;
    real_ip_recursive on;
    lua_package_path '/opt/app/?.lua;;';
    server {
        listen 80;
        server_name localhost;
        charset utf-8;
        root html;
        default_type text/html;
        location / {
           default_type text/html;
           index index.html;
        }
        location /upper {
           default_type text/plain;
           content_by_lua_block {
              require("upper/init")();
           }
        }
        error_page 500 502 503 504 /50x.html;
        location = /50x.html {
            root html;
        }
    }
}
 
 
  • resty.gearman lua 调用代码
local gearman = require "resty.gearman"
local gm = gearman:new()
function init()
    gm:set_timeout(1000) -- 1 sec
    local ok, err = gm:connect("app", 4730)
    if not ok then
        ngx.say("failed to connect: ", err)
          return
    end
    ok, err = gm:submit_job("ToUpper", "dalong demo")  
            -- submit_job,submit_job_bg,submit_job_high,submit_job_high_bg,submit_job_low,submit_job_low_bg are supported
            -- submit_job(function_name, workload[, unique])
    if not ok then
        ngx.say("failed to submit job: ", err)
            return
    else
        ngx.say(ok)
    end
    -- put it into the connection pool of size 100,
            -- with 0 idle timeout
    -- local ok, err = gm:set_keepalive(0, 100)
    -- if not ok then
    -- ngx.say("failed to set keepalive: ", err)
    -- return
    -- end
            -- or just close the connection right away:
    local ok, err = gm:close()
        if not ok then
          ngx.say("failed to close: ", err)
          return
        end
end
return init;
 
 
  • resty.gearman 模块配置
    使用dockerfile 指定的
 
FROM openresty/openresty:alpine-fat
LABEL author="1141591465@qq.com"
COPY app/lua-resty-gearman/lib/resty/gearman.lua /usr/local/openresty/lualib/resty/gearman.lua
 

启动&&测试

  • 启动
docker-compose up  -d
 
 
DALONG DEMO
 

说明

当前这个resty 库,只实现了client 的功能,但总的来说集成起来还是很强大的

参考资料

https://github.com/rongfengliang/gearmangolang-docker
https://github.com/zhhchen/lua-resty-gearman

gearman openresty 集成试用的更多相关文章

  1. pushpin Server-sent events && openresty 集成试用

    前边有写过一个简单pushpin 集成stream 的demo,这次测试下sse 的功能 备注: 环境依然使用的是docker-compose运行 环境准备 docker-compose 文件 ver ...

  2. pushpin openresty 集成试用

    pushpin 是一个很不错的将restapi 转换为reailtime api 的proxy,openresty 具有很强的nginx 控制能力 可以方便的用来进行api 的开发,默认其他语言pus ...

  3. openresty 集成 keycloak-oauth-oidc

    keycloak 是一个比较全,而且比较方便的sso 解决方案,同时为我们提供了灵活的扩展特性 备注: 测试使用docker-compose 运行,对于keycloak 使用pg 数据库做为后端存储 ...

  4. openresty 集成 sentry 异常系统

    sentry 是一个方便的错误异常追踪系统,同时社区也提供了openresty 的lua 包,使用docker-compose 进行测试 备注: sentry 部分的配置来自官方文档 环境准备 doc ...

  5. openresty 集成lua-resty-mail +smtp2http 扩展灵活的mail 服务

    lua-resty-mail 是一个不错的openresty mail 扩展,我们可以用来进行邮件发送,支持附件功能 smtp2http 是一个smtp 服务,可以将smtp 请求数据转换为http ...

  6. gogs wekan 集成试用

    wekan 官方提供了一个集成gogs 的扩展,不是完全的自动化,需要结合cli,但是官方的cli 写的...(不是很全) 备注: 测试环境使用docker-compose 环境准备 docker-c ...

  7. graphql elasticsearch 集成试用

    graphql 是很方便的api 查询语言,elasticsearch 可以方便的进行全文检索的应用开发 有一个方便的npm 包graphql-compose-elasticsearch 可以进行es ...

  8. benthos stream nats 集成试用

    测试demo 来自官方例子 使用docker-compose 进行运行 nats docker-compose file version: '3.3' services: nats: image: n ...

  9. 基于OpenResty和Node.js的微服务架构实践

    什么是微服务? 传统的单体服务架构是单独服务包,共享代码与数据,开发成本较高,可维护性.伸缩性较差,技术转型.跨语言配合相对困难.而微服务架构强调一个服务负责一项业务,服务可以单独部署,独立进行技术选 ...

随机推荐

  1. PHP和Mysql事物处理

    这几天做支付的时候,又用到了事物,为了方便自己以后查看,今天闲的没事就把以前的东西整理下.(其中引用别人的东西,在这里谢谢他们贡献的代码!) 一.事务处理概述: 事务:是若干事件的集合 事务处理:当所 ...

  2. redis、memcache、mongoDB 对比

    从以下几个维度,对 redis.memcache.mongoDB 做了对比. 1.性能 都比较高,性能对我们来说应该都不是瓶颈. 总体来讲,TPS 方面 redis 和 memcache 差不多,要大 ...

  3. 【转载】Maven中的BOM概念

    1.概述 1.1.什么是 BOM? BOM stands for Bill Of Materials. A BOM is a special kind of POM that is used to c ...

  4. BCM5396的SPI理解

    参考文档链接:https://pan.baidu.com/s/1kuXJmULwtjOW1TeOuTRPQQ *时钟极性和相位 BCM538X / BCM5396用于根据以下标准发送/接收SPI数据: ...

  5. java8 字符串转换 list long Integer

    String ids= "1,2,3,4,5,6"; List<Long> listIds = Arrays.asList(ids.split("," ...

  6. web项目与jsp有关的三个jar的依赖

    <!-- jsp --> <dependency> <groupId>javax.servlet</groupId> <artifactId> ...

  7. 运用HTML5+CSS3和CSS滤镜做的精美的登录界面

    原始出处http://chenjinfei.blog.51cto.com/2965201/774865 <!DOCTYPE HTML> <html> <head> ...

  8. mysql查询锁表语句

    processlist命令的输出结果显示了有哪些线程在运行,可以帮助识别出有问题的查询语句,两种方式使用这个命令. 1.      进入mysql/bin目录下输入mysqladmin process ...

  9. HIVE点滴:选择两个字段时distinct位置的影响

    当选择两个字段时,例如:"select XX1, XX2 from tb; ",那么将distinct放在前一个字段XX1之前和放在后一个字段XX2之前,结果有什么不同呢? 先说结 ...

  10. 获取页面元素的css属性

    function getStyle(obj, name){    if(obj.currentStyle)    {         return obj.currentStyle[name];//兼 ...