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

[Access] Implement new web socket controller component #6583

Open
Tracked by #6163
Guitarheroua opened this issue Oct 22, 2024 · 0 comments
Open
Tracked by #6163

[Access] Implement new web socket controller component #6583

Guitarheroua opened this issue Oct 22, 2024 · 0 comments
Assignees
Labels

Comments

@Guitarheroua
Copy link
Contributor

Guitarheroua commented Oct 22, 2024

WebSocketController Implementation

Based on the Draft design of new WebSockets, a new WebSocketController should be implemented as part of the new WebSocket subscription system. The draft design document describes all requirements and relationships between components.

Structure description:

type LimitsConfiguration struct {
    maxSubscriptions       uint64
    activeSubscriptions *atomic.Uint64

    maxResponsesPerSecond uint64
    sendMessageTimeout    time.Duration
}

type WebSocketBroker struct {
    logger zerolog.Logger

    conn *websocket.Conn // WebSocket connection for communication with the client

    subs map[string]DataProvider // The key is the subscription ID   
              
    limitsConfiguration LimitsConfiguration // Limits on the maximum number of subscriptions per connection, responses per second, and send message timeout.
            
    communicationChannel chan interface{}                     
}

API Description

  1. readMessages:
    This method runs while the connection is active. It retrieves, validates, and processes client messages. Actions handled include subscribe, unsubscribe, and list_subscriptions. Additional actions can be added as needed.

  2. writeMessages:
    This method runs while the connection is active, listening on the broadcast channel. It retrieves responses and sends them to the client.

  3. broadcastMessage:
    This method is called by each DataProvider, receiving formatted subscription messages and writing them to the broadcast channel.

  4. subscribe:
    Triggered by the readMessages method when the action is subscribe. It extracts the topic from the message’s topic field, creates the appropriate DataProvider for the topic using the factory function CreateSubscription, and adds an instance of the new handler to the subs map. The client receives a notification confirming the successful subscription along with the specific ID.

  5. unsubscribe:
    It is triggered by the readMessages method when the action is unsubscribe. It removes the relevant handler from the subs map by calling DataProvider::Close and notifying the client of successful unsubscription.

  6. listSubscriptions:
    It is triggered by the readMessages method when the action is list_subscriptions. It gathers all active subscriptions for the current connection, formats the response, and sends it back to the client.

@Guitarheroua Guitarheroua changed the title [Access] Implement new WebSocketBroker component to support multiple subscriptions per connection [Access] Implement new WebSocketBroker component to support multiple subscriptions per connection Oct 22, 2024
@Guitarheroua Guitarheroua changed the title [Access] Implement new WebSocketBroker component to support multiple subscriptions per connection [Access] Implement new web socket controller component Nov 12, 2024
@illia-malachyn illia-malachyn self-assigned this Nov 14, 2024
@Guitarheroua Guitarheroua removed their assignment Nov 19, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants