Giter VIP home page Giter VIP logo

test-room's Introduction

题目1:

  • 1、
  • 实现一个房间的功能,单纯的业务逻辑不包含网络层接入
  • 一个加入房间的方法。joinRoom(String roomId,String userId)
  • 一个退出房间的方法。leaveRoom(String roomId,String userId)
  • 要求加入退出房间时打印房间内除了自己的所有成员。
  • 2、
  • 现在基于房间加入退出的功能对外提供了对外的请求接口(QPS 要求为 1W/S)不需要关心中间件,以及网络接入层,如果有想法可以写一下,主要关注怎么保证房间的功能正常。
  • 由于网络的问题加入退出房间的请求(可以自定义请求体)到的先后顺序可能不一样,但是原始顺序是一样的,要求保证加入退出房间在动作上是一致的。
  • 设计接收网络请求的 service 方法。以及对上述问题的解决方案。

整体思路:

    • 类似指令模式,c端发送指令,s端解析对应执行
    • 保证顺序,个人不建议在s端保证顺序,浪费时间,浪费生命
    • 多线程也没必要用, 业务逻辑都不够切换上下文的时间
    • 在用户退出房间请求先执行,进入房间请求后执行的情况,
    • 可以依据房间号+用户id 作为唯一标识存储集合中,
    • 当唯一标识不存在,则用户退出行为触发于加入行为之前,不予理会,
    • 同时记录到异常行为集合, 当进入房间请求再次进来时,查询异常集合是否存在当前唯一标识,存在则忽略,代表之前已退出,不允许进入

这里没有解决一个用户只能进入一个房间的问题.... 这个逻辑就简单了不过多描述

如果非要保证触发逻辑顺序一致, 则可以考虑使用redis 延迟队列来实现,进行触发时间排序,定时任务按照时间排序弹出,但这样会有一个 问题,就是必须提供一个可查询结果接口,否则都不成立....

test-room's People

Contributors

cyf0477 avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.