
coco/notifications-pushnotifications-push 是一个微服务,用于提供内容发布或变更的推送通知。该微服务消费特定的 Apache Kafka 主题组,然后为消费的 Kafka 消息中包含的每个文章或内容列表推送通知。
适用于需要实时获取内容发布或变更通知的系统,如内容管理平台、实时内容展示应用、内容监控工具等,帮助下游服务及时响应内容更新。
bashcurl [***] | sh go get -u github.com/Financial-Times/notifications-push cd $GOPATH/src/github.com/Financial-Times/notifications-push dep ensure -vendor-only go test ./... -race go install
bashssh -L 2181:localhost:2181 -L 9092:localhost:9092 username@<host>
bash127.0.0.1 <private_dns>
bashexport NOTIFICATIONS_RESOURCE=content \ && export KAFKA_ADDRS=localhost:2181 \ && export GROUP_ID=notifications-push-yourtest \ && export TOPIC=PostPublicationEvents \ && export NOTIFICATIONS_DELAY=10 \ && export API_BASE_URL="[***]" \ && export CONTENT_TYPE_WHITELIST="application/vnd.ft-upp-article+json,application/vnd.ft-upp-content-package+json" \ && export CONTENT_URI_WHITELIST="^[***]|wordpress|content)-(article|collection|content-placeholder)-(transformer|mapper|unfolder)(-pr|-iw)?(-uk-.*)?\\.svc\\.ft\\.com(:\\d{2,5})?/(content)/[\\w-]+.*$" \ && ./notifications-push
bash./notifications-push \ --notifications_resource="content" \ --consumer_addr="localhost:2181" \ --consumer_group_id="notifications-push" \ --topic="PostPublicationEvents" \ --notifications_delay=10 \ --api-base-url="[***]" \ --api_key_validation_endpoint="t800/a" \ --content_type_whitelist="application/vnd.ft-upp-article+json,application/vnd.ft-upp-content-package+json" \ --content_uri_whitelist="^[***]|wordpress|content)-(article|collection|content-placeholder)-(transformer|mapper|unfolder)(-pr|-iw)?(-uk-.*)?\\.svc\\.ft\\.com(:\\d{2,5})?/(content)/[\\w-]+.*$"
注:运行
./notifications-push -h获取完整选项列表
bashdocker build -t coco/notifications-push .
bashdocker run --env NOTIFICATIONS_RESOURCE=content \ --env KAFKA_ADDRS=localhost:2181 \ --env GROUP_ID="notifications-push-yourtest" \ --env TOPIC="PostPublicationEvents" \ --env NOTIFICATIONS_DELAY=10 \ --env API_BASE_URL="[***]" \ --env CONTENT_TYPE_WHITELIST="application/vnd.ft-upp-article+json,application/vnd.ft-upp-content-package+json" \ --env CONTENT_URI_WHITELIST="^[***]|wordpress|content)-(article|collection)-(transformer|mapper|unfolder)(-pr|-iw)?(-uk-.*)?\\.svc\\.ft\\.com(:\\d{2,5})?/(content)/[\\w-]+.*$" \ coco/notifications-push
| 环境变量 | 命令行参数 | 描述 |
|---|---|---|
| NOTIFICATIONS_RESOURCE | --notifications_resource | 通知资源类型(如 "content") |
| KAFKA_ADDRS | --consumer_addr | Kafka 地址 |
| GROUP_ID | --consumer_group_id | 消费者组 ID |
| TOPIC | --topic | 要消费的 Kafka 主题 |
| NOTIFICATIONS_DELAY | --notifications_delay | 通知延迟时间(秒) |
| API_BASE_URL | --api-base-url | API 基础 URL |
| CONTENT_TYPE_WHITELIST | --content_type_whitelist | 允许的内容类型列表,逗号分隔 |
| CONTENT_URI_WHITELIST | --content_uri_whitelist | 允许的内容 URI 正则表达式 |
| API_KEY_VALIDATION_ENDPOINT | --api_key_validation_endpoint | API 密钥验证端点 |
通过 GET 请求访问 /{resource}/notifications-push 端点,订阅者可消费指定资源的通知推送流。
请求示例:
bashcurl -i --header "x-api-key: «api_key»" [***] curl -X GET "http://localhost:8080/content/notifications-push?monitor=true"
参数:
type:指定接收通知的内容类型,可选值:Article、ContentPackage、Audio、All(默认 Article)monitor:设为 true 时返回 publishReference 和 lastModified 属性(用于内部监控)响应示例:
data: [] data: [{"apiUrl":"[***]","id":"[***]","type":"[***]","title":"For Ioana & Ioana only;","standout":{"scoop":true}}] data: []
注:空
[]行为心跳包,每 30 秒发送一次以保持连接。
GET 请求访问 /__history 端点,返回最近从 Kafka 队列消费的通知历史。
响应示例:
json[ { "apiUrl": "[***]", "id": "[***]", "type": "[***]", "publishReference": "tid_jwhfe7n6dj", "lastModified": "2016-11-07T13:59:44.950Z" } ]
GET 请求访问 /__stats 端点,返回当前消费推送流的订阅者统计信息。
响应示例:
json{ "nrOfSubscribers": 2, "subscribers": [ { "addr": "127.0.0.1:61047", "since": "Nov 7 14:26:04.018", "connectionDuration": "2m41.693365011s", "type": "dispatcher.standardSubscriber" } ] }
/__notifications-push/ 路径下工作,因 Vulcan 不支持 HTTP 长轮询,通过 Varnish 转发到固定端口解决。示例客户端代码位于 bin/client 目录。
应用使用 go-logger,日志文件在 app.go 中初始化。



manifest unknown 错误
TLS 证书验证失败
DNS 解析超时
410 错误:版本过低
402 错误:流量耗尽
身份认证失败错误
429 限流错误
凭证保存错误
来自真实用户的反馈,见证轩辕镜像的优质服务