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 WSBrokerHandler component #6593

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

[Access] Implement WSBrokerHandler component #6593

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

Comments

@Guitarheroua
Copy link
Collaborator

Guitarheroua commented Oct 24, 2024

Based on the Draft design of new WebSockets, a new WSBrokerHandler should be implemented as part of the new WebSocket subscription system, building upon the current WSHandler.

The new WSBrokerHandler should be created in router.go, similar to how the WSHandler is implemented. It can use a similar WSHandler approach:

func NewWSHandler(
logger zerolog.Logger,
api state_stream.API,
subscribeFunc SubscribeHandlerFunc,
chain flow.Chain,
stateStreamConfig backend.Config,
) *WSHandler {
handler := &WSHandler{
subscribeFunc: subscribeFunc,
api: api,
eventFilterConfig: stateStreamConfig.EventFilterConfig,
maxStreams: int32(stateStreamConfig.MaxGlobalStreams),
defaultHeartbeatInterval: stateStreamConfig.HeartbeatInterval,
activeStreamCount: atomic.NewInt32(0),
HttpHandler: NewHttpHandler(logger, chain),
}
return handler
}

A new AddPubSubRoute function should be added to router.go to separate the new WebSocket implementation from other REST API functionalities:

func (b *RouterBuilder) AddWsRoutes(
stateStreamApi state_stream.API,
chain flow.Chain,
stateStreamConfig backend.Config,
) *RouterBuilder {
for _, r := range WSRoutes {
h := NewWSHandler(b.logger, stateStreamApi, r.Handler, chain, stateStreamConfig)
b.v1SubRouter.
Methods(r.Method).
Path(r.Pattern).
Name(r.Name).
Handler(h)
}
return b
}

The main difference in the creation of this handler is that it will use a single route with the Name "ws" and Pattern "/ws", but without a handler function, as specific subscriptions will be managed internally by the new WebSocketBroker.

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

2 participants