Design Summary station letter

Why Letters station

In my last article website design message notification referred to in the composition of the website message notification system, which has a very important part of the notification channels, including the letter of the station, otherwise SMS, email and so on. The most important and essential that the station believed in many channels, after all text messages, e-mail the way up to touch the money did not say, but also every minute and pull the black bell Tucao user. Note that: in terms of pushing the PC side or the site APP end of this article are collectively referred to as the letter the station, they are at the bottom of the same set, just to show it in different ways.

Letters source station

Letters notification source station typically includes the following three:

1.用户事件触发:当某个用户对某个对象执行了评论、@、点赞、留言等动作,都需要对对象拥有者进行通知。这是最常见的需要通知的场景。
2.满足系统的规则后自动触发:比如被系统封号、等级提升、获得勋章时,理论上都应该对用户进行通知。
3.管理员触发:管理员主动向全网或者某个用户发送通知,比如发送公告等。
复制代码

I believe the reader in the use of the Nuggets, know almost other sites or APP received the most in the letter should be the type of station 1 and 3 of the.

Station format Letters

Specific contents of the letter we can not enumerate the station, but it has a fixed structure of the content model. Depending on the source and reference nuggets we know almost enumeration of the contents of the communication station, making it easier to summarize the model.

Case enumeration station letter

1. The user event triggers

【xxx】【点赞】了你的【文章】【文章的标题】
【xxx】【评论】了你的【文章】【文章的标题】
【xxx】【点赞】了你在【文章】【文章的标题】下的评论
【xxx】【回复】了你的【评论】【被回复的评论的内容】
【xxx】【点赞】了你在【文章】【文章标题】下的回复
【xxx】在【文章】【文章的标题】中【@】了你
【xxx】在【文章】下的【评论】中【@】了你
【xxx】在【文章】下的【回复】中【@】了你
【xxx】回答了你关注的【问题】【问题标题】
【xxx】更新了你关注的【文章】【文章标题】
【xxx】邀请你回答【问答】【问答标题】
【xxx】关注了你
复制代码

2. The system automatically triggers

恭喜你,你的【会员】成功升级到了【13级】
由于你已经多次违反网站规定,现已经被封号【3个月】
复制代码

3. Administrator Send

您的【沸点】被选为编辑精选
【管理员】发布了系统公告【文章】【文章标题,请点击查看。
【xxx】专栏新增了【N篇】文章
复制代码

SUMMARY station letter model

The content can be seen that numerous communication station, but slightly summary it can be seen that they require the following variable information:

Letters station 1. Subject : a certain user, the system administrator, of course, may not show, no system is shown generally. For later discussion, we call subject . This variable is to inform the recipient who triggered the notification.

Entity associated object is located within 2 station when triggered letter : Q & A, articles, columns, answer the next questions and answers, comments in answer, respond in comments.

这里想强调的是:实体对象在通知的时候只取两层,什么意思呢。比如问答下的回答的评论,通知的时候只取【回答下的评论】不用带上问答这个实体信息,否则显得累赘不说还得保存很多实体信息。
复制代码

Also for convenience, we call associated objects . To the entity object information associated with the show in the notification.

3. station within the letter recipient : this is relatively simple, certainly people are currently logged on.

4. Trigger station within the letter of the event : thumbs up, comment, reply, @, replied, inviting, and so on are concerned. We call events , mainly for the station within the letter of the content with.

The content model Letters station may use pseudo-code shown below:

public NoticeMode<FatherEntity, SonEntity> {
    private User subject; //主语
    private FatherEntity fatherEntity; //发生对象父实体(可以为空)
    private SonEntity sonEntity; //发生对象子实体。
    Private User receiver;//接收人
    private NoticeEvent event; //通知事件,枚举中的一个元素
}
复制代码

Letter station organizing content

Do not organize content within the letter of the station in the application code, so if you want to change the content of the notifications have to modify the code and then re-released. In the notification message website design also talked about the design of the notification can refer to the MVC pattern. Model (M) have, in C programs (typically in velocity) a combination of an internal mail desired content (V) by the event field. C code while (if implemented velocity template code) may be arranged into the center, so that the need to modify the contents of the communication station configuration, like format can be modified directly as immediate effect. Of course, here we can also use the rules engine to implement, but it feels a little overkill.

Letter disposed station

Sometimes users are not interested in certain events within the letter of the station, and even annoying. That letter inside the station will provide the settings to let users select a letter in the receiving station, of course, believe in the system of the station was to be sure to receive. The following are provided in the part of the letter know almost station:

The content model of the communication station only needs to herein as a dimension setting is received event message, who received the message, can be more easily achieved notification setting message.

The specific design of the station Letters

Said so much, I want some of their own design ideas especially within the letter of the station to generate, store and retrieve functions appear here. A reference to those who need it:

How to generate the communication station

Letters of the time when the station are carried out in an action of a user-generated, such as comments. That is in addition to the time saved comments comments relevant information needed to generate the background Letters station. I believe many people know that in the letter to save comments and generate two operating stations should be used in an asynchronous manner, prevent the latter from the former blocking the return, affecting experience. Asynchronous message queues within the application using a little overkill, asynchronous event framework recommended by the open source Google guava Eventbus.

How to save Letters station

Letter station table : tbl_website_message, stored in the communication station specific information, regardless of the user, substantially comprising the following fields:

Field Types of Remark
id Long Primary key id
event String Event Type
notice_type String The type of notification (message system, user messages)
fatherEntity json Associated parent entity
sonEntity json Child objects associated entities
content String Contents of the letter station

The communication station and the user relationship tables : tbl_user_message, substantially comprising the following fields:

Field Types of Remark
id Long Primary key id
website_message_id Long Letter station table id
notice_type String The type of notification (message system, user messages)
max_message_id Long He has traversed the maximum table id Station Letters
is_read Integer Has been read

Wherein notice_type notification type are, for example: Denver user and system messages. Also finer points: thumbs up, comment, @, other notification. DETAILED divided according to business needs, user distinguish.

How to obtain the communication station

When the user triggers a query visit the Web site or open the app, read the letter inside the station list Station Letters from the user table (tbl_user_message association tbl_website_message), is relatively simple. But one thing to note: If many scenes that more than one event triggers to receive notifications. Does not require that everyone needs to accept notices in tbl_user_message table in the station, people need to be informed of the inquiry and to demand access to tbl_user_message tbl_website_message in obtaining landing station within the letter of the time. Specific process is as follows:

1. 获取 tbl_user_message 中跟自己有关的最大 max_message_id。
2. 去 tbl_website_message 中获取 > max_message_id 的所有记录。
3. 循环遍历判断记录是否与自己有关(根据业务逻辑,如果有关将关联关系插入到 tbl_user_message 即可(记得 id 也要保存到 max_message_id 字段中。
4. 更新最晚插入 tbl_user_message 那条记录中的 max_message_id 为新遍历的最大的 website_message 表 id。防止下次重复遍历。
复制代码

some problems

Letter substantial contents associated station acquired dynamically

Letter station stored previously designed content model is the object of the associated entity, when generating the content filled into the communication station from an entity associated with the information in the model (e.g., title). If the entity-related information (e.g., title) After this change, and the message is not reflected. To obtain the associated dynamic content is also very simple, saving id of the associated entities in the model can, according to again obtain the substantial contents associated with when the user id channel acquisition station can be assembled into the returned content. Dynamic access to content associated entities can ensure real-time, but I think, non-dynamic content acquisition related entities would be better, for four reasons:

1.动态获取关联实体的内容导致每次获取站内信都发生表关联查询,对服务器造成一定的压力。
2.站内信消息反应的是触发的那一刻的一个状态,并不需要动态性。
3.动态改变内容可能会给接收人带来一定的困扰。特别是一些关键性信息,如触发人用户名、标题等。
4.如果还有其他通知渠道,比如钉钉、微信、邮件,这些渠道无法做到动态获取。所以还不如统一。
复制代码

Letters station polymerization

Sometimes the same type of channel stop too much can cause a long list of messages, such as point like, which can make a continuous time, the same Event, the same polymerization operation target message. Although I have not practiced, but my understanding is simple: go to the website or the user to open the app when obtaining the letter of the station, background letter message gets one package can do on the interface in the original station. I do not know the method used in the practice of people who had what kind of welcome message discussed.

Guess you like

Origin juejin.im/post/5d04ff9cf265da1bc752377f