heussd/nats-news-analysis

GitHub: heussd/nats-news-analysis

一个基于NATS队列的自动化新闻分析系统,用于从网络查找新闻、匹配关键词并输出结果到Raindrop.io。

Stars: 11 | Forks: 2

## 标题:个人新闻分析 摘要:自动从网络查找相关新闻。 系统性地检索在线新闻文章,进行丰富处理,扫描关键词,并将匹配结果发送至 [raindrop.io](https://raindrop.io/)。所有分析组件通过 [NATS.io](https://nats.io/) 队列实现松散耦合,这也使得扩展单核CPU密集型组件变得简单。 ![](https://static.pigsec.cn/wp-content/uploads/repos/2026/05/638c0a8e42022245.svg) [在 Draw.io 中打开](https://app.diagrams.net/?url=https://static.pigsec.cn/wp-content/uploads/repos/2026/05/638c0a8e42022245.svg) 该系统使用以下 NATS 队列: 1. `feed-urls` - RSS 订阅源的 URL。 2. `article-urls` - RSS 订阅源中单篇文章的 URL。 3. `news` - 新闻文本及其元数据。 4. `match-urls` - 正向匹配文章的 URL。 该系统的产出包括: 1. 一个包含与关键词匹配的文章的 Raindrop.io 集合。 2. 一个为新闻混合搜索准备的 Azure AI Search 索引。 3. 一个带有指标的 Grafana 仪表盘。 4. 一个 MCP-Server,允许使用智能体 LLM(例如 [Roo Code](https://roocode.com))来使用第 1 项和第 2 项。 ## 涉及的服务 所有服务均通过 `compose.yml` 进行编排和扩展。 ### 自定义服务 - [ghcr.io/heussd/nats-news-analysis/feed-feeder](https://ghcr.io/heussd/nats-news-analysis/feed-feeder) - **Bash** - 从文本文件中获取 RSS 订阅源 URL。 - [ghcr.io/heussd/nats-news-analysis/article-feeder](https://ghcr.io/heussd/nats-news-analysis/article-feeder) - **Golang** - 从 RSS 订阅源中获取新闻文章 URL。 - [ghcr.io/heussd/nats-news-analysis/news-feeder](https://ghcr.io/heussd/nats-news-analysis/news-feeder) - **Golang** - 检索新闻并提供文章内容及元数据。 - [ghcr.io/heussd/nats-news-analysis/keyword-matcher](https://ghcr.io/heussd/nats-news-analysis/keyword-matcher) - **Golang** - 根据关键词列表进行匹配。 - [ghcr.io/heussd/nats-news-analysis/nats-indexer](https://ghcr.io/heussd/nats-news-analysis/nats-indexer) - **Python** - 为新闻及其元数据建立索引。 - [ghcr.io/heussd/nats-news-analysis/raindrop-integration](https://ghcr.io/heussd/nats-news-analysis/raindrop-integration) - **Golang** - 在 [raindrop.io](https://raindrop.io/) 上发布匹配结果。 ### 第三方服务 - [docker.io/heussd/fivefilters-full-text-rss](https://hub.docker.com/r/heussd/fivefilters-full-text-rss) - 检索网页全文。 - [docker.io/nats](https://hub.docker.com/_/nats) - 事件队列、键值存储与去重。 - [NGINX](https://www.nginx.com/) - 简单的负载均衡器/反向代理。 - [Prometheus NATS Exporter](https://github.com/nats-io/prometheus-nats-exporter) - 使 NATS 指标可供 Prometheus 使用。 - [Prometheus](https://prometheus.io/) - 指标与监控。 - [Grafana Loki](https://grafana.com/oss/loki/) - 日志聚合。 - [Grafana](https://grafana.com/grafana/) - 用于指标和统计的仪表盘。 - [Watchtower](https://github.com/containrrr/watchtower) - 保持容器更新。 ## 用于扩展的消息队列 我们并非用单核关键词匹配操作阻塞应用程序,甚至试图构建复杂的多线程关键词匹配,而是使用 docker compose 的 `scale` 选项来并行运行多个单核关键词匹配组件,并通过消息队列将它们连接起来。这使我们能够保持各个组件极其简单且易于维护。 ### 已扩展的关键词匹配容器 ![](https://static.pigsec.cn/wp-content/uploads/repos/2026/05/e4675f7841022246.png) ### 每个关键词匹配使用一个核心 ![](https://static.pigsec.cn/wp-content/uploads/repos/2026/05/eb9964f7fd022247.png) ## 可观察性 使用典型的 Prometheus-Loki-Grafana 技术栈来监控应用程序的指标和统计数据。 ![](https://static.pigsec.cn/wp-content/uploads/repos/2026/05/a6dbd81fee022248.png) NATS 服务器统计信息通过 [Prometheus NATS Exporter](https://github.com/nats-io/prometheus-nats-exporter) 提供给 Prometheus。 关键词匹配容器使用 zerolog,并通过 [Docker Loki 日志驱动将其日志暴露给 Loki](https://yuriktech.com/2020/03/21/Collecting-Docker-Logs-With-Loki/)。 Grafana 仪表盘随代码仓库源码一同提供。 ## Python 与 Golang 比较 作为负责主要分析任务的核心组件之一,关键词匹配器(keyword-matcher)已从 Python 移植到 Golang,这既是出于乐趣也是为了研究目的。关键词匹配器的两种实现可以并行工作,甚至相互竞争: ``` NAME CPU % MEM USAGE / LIMIT loki 1.33% 74.55MiB / 7.667GiB nats-news-analysis_fullfeedrss_1 0.00% 76.68MiB / 7.667GiB nats-news-analysis_fullfeedrss_2 0.01% 70.62MiB / 7.667GiB nats-news-analysis_grafana_1 0.17% 35.95MiB / 7.667GiB nats-news-analysis_keyword-matcher-go_1 0.00% 8.051MiB / 7.667GiB nats-news-analysis_keyword-matcher-go_2 0.00% 8.422MiB / 7.667GiB nats-news-analysis_keyword-matcher-go_3 0.00% 8.781MiB / 7.667GiB nats-news-analysis_keyword-matcher-go_4 0.00% 8.059MiB / 7.667GiB nats-news-analysis_keyword-matcher-python_1 0.00% 22.64MiB / 7.667GiB nats-news-analysis_keyword-matcher-python_2 0.00% 23.21MiB / 7.667GiB nats-news-analysis_keyword-matcher-python_3 0.00% 24.23MiB / 7.667GiB nats-news-analysis_keyword-matcher-python_4 0.00% 23.8MiB / 7.667GiB nats-news-analysis_loadbalancer_1 0.00% 2.316MiB / 7.667GiB nats-news-analysis_nats-server_1 1.34% 92.97MiB / 7.667GiB nats-news-analysis_natsexporter_1 0.03% 7.41MiB / 7.667GiB nats-news-analysis_pocket-integration_1 0.00% 18.41MiB / 7.667GiB nats-news-analysis_prometheus_1 0.00% 37.22MiB / 7.667GiB nats-news-analysis_rss-article-url-feeder-go-1st_1 0.05% 15.32MiB / 7.667GiB nats-news-analysis_rss-article-url-feeder-go-2nd_1 11.46% 12.95MiB / 7.667GiB ``` 以下是在常规运行期间从 Docker 和 Loki 收集的一些有趣统计数据: | 指标 | Python | Golang | 对比 | | ---------------- | ------- | ------- | ----------------------------- | | Docker 镜像大小 | 424MB | 6.09MB | Go 实现约小70倍 | | 内存消耗 | 23,8MiB | 8,33MiB | Go 实现所需内存约为1/3 | | 代码行数 | 447 | 485 | Python 实现少约8%的代码行数 |
标签:Azure AI 搜索, Docker 编排, EVTX分析, MCP 服务器, RSS 订阅, 书签管理, 信息检索, 关键词匹配, 内容丰富化, 可扩展性, 多语言编程, 应用安全, 数据索引, 新闻分析, 智能搜索, 消息队列, 监控仪表板, 自动化数据收集, 自定义请求头, 请求拦截, 逆向工具, 雨滴书签