Skip to content

Commit

Permalink
Adding additional frontend connector apis for merging listeners
Browse files Browse the repository at this point in the history
  • Loading branch information
pdelewski committed Dec 27, 2024
1 parent 820fdeb commit fb66348
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 6 deletions.
9 changes: 9 additions & 0 deletions quesma/frontend_connectors/basic_http_frontend_connector.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{} {
Expand Down Expand Up @@ -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
}
2 changes: 1 addition & 1 deletion quesma/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
2 changes: 2 additions & 0 deletions quesma/v2/core/quesma_apis.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 6 additions & 4 deletions quesma/v2/core/quesma_builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion quesma/v2/core/quesma_pipeline.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}
}

Expand Down

0 comments on commit fb66348

Please sign in to comment.