From fb6634866bbb025abb9214909c934ecc36d4740e Mon Sep 17 00:00:00 2001 From: Przemek Delewski Date: Fri, 27 Dec 2024 16:07:45 +0100 Subject: [PATCH] Adding additional frontend connector apis for merging listeners --- .../basic_http_frontend_connector.go | 9 +++++++++ quesma/main.go | 2 +- quesma/v2/core/quesma_apis.go | 2 ++ quesma/v2/core/quesma_builder.go | 10 ++++++---- quesma/v2/core/quesma_pipeline.go | 2 +- 5 files changed, 19 insertions(+), 6 deletions(-) diff --git a/quesma/frontend_connectors/basic_http_frontend_connector.go b/quesma/frontend_connectors/basic_http_frontend_connector.go index 51888c92a..8427a6ab5 100644 --- a/quesma/frontend_connectors/basic_http_frontend_connector.go +++ b/quesma/frontend_connectors/basic_http_frontend_connector.go @@ -31,6 +31,7 @@ type BasicHTTPFrontendConnector struct { debugInfoCollector diag.DebugInfoCollector logger quesma_api.QuesmaLogger middlewares []http.Handler + currentListener quesma_api.FrontendConnector } func (h *BasicHTTPFrontendConnector) GetChildComponents() []interface{} { @@ -182,3 +183,11 @@ func (h *BasicHTTPFrontendConnector) GetRouterInstance() *RouterV2 { func (h *BasicHTTPFrontendConnector) AddMiddleware(middleware http.Handler) { h.middlewares = append(h.middlewares, middleware) } + +func (h *BasicHTTPFrontendConnector) SetListener(listener quesma_api.FrontendConnector) { + h.currentListener = listener +} + +func (h *BasicHTTPFrontendConnector) Listener() quesma_api.FrontendConnector { + return h.currentListener +} diff --git a/quesma/main.go b/quesma/main.go index a42ab85fc..66f88508b 100644 --- a/quesma/main.go +++ b/quesma/main.go @@ -209,7 +209,7 @@ func constructQuesma(cfg *config.QuesmaConfiguration, sl clickhouse.TableDiscove if cfg.TransparentProxy { return quesma.NewQuesmaTcpProxy(cfg, quesmaManagementConsole, logChan, false) } else { - const quesma_v2 = false + const quesma_v2 = true return quesma.NewHttpProxy(phoneHomeAgent, lm, ip, sl, im, schemaRegistry, cfg, quesmaManagementConsole, abResultsrepository, indexRegistry, quesma_v2) } } diff --git a/quesma/v2/core/quesma_apis.go b/quesma/v2/core/quesma_apis.go index 9b59af592..4ec793861 100644 --- a/quesma/v2/core/quesma_apis.go +++ b/quesma/v2/core/quesma_apis.go @@ -25,6 +25,8 @@ type Router interface { type FrontendConnector interface { InstanceNamer + SetListener(listener FrontendConnector) + Listener() FrontendConnector Listen() error // Start listening on the endpoint GetEndpoint() string Stop(ctx context.Context) error // Stop listening diff --git a/quesma/v2/core/quesma_builder.go b/quesma/v2/core/quesma_builder.go index f1dcbf38c..bebd03614 100644 --- a/quesma/v2/core/quesma_builder.go +++ b/quesma/v2/core/quesma_builder.go @@ -80,14 +80,16 @@ func (quesma *Quesma) buildInternal() (QuesmaBuilder, error) { for _, conn := range pipeline.GetFrontendConnectors() { if httpConn, ok := conn.(HTTPFrontendConnector); ok { router := httpConn.GetRouter().Clone().(Router) - if len(endpoints) == 1 { - router.SetHandlers(handlers) - } + router.SetHandlers(handlers) httpConn.AddRouter(router) - } } } + for pipelineIndex, _ := range quesma.pipelines { + for frontendConnectorIndex := range quesma.pipelines[pipelineIndex].GetFrontendConnectors() { + quesma.pipelines[pipelineIndex].GetFrontendConnectors()[frontendConnectorIndex].SetListener(quesma.pipelines[0].GetFrontendConnectors()[0]) + } + } } for _, pipeline := range quesma.pipelines { diff --git a/quesma/v2/core/quesma_pipeline.go b/quesma/v2/core/quesma_pipeline.go index f8d85f682..f0d7e8f36 100644 --- a/quesma/v2/core/quesma_pipeline.go +++ b/quesma/v2/core/quesma_pipeline.go @@ -71,7 +71,7 @@ func (p *Pipeline) Start() { // however, bind error remains for _, conn := range p.FrontendConnectors { p.logger.Info().Msgf("Starting frontend connector %s", conn) - go conn.Listen() + go conn.Listener().Listen() } }