#consumer #kafka #push-notifications #web-push #fcm #apns

bin+lib xorc-notifications

用于从 Kafka 发送推送通知的消费者

1 个不稳定版本

使用旧的 Rust 2015

0.1.0 2018年10月31日

#4#apns

Apache-2.0

84KB
2K SLoC

XORC Notifications

Travis Build Status Apache licensed

一个服务集合,消费 PushNotification 事件 以向 apns2/fcm/web push 发送推送通知,以及消费 Application 事件 以接收配置。

系统默认为多租户,以便向多个不同的应用程序发送推送通知。

依赖项

该系统是用 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 日志输出格式 textjson,默认:text
RUST_ENV 程序环境 testdevelopmentstagingproduction,默认: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用于PushNotificationhttp_request用于HttpRequest

代码架构

  • 所有四个系统都使用异步Kafka消费者消费input_topic,使用客户端请求外部服务,解析响应并将响应返回给调用者。
  • 系统应实现EventHandlerrequest_consumer.rs)并使用ResponseProducerresponse_producer.rs)进行响应。
  • 消费者应跟踪使用来自config_topic的配置值的各个应用程序的连接。
  • 一般来说,主代码不应有任何阻塞。
  • 所有消费者都使用HTTP进行通信,并在请求时返回Prometheus统计信息

依赖项

~60MB
~1M SLoC