Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add publish-subscribe capability to JSON API #43

Open
cassava opened this issue Jun 23, 2021 · 0 comments
Open

Add publish-subscribe capability to JSON API #43

cassava opened this issue Jun 23, 2021 · 0 comments
Labels
enhancement New feature or request

Comments

@cassava
Copy link
Contributor

cassava commented Jun 23, 2021

Publish-Subscribe JSON API

The JSON API provides a collection of endpoints that can be queried for data.
In principle, the Cloe UI has two phases: setup and update. In the setup
phase, the context of the simulation is queried, the model dynamic UI is
created, and initial data values are shown. From this point on, the structure
remains the same and the server is queried for updates.

This can result in an excessive load, especially if the simulation is already
running in a speed that is less than realtime. A more efficient solution would
be that the UI does not need to poll for updates, but instead subscribe to
them.

Requirements

The following requirements have been collected through an informal process of
information gathering and brainstorming.

  1. Information for the update phase can be subscribed to.

    This is necessary to reduce the (possibly) excessive number of GET requests
    that would otherwise be required to acquire all the information needed.

Proposal

The following design attempts to fulfill the requirements in a sustainable
way:

  1. Web sockets is used to provide the network pattern of publishing and
    subscribing.

    This is already used to a small degree in the Cloe runtime, so expanding
    its usage does not add an extra dependency.

  2. Collections of endpoints can be subscribed to.

    By allowing endpoints to subscribe to a collection of endpoints, the burden
    is placed on the server to provide them. This extra effort is not more than
    it would otherwise be.

    An endpoint, such as /api/subscribe is provided which can receive a JSON
    list of endpoints that should be returned in a subscription response:

    {
       "channel": "cloe-ui",
       "endpoints": [
          "/api/vehicles",
          "/api/uuid"
       ],
       "update": 100
    }

    Only endpoints that have the API prefix can be subscribed to.
    The server returns a ZeroMQ endpoint that the UI should use to connect to:

    {
       "connect": "tcp://localhost:23000",
       "channel": "cloe-ui"
    }

    Once the client has connected, it will receive updates as JSON objects,
    where each endpoint is a key, and the response of that endpoint is the
    value of the key::

    {
       "/api/vehicles": [ "default" ],
       "/api/uuid": "f5988dea-119e-4fd5-8514-d948a1093eb1"
    }

Challenges

  • Replacement of the current network server (libcppnetlib) is required for
    WebSockets support.

  • How does a client signal that it is no longer interested in a subscription?

  • How do we efficiently support multiple Cloe UI instances? Is this even
    necessary?

  • How does a client change the update interval after subscribing to
    a collection of endpoints?

    One approach here would be to close a subscription and restart with
    a different update interval.

Logging Endpoint

It would be useful for Cloe logging output to be fetchable from a web endpoint.
It's likely not performant to store the logging data and return it all, so
streaming seems like the best fit.

@cassava cassava added the enhancement New feature or request label Jun 23, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant