Giter Club home page Giter Club logo

Comments (3)

zhou-hao avatar zhou-hao commented on August 25, 2024 1
  1. Device real status will managed by DeviceSessionManager in memory.
  2. When device register to DeviceSessionManager, device state,server id will save to DeviceRegistry(Redis).
  3. Publish DeviceOnlineMessage to EventBus /device/{productId}/{deviceId}/online.
  4. DeviceMessageBusinessHandler subscribe topic /device/*/*/online,offline from EventBus when server started.
  5. Synchronization device real state to PostgreSQL when EventBus sent /device/*/*/online,offline message ,( get state from DeviceRegsitry )
  6. Check real state when api request: /device/instance/{deviceId}/detail and synchronization it.

from jetlinks-community.

zhou-hao avatar zhou-hao commented on August 25, 2024 1
  1. When device register to DeviceSessionManager, device state,server id will save to DeviceRegistry(Redis).

In fact, Redis can not keep real-time for device state:
e.g. When the service restarts or crashes, the state does not have time to synchronize.

JetLinks device state check strategy :

  1. Get server id info in DeviceRegistry (store in redis, cache in memory.).
  2. RPC the server id: Get device real state.
  3. If cached state not equals RPC response, synchronization to PostgreSQL

TIP: The same principle was used in a send device message (when cluster).

from jetlinks-community.

LLLLimbo avatar LLLLimbo commented on August 25, 2024
  1. Device real status will managed by DeviceSessionManager in memory.
  2. When device register to DeviceSessionManager, device state,server id will save to DeviceRegistry(Redis).
  3. Publish DeviceOnlineMessage to EventBus /device/{productId}/{deviceId}/online.
  4. DeviceMessageBusinessHandler subscribe topic /device/*/*/online,offline from EventBus when server started.
  5. Synchronization device real state to PostgreSQL when EventBus sent /device/*/*/online,offline message ,( get state from DeviceRegsitry )
  6. Check real state when api request: /device/instance/{deviceId}/detail and synchronization it.

Thank you for your answer, but I still have a question:

Is it not quite appropriate to store the real state of the device in memory? This is not conducive to horizontal scaling. Perhaps it would be better to use Redis' ZSET to store the device ID and use the device's last active time as its score?

from jetlinks-community.

Related Issues (20)

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.