现在,我有一个运行Cassandra的ec2实例和一个简单的websocket服务器。我想知道这是否是制作“实时”聊天应用程序的正确方法。有什么我想念的吗?
客户端连接到websocket,插入一条消息,将该消息存储到数据库中,然后如果记录到数据库成功,则将消息发送给用户。
const cassandra = require('cassandra-driver'); const client = new cassandra.Client({ contactPoints: ['127.0.0.1'], localDataCenter: 'datacenter1' }); const WebSocket = require('ws'); const wss = new WebSocket.Server({ port: 3000 }); wss.on('connection', function connection(ws) { ws.on('message', function incoming(message) { //Insert message into Cassandra DB //Send message to other users if record to database with a consistency level of one is successful //Then send messages to users connected to the websocket in chatroom });
编辑:我似乎也找不到类似这样的任何教程,所以如果您有任何链接,请分享