Firehose 技术文档
Firehose 是一个基于 Ruby 和 JavaScript 的实时 Web 应用程序构建工具。它既是一个 Rack 应用程序,也是一个 JavaScript 库,能够帮助开发者轻松构建实时 Web 应用。本文将详细介绍 Firehose 的安装、使用、API 以及配置等内容。
1. 安装指南
1.1 安装 Redis
Firehose 依赖于 Redis 2.6 或更高版本,因为 Firehose 使用了 Redis 的 Lua/EVAL 功能。请确保已安装并运行 Redis 2.6。
# 下载并安装 Redis
$ wget http://download.redis.io/releases/redis-2.6.0.tar.gz
$ tar xzf redis-2.6.0.tar.gz
$ cd redis-2.6.0
$ make
1.2 安装 Firehose
通过 RubyGems 安装 Firehose:
$ gem install firehose
1.3 使用 Docker 安装
如果你更喜欢使用 Docker,可以通过以下命令构建并启动 Firehose:
$ docker-compose build
$ docker-compose up
2. 项目的使用说明
2.1 启动 Firehose 服务器
启动 Firehose 服务器非常简单,只需运行以下命令:
$ firehose server
服务器启动后,默认监听 127.0.0.1:7474。
2.2 发布和订阅消息
Firehose 提供了一个简单的 HTTP 发布-订阅机制。你可以通过 curl 命令来测试这一功能。
在一个终端窗口中订阅消息:
$ curl "http://localhost:7474/hello"
在另一个终端窗口中发布消息:
$ curl -X PUT -d "Greetings fellow human being..." "http://localhost:7474/hello"
你将在第一个终端窗口中看到发布的消息。
2.3 运行测试
Firehose 提供了测试套件,可以通过以下命令运行测试:
$ docker-compose run firehose bundle exec rspec spec
3. 项目 API 使用文档
3.1 JavaScript 消费者
Firehose 提供了一个功能齐全的 JavaScript 客户端,允许你订阅频道以获取实时更新。
以下是一个简单的 JavaScript 消费者示例:
new Firehose.Consumer({
message: function(msg){
console.log(msg);
},
connected: function(){
console.log("Great Scotts!! We're connected!");
},
disconnected: function(){
console.log("Well shucks, we're not connected anymore");
},
error: function(){
console.log("Well then, something went horribly wrong.");
},
uri: '//localhost:7474/hello'
}).connect();
3.2 多路复用消费者
如果你需要同时订阅多个频道,可以使用多路复用消费者:
new Firehose.MultiplexedConsumer({
connected: function(){
console.log("Great Scotts!! We're connected!");
},
disconnected: function(){
console.log("Well shucks, we're not connected anymore");
},
error: function(){
console.log("Well then, something went horribly wrong.");
},
uri: '//localhost:7474/',
channels: {
"/my/channel/1": {
message: function(msg) {
console.log("got message on channel 1:");
console.log(msg);
}
},
"/my/channel/2": {
message: function(msg) {
console.log("got message on channel 2:");
console.log(msg);
}
}
}
}).connect();
3.3 Ruby 发布者
Firehose 还提供了一个 Ruby 客户端,用于轻松发布消息:
require 'firehose'
require 'json'
json = {'hello'=> 'world'}.to_json
firehose = Firehose::Client::Producer::Http.new('//127.0.0.1:7474')
firehose.publish(json).to("/my/messages/path")
你还可以通过传递选项来设置自定义 HTTP 头,例如 TTL、缓冲区大小等。
firehose.publish(json).to("/my/messages/path", ttl: 120, buffer_size: 1, deprecated: true, persist: true)
4. 项目配置
4.1 环境变量配置
Firehose 可以通过环境变量进行配置。参考 .env.sample 文件获取更多信息。
4.2 服务器配置
你可以通过 Firehose::Server.configuration 对象来配置 Firehose 服务器:
require "firehose"
class MyFilter < Firehose::Server::MessageFilter
def process(message)
message.payload = message.payload.upcase
end
end
Firehose::Server.configuration do |config|
config.message_filter = MyFilter
config.redis.url = ENV.fetch "FIREHOSE_REDIS_URL", "redis://redis:6379/10"
end
4.3 自定义消息过滤器
你可以通过继承 Firehose::Server::MessageFilter 类来实现自定义的消息过滤器,用于处理消息的认证和过滤逻辑。
class MyFilter < Firehose::Server::MessageFilter
def initialize(channel)
super(channel)
MyLogger.info "Subscribing to channel: #{channel}"
end
def on_subscribe(params)
@my_param = params["my-param"].to_i
end
def process(message)
if @my_param > 10
message.payload += "My-Param: #{@my_param}"
end
end
def on_unsubscribe
end
end
4.4 频道弃用日志
你可以通过配置将某些频道标记为弃用,并在订阅或发布时记录日志:
Firehose::Server.configuration do |config|
config.deprecated_channels = ["/my/deprecated/channel"]
end
总结
Firehose 是一个功能强大且易于使用的实时 Web 应用程序构建工具。通过本文的指南,你应该能够轻松安装、配置和使用 Firehose,并利用其丰富的 API 构建实时应用。
PaddleOCR-VLPaddleOCR-VL 是一款顶尖且资源高效的文档解析专用模型。其核心组件为 PaddleOCR-VL-0.9B,这是一款精简却功能强大的视觉语言模型(VLM)。该模型融合了 NaViT 风格的动态分辨率视觉编码器与 ERNIE-4.5-0.3B 语言模型,可实现精准的元素识别。Python00- DDeepSeek-OCRDeepSeek-OCR是一款以大语言模型为核心的开源工具,从LLM视角出发,探索视觉文本压缩的极限。Python00
MiniCPM-V-4_5MiniCPM-V 4.5 是 MiniCPM-V 系列中最新且功能最强的模型。该模型基于 Qwen3-8B 和 SigLIP2-400M 构建,总参数量为 80 亿。与之前的 MiniCPM-V 和 MiniCPM-o 模型相比,它在性能上有显著提升,并引入了新的实用功能Python00
HunyuanWorld-Mirror混元3D世界重建模型,支持多模态先验注入和多任务统一输出Python00
MiniMax-M2MiniMax-M2是MiniMaxAI开源的高效MoE模型,2300亿总参数中仅激活100亿,却在编码和智能体任务上表现卓越。它支持多文件编辑、终端操作和复杂工具链调用Jinja00
Spark-Scilit-X1-13B科大讯飞Spark Scilit-X1-13B基于最新一代科大讯飞基础模型,并针对源自科学文献的多项核心任务进行了训练。作为一款专为学术研究场景打造的大型语言模型,它在论文辅助阅读、学术翻译、英语润色和评论生成等方面均表现出色,旨在为研究人员、教师和学生提供高效、精准的智能辅助。Python00
GOT-OCR-2.0-hf阶跃星辰StepFun推出的GOT-OCR-2.0-hf是一款强大的多语言OCR开源模型,支持从普通文档到复杂场景的文字识别。它能精准处理表格、图表、数学公式、几何图形甚至乐谱等特殊内容,输出结果可通过第三方工具渲染成多种格式。模型支持1024×1024高分辨率输入,具备多页批量处理、动态分块识别和交互式区域选择等创新功能,用户可通过坐标或颜色指定识别区域。基于Apache 2.0协议开源,提供Hugging Face演示和完整代码,适用于学术研究到工业应用的广泛场景,为OCR领域带来突破性解决方案。00- HHowToCook程序员在家做饭方法指南。Programmer's guide about how to cook at home (Chinese only).Dockerfile014
Spark-Chemistry-X1-13B科大讯飞星火化学-X1-13B (iFLYTEK Spark Chemistry-X1-13B) 是一款专为化学领域优化的大语言模型。它由星火-X1 (Spark-X1) 基础模型微调而来,在化学知识问答、分子性质预测、化学名称转换和科学推理方面展现出强大的能力,同时保持了强大的通用语言理解与生成能力。Python00- PpathwayPathway is an open framework for high-throughput and low-latency real-time data processing.Python00