1 个不稳定版本
使用旧的 Rust 2015
0.1.0 | 2018年10月31日 |
---|
#4 在 #apns
84KB
2K SLoC
XORC Notifications
一个服务集合,消费 PushNotification 事件 以向 apns2/fcm/web push 发送推送通知,以及消费 Application 事件 以接收配置。
系统默认为多租户,以便向多个不同的应用程序发送推送通知。
- apns2 用于 Apple 通知
- fcm 用于 Google 通知
- web_push 用于 Web 推送通知
- http_requester 用于通用 HTTP 请求
- common 所有四个消费者都使用的库
依赖项
该系统是用 Rust 编写的,应该始终可以使用最新稳定版本进行编译。获取最新 Rust 的实际方法是使用 rustup
> curl https://sh.rustup.rs -sSf | sh
> rustup update
> rustup default stable
检查是否一切正常
> rustc --version
rustc 1.30.0 (da5f414c2 2018-10-24)
> cargo --version
cargo 1.30.0 (36d96825d 2018-10-24)
项目中使用的一些 crate 对某些系统库和工具有依赖,对于 Ubuntu 18.04,你可以使用以下命令获取它们
> sudo apt install build-essential libssl-dev automake ca-certificates libffi-dev protobuf-compiler
开发设置
项目使用 Protocol Buffers 作为事件模式。使用 cargo build
应该生成用于代码中使用的相应 Rust 结构体。默认情况下,protobuf 类作为子模块包含在内,必须将其导入项目树中
> git submodule update --init
所有消费者的配置示例在 config 中。从示例配置中复制一份,移除结尾,并修改它以适应您的测试设置。
运行 apns2
> env CONFIG=./config/apns2.toml cargo run --bin apns2
运行 fcm
> env CONFIG=./config/fcm.toml cargo run --bin fcm
运行 web_push
> env CONFIG=./config/web_push.toml cargo run --bin web_push
运行 http_requester
> env CONFIG=./config/http_requester.toml cargo run --bin http_requester
用于测试目的的示例脚本
examples 目录包含用于测试消费者的辅助脚本。
要构建它们
cargo build --release --examples
可执行文件位于 target/release
目录中。
配置
系统配置通过一个toml文件和一个环境变量来处理。
环境变量
变量 | 描述 | 示例 |
---|---|---|
CONFIG |
配置文件位置 | /etc/xorc-notifications/config.toml |
LOG_FORMAT |
日志输出格式 | text 或json ,默认:text |
RUST_ENV |
程序环境 | test 、development 、staging 或production ,默认:development |
必需选项
部分 | 键 | 描述 | 示例 |
---|---|---|---|
[kafka] |
input_topic |
通知输入主题 | "production.notifications.apns" |
[kafka] |
config_topic |
应用配置主题 | "production.applications" |
[kafka] |
output_topic |
通知响应主题 | "production.oam" |
[kafka] |
group_id |
消费者组ID | "production.consumers.apns" |
[kafka] |
brokers |
逗号分隔的Kafka代理列表 | "kafka1:9092,kafka2:9092" |
[kafka] |
consumer_type |
决定输入protobuf反序列化 | push_notification 用于PushNotification 、http_request 用于HttpRequest |
代码架构
- 所有四个系统都使用异步Kafka消费者消费
input_topic
,使用客户端请求外部服务,解析响应并将响应返回给调用者。 - 系统应实现
EventHandler
(request_consumer.rs)并使用ResponseProducer
(response_producer.rs)进行响应。 - 消费者应跟踪使用来自
config_topic
的配置值的各个应用程序的连接。 - 一般来说,主代码不应有任何阻塞。
- 所有消费者都使用HTTP进行通信,并在请求时返回Prometheus统计信息
依赖项
~60MB
~1M SLoC