openresty 1.21.4 集成nchan 1.3.0

原计划是将nchan 构建为一个动态模块(centos 的)但是发现包含了一些gcc 的问题,所以就直接使用了容器构建(alpine)

镜像

直接复用了openresty官方的,添加了nchan模块,具体参考github,同时也包含了一个fat jar dalongrong/openresty:1.21.4.1-alpine-fat

集成使用

这个比较简单,都是开箱即用的,核心是配置
nginx.conf

 
user root; 
master_process off;
worker_processes 1;
events {
    worker_connections  1024;
}
http {
    upstream my_redis_server {
        nchan_redis_server redis;
    }
    include       mime.types;
    default_type  text/html;
    lua_code_cache off;
    lua_package_path '/opt/lua/?.lua;;';
    real_ip_header     X-Forwarded-For;
    resolver 127.0.0.11;
    server {
       listen 80;
       charset utf-8;
       proxy_set_header X-Forwarded-For $remote_addr;
       proxy_buffering off;
       proxy_cache off;
       proxy_set_header Connection '';
       proxy_http_version 1.1;
       chunked_transfer_encoding off;
       default_type text/html;
       location ~ /redis_sub/(\w+)$ {
            nchan_subscriber;
            nchan_channel_id $1;
            nchan_redis_pass my_redis_server;
        }
        location ~ /redis_pub/(\w+)$ {
            nchan_redis_pass my_redis_server;
            nchan_publisher;
            nchan_channel_id $1;
        }
    }
}

docker-compose 文件

version: '3'
services:
   redis:
     image: redis:7.0.0-bullseye
     ports:
     - "6379:6379"
   app:
     image: dalongrong/openresty:1.21.4.1-alpine-fat
     ports:
     - "80:80"
     volumes:
     - "./nginx.conf:/usr/local/openresty/nginx/conf/nginx.conf"

说明

nchan 源码还是值得学习的,以前是大概的了解过nchan的配置使用,实际上如果企业有实时消息的场景,基于此时一个快速的方案,还是值得研究下的
同时利用好openresty 可以更好的扩展nchan

参考资料

https://github.com/rongfengliang/openresty-nchan
https://github.com/slact/nchan
https://nchan.io/

posted on   荣锋亮  阅读(184)  评论(0编辑  收藏  举报

相关博文:
阅读排行:
· 全程不用写代码,我用AI程序员写了一个飞机大战
· DeepSeek 开源周回顾「GitHub 热点速览」
· 记一次.NET内存居高不下排查解决与启示
· MongoDB 8.0这个新功能碉堡了,比商业数据库还牛
· .NET10 - 预览版1新功能体验(一)
历史上的今天:
2021-06-04 使用 Delta Sharing 协议进行数据共享
2021-06-04 dremio 16 升级问题
2019-06-04 Prisma 2 is Coming Soon
2019-06-04 amundsen 来自lyft 的开源数据发现平台
2019-06-04 packr 方便的潜入静态资源文件到golang 二进制文件中
2019-06-04 hasura skor 构建安装
2019-06-04 Lightning Web Components 组件生命周期(六)

导航

< 2025年3月 >
23 24 25 26 27 28 1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31 1 2 3 4 5
点击右上角即可分享
微信分享提示