简体   繁体   中英

Online chat solution for Asp.Net MVC 5.1 website

I have an Asp.Net MVC 5.1 website. We've got 3 types of users and I want to add support for chat between one type of them. I have thought of some models like this:

public class Conversation
{
    public NormalUser A { get; set; }
    public NormalUser B { get; set; }
    public List<PrivateMessaage> Messages { get; set; }
}

public class PrivateMessaage
{
    public NormalUser Sender { get; set; }
    public NormalUser Receiver { get; set; }
    public string Message { get; set; }
    public DateTime Created { get; set; }
}

Also, I'm using SignalR in other parts of the project and thought like it's a very good solution to add the chat interface on top of the SignalR. Everything looks good so far. However, I think hitting the database to insert a new message EVERY time a message is being typed is not a good idea. I've created so many strategies to implement custom donut caching in my website to make every single page as fast as possible and it seems like this would cancel all of them out! What is the preferred solution to this problem? I think I might take some approaches like these:

  • Push them to the database in batches. For instance once a message is past a threshold (its date/time difference is more than X or the message count is more than Y).
  • Don't support offline messages, just push them in-memory to the other side through SignalR.
  • Same as the 2nd, but support offline when the target user is offline. I imagine not many messages will be sent to offline users!
  • Don't cache anything. I'll work out!!

One issue with the first one is that, there might be a situation where the website would go down (for update, power failure, apocalypse(!), etc.) and all the messages in memory would be lost. I can add a custom action to flush everything but it's never quite safe. Since there's a lot of chat solutions out there, I think there are very convenient solutions to this.

如果您不反对使用其他数据库,使用Firebase和AngularJS可以非常轻松地进行实时聊天。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM