openresty 1.21.4 集成nchan 1.3.0
  8KhYbgszLLmZ 2023年11月02日 51 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/​

【版权声明】本文内容来自摩杜云社区用户原创、第三方投稿、转载,内容版权归原作者所有。本网站的目的在于传递更多信息,不拥有版权,亦不承担相应法律责任。如果您发现本社区中有涉嫌抄袭的内容,欢迎发送邮件进行举报,并提供相关证据,一经查实,本社区将立刻删除涉嫌侵权内容,举报邮箱: cloudbbs@moduyun.com

  1. 分享:
最后一次编辑于 2023年11月08日 0

暂无评论

推荐阅读
8KhYbgszLLmZ