diff --git a/quesma/frontend_connectors/basic_http_frontend_connector.go b/quesma/frontend_connectors/basic_http_frontend_connector.go index 8427a6ab5..5963f9e64 100644 --- a/quesma/frontend_connectors/basic_http_frontend_connector.go +++ b/quesma/frontend_connectors/basic_http_frontend_connector.go @@ -31,7 +31,7 @@ type BasicHTTPFrontendConnector struct { debugInfoCollector diag.DebugInfoCollector logger quesma_api.QuesmaLogger middlewares []http.Handler - currentListener quesma_api.FrontendConnector + connector quesma_api.FrontendConnector } func (h *BasicHTTPFrontendConnector) GetChildComponents() []interface{} { @@ -184,10 +184,10 @@ 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) SetConnector(connector quesma_api.FrontendConnector) { + h.connector = connector } -func (h *BasicHTTPFrontendConnector) Listener() quesma_api.FrontendConnector { - return h.currentListener +func (h *BasicHTTPFrontendConnector) Connector() quesma_api.FrontendConnector { + return h.connector } diff --git a/quesma/v2/core/quesma_apis.go b/quesma/v2/core/quesma_apis.go index 4ec793861..5eca016ce 100644 --- a/quesma/v2/core/quesma_apis.go +++ b/quesma/v2/core/quesma_apis.go @@ -25,8 +25,16 @@ type Router interface { type FrontendConnector interface { InstanceNamer - SetListener(listener FrontendConnector) - Listener() FrontendConnector + // SetConnector sets the connector + // Connectors are the components that listen for incoming requests + // They can be shared for instance in the case when + // the same tcp port is used + // SetConnector and Connector are used to set and get the connector + // and merge the connectors + SetConnector(listener FrontendConnector) + // Connector returns the connector + Connector() FrontendConnector + // Listen starts listening on the endpoint 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 bebd03614..ab394ceec 100644 --- a/quesma/v2/core/quesma_builder.go +++ b/quesma/v2/core/quesma_builder.go @@ -87,7 +87,7 @@ func (quesma *Quesma) buildInternal() (QuesmaBuilder, error) { } for pipelineIndex, _ := range quesma.pipelines { for frontendConnectorIndex := range quesma.pipelines[pipelineIndex].GetFrontendConnectors() { - quesma.pipelines[pipelineIndex].GetFrontendConnectors()[frontendConnectorIndex].SetListener(quesma.pipelines[0].GetFrontendConnectors()[0]) + quesma.pipelines[pipelineIndex].GetFrontendConnectors()[frontendConnectorIndex].SetConnector(quesma.pipelines[0].GetFrontendConnectors()[0]) } } } diff --git a/quesma/v2/core/quesma_pipeline.go b/quesma/v2/core/quesma_pipeline.go index f0d7e8f36..bd7ccbdda 100644 --- a/quesma/v2/core/quesma_pipeline.go +++ b/quesma/v2/core/quesma_pipeline.go @@ -71,7 +71,12 @@ func (p *Pipeline) Start() { // however, bind error remains for _, conn := range p.FrontendConnectors { p.logger.Info().Msgf("Starting frontend connector %s", conn) - go conn.Listener().Listen() + go func() { + err := conn.Connector().Listen() + if err != nil { + p.logger.Error().Err(err).Msgf("Failed to start frontend connector %s", conn) + } + }() } }