zoukankan      html  css  js  c++  java
  • gearman openresty 集成试用

    很简单使用了一个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

  • 相关阅读:
    DELL、HP、IBM X86服务器命名规则
    容灾,热备,集群等区别
    HDS(日立)AMS2000系列存储管理配置方法
    KBMMW 4.90.00 发布
    delphi 10 seattle 安卓服务开发(三)
    delphi 10 seattle 安卓服务开发(二)
    delphi 10 seattle 中 解决IOS 9 限制使用HTTP 服务问题
    Android 中的 Service 全面总结(转载)
    KBMMW 4.84.00 发布
    delphi 10 seattle 安卓服务开发(一)
  • 原文地址:https://www.cnblogs.com/rongfengliang/p/10290219.html
Copyright © 2011-2022 走看看