惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

T
Threat Research - Cisco Blogs
S
Securelist
H
Heimdal Security Blog
Scott Helme
Scott Helme
D
Darknet – Hacking Tools, Hacker News & Cyber Security
The Hacker News
The Hacker News
C
CXSECURITY Database RSS Feed - CXSecurity.com
Spread Privacy
Spread Privacy
Cyberwarzone
Cyberwarzone
V
Vulnerabilities – Threatpost
C
Cybersecurity and Infrastructure Security Agency CISA
C
CERT Recently Published Vulnerability Notes
P
Proofpoint News Feed
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
人人都是产品经理
人人都是产品经理
C
Cisco Blogs
www.infosecurity-magazine.com
www.infosecurity-magazine.com
Engineering at Meta
Engineering at Meta
Project Zero
Project Zero
CTFtime.org: upcoming CTF events
CTFtime.org: upcoming CTF events
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
有赞技术团队
有赞技术团队
T
Tailwind CSS Blog
Cisco Talos Blog
Cisco Talos Blog
Last Week in AI
Last Week in AI
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
O
OpenAI News
P
Proofpoint News Feed
Google Online Security Blog
Google Online Security Blog
Recent Announcements
Recent Announcements
Hacker News: Ask HN
Hacker News: Ask HN
美团技术团队
Stack Overflow Blog
Stack Overflow Blog
U
Unit 42
P
Privacy International News Feed
Google DeepMind News
Google DeepMind News
G
GRAHAM CLULEY
Apple Machine Learning Research
Apple Machine Learning Research
TaoSecurity Blog
TaoSecurity Blog
S
Security @ Cisco Blogs
C
Check Point Blog
H
Hackread – Cybersecurity News, Data Breaches, AI and More
Jina AI
Jina AI
S
Secure Thoughts
G
Google Developers Blog
C
Cyber Attacks, Cyber Crime and Cyber Security
L
LINUX DO - 最新话题
T
Tenable Blog
Latest news
Latest news
I
InfoQ

夜行人

回家路上 第一期的直播演示项目 震动检测器 正能量 在线参观CodeLab Neverland 发布 CodeLab Adapter 3.3.1 DynamicTable 之 纸糊方向盘 CodeLab DynamicTable: 一个可实施的技术方案 CodeLab Insight 发布 Alpha 版 情人节 Home Assistant 周报 && IoT 周报 (02) Joplin: 关注隐私的 Evernote 开源替代软件 浏览器的未来与 Web 传感器 Home Assistant 周报 && IoT 周报 (01) 百宝箱(01) 论自由 介绍 WebThings Home Assistant 周报 && iot 周报 (00) 百宝箱(00) 毛姆读书心得 传世之作 周末徒步 CodeLab Adapter ❤️ Jupyter/Python 航班 躲雨 夏令营途中 [译]思想--作为一种技术 The future of coding 美国之行 三门问题的程序模拟 从Python转向Pharo https://blog.just4fun.site/post/iot/iot-open-source-projects/ Python异步编程笔记 https://blog.just4fun.site/post/iot/iot-open-source-hardware-community/ 万物积木化开发者社区 CodeLab ❤️ Blender Scratch3技术分析之云变量 API(第7篇) [译]对管道(Pipes)的偏爱 [译]提出正确的问题比得到正确答案更重要 蓝牙设备与Scratch3.0 创建你的第一个Scratch3.0 Extension Scratch3技术分析之项目内部数据(第6篇) Scratch3技术分析之社区 API(第5篇) Scratch3技术分析之User API(第4篇) Scratch3技术分析之项目主页API(第3篇) Scratch3技术分析之静态资源API(第2篇) Scratch3.0、micro:bit与Windows7 https://blog.just4fun.site/post/iot/zerynth-vs-micropython/ 核聚变、方所与半宅空间 可视化编程为何是个糟糕的主意 codelab.club周末聚会 关于codelab.club '下一件大事'是一个房间 Hungry Robot - Eat everything 编程作为一种思考方式 今日简史 史蒂夫·乔布斯传 罗素自选文集 https://blog.just4fun.site/post/edx/tianjin-scratch-ai/ https://blog.just4fun.site/post/edx/richie-cms-openedx/ 徒步武功山 WebUSB与micro:bit 积木化编程与3D场景 夜宿武功山顶 scratch3-adapter接入优必选Alpha系列机器人 https://blog.just4fun.site/post/edx/video-migration-note/ scratch3-adapter重构笔记 https://blog.just4fun.site/post/edx/edx-community-members/ 两种硬件编程风格的比较 使用micro:bit自制PPT翻页笔 柏拉图对话集 scratch3.0 + micro:bit 七月电影放映计划 非营利组织的管理 Screenly--用树莓派让任何屏幕变为可编程的数字标牌 以最佳实践开始你的Django项目 micro:bit与事件驱动 为Scratch3.0设计的插件系统(上篇) OCR应用一例 近两年读过的一些好书 blockly开发之使用python驱动浏览器中的turtle(2) 牛顿新传 文学理论入门 逻辑的引擎 人生的意义 blockly开发之生成并运行js代码(1) blockly开发之hello world(0) micro:bit使用笔记 神器之Termux https://blog.just4fun.site/post/iot/micropython-notes/ Cozmo what is this Scratch的前世今生 下段旅程 我行在远方 爆裂 途中杂记 https://blog.just4fun.site/post/edx/open-edx-startup/ cozmo系列之入门 - 有性格且可编程的机器人 PaperWeekly开发笔记 创业二三事
notification system思路、概念与实现
2016-06-08 · via 夜行人

文章目录

试水

水挺深,撸起你的裤管

缘起

最初我想为Open edX实现一套消息系统(Notification system)。通过浏览官方库,我们发现,官方在做类似的事:notifier

notifier is a django application for edX platform notifications

It currently sends daily digests of new content to subscribed forums users, with a goal of eventually supporting real-time and batched notifications of various types of content across various channels (e.g. SMS).

由此可知这个库,最终会变得real-time and powerful(多种通知方式)

但目前而言,似乎偏弱,且只能提供论坛消息通知,且是以邮件的方式。而我们似乎更习惯站内消息这种通知形式

至于具体实现,我没细看,猜测是celery+rabbitmq,采用pub/sub模型

最初的思路

我的需求

  • 私信(message)
  • 站内消息(Announce)
    • 是系统发送的消息,格式是固定的,特殊对象一般拥有超链接(资源定位符)。
  • 提醒(activities,Remind,类似github消息通知)
    • 可能涉及关注对象/活动/订阅/
      • 谁对一样属于谁的事物做了什么操作(someone do something in someone’s something)

分析需求

通过万能的google,我们发现这类需求早就有人讨论过啦,以下是我喜欢的讨论

概念篇

对Pinterest、Instagram和Fashiolista来说,feed是一个核心组件。 这些系统的共同点在于向用户展示其关注的人的动态,Fashiolista是基于Atom Activity Streams 1.0(还有个使用json格式的版本)来构建动态数据流的(ps:Atom Activity Streams今年出了2.0版本

feed

那么我们首先要搞清楚feed是什么。

可以参考Web_feed

On the World Wide Web, a web feed (or news feed) is a data format used for providing users with frequently updated content.

我把它理解为最新讯息,提要)

Activities

stream的文档,对我们理解消息系统很有帮助, JSON Activity Streams 1.0有些抽象,而Stream-Framework名词太多

stream的文档让我们在使用过程中理解消息系统

一则Activities有以下属性:

  • Actor
  • Verb
  • Object
  • Target

举例而言

Erik is pinning Hawaii to his Places to Visit board.

我们来拆解这句话,用以上属性积木来构建它

  • Actor: “Eric” (User:2)
  • Verb: “pin”
  • Object: “Hawaii” (Place:42)
  • Target: “Places to Visit” (Board:1)

我们来看下这个动作用代码来描述

1
2
3
4
5
# Instantiate a feed object
user_feed_1 = client.feed('user', '1')
# Add an activity to the feed, where actor, object and target are references to objects (`Eric`, `Hawaii`, `Places to Visit`)
activity_data = {"actor": "User:2", "verb": "pin", "object": "Place:42", "target": "Board:1"}
activity_response = user_feed_1.add_activity(activity_data)

Using the above fields, you can express any activity!

意识到这点,我们就理解消息系统啦

ps:用程序表达现实关系(动作),业务相关的代码通常是模拟现实(关系或者事务),所以表达现实是一种常见的模式

其他概念

  • fanout:将动态推送给你的粉丝的过程被称为消息分发

###参考

实现篇

stream framework

Stream Framework is a Python library, which allows you to build newsfeed and notification systems using Cassandra and/or Redis.

  • Examples of what you can build are
    • Activity streams such as seen on Github
    • A notification system
  • 之前的Feedly
  • 作者博客

最近我在看stream framework的实现,重点关注redis部分,之后有时间再做分析

我们先来看下数据在redis里的结构

pin-redis

demo

这是基于stream_framework的一个demo,模仿Pinterest,用户可以发布自己的pin(类似post),其他用户可以follow该用户,并且对喜欢的物品进行点赞

由于时间久远,该项目无法直接运行,我做了些调整,使其跑在osx下,测试正常

首页 pin1.png

信息流

pin2.png

关注者 pin3.png

stream

当然我们也可以使用stream的服务来构建我们的消息系统,我们跑一个简单的demo

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
import stream
client = stream.connect('client id', 'client secret', location='us-east')

chris = client.feed('user', 'chris')
# add an activity, message is a custom field. add as many custom fields as you'd like
chris.add_activity({
  'actor': 'chris',
  'verb': 'add',
  'object': 'picture:10',
  'foreign_id': 'picture:10',
  'message': 'This bird is absolutely beautiful. Glad it\'s recovering from a damaged wing.'
});
# jack's timeline feed follows chris' user feed.
jack = client.feed('timeline', 'jack')
jack.follow('user', 'chris')
# read the timeline for jack, chris post will show up here
activities = jack.get(limit=10)['results']
# read the next page, use id filtering for optimal performance
next_activities = jack.get(limit=10, id_lte=activities[-1]['id'])['results']
# remove the activity by referencing the foreign_id you provided
chris.remove_activity(foreign_id='picture:10')

django demo

exampledjango

文章作者 种瓜

上次更新 2016-06-08