|
|
|
@@ -23,16 +23,19 @@ import ( |
|
|
|
|
|
|
|
// ServerApp holds dependencies and state for the server service. |
|
|
|
type ServerApp struct { |
|
|
|
Cfg *config.Config |
|
|
|
DB *gorm.DB |
|
|
|
KafkaManager *kafkaclient.KafkaManager |
|
|
|
AppState *appcontext.AppState |
|
|
|
ChLoc chan model.HTTPLocation |
|
|
|
ChEvents chan appcontext.BeaconEvent |
|
|
|
ctx context.Context |
|
|
|
Server *http.Server |
|
|
|
Cleanup func() |
|
|
|
wg sync.WaitGroup |
|
|
|
Cfg *config.Config |
|
|
|
DB *gorm.DB |
|
|
|
KafkaManager *kafkaclient.KafkaManager |
|
|
|
AppState *appcontext.AppState |
|
|
|
ChLoc chan model.HTTPLocation |
|
|
|
ChEvents chan appcontext.BeaconEvent |
|
|
|
ChHealthLocation chan appcontext.LocationHealth |
|
|
|
ChHealthDecoder chan appcontext.DecoderHealth |
|
|
|
ChHealthBridge chan appcontext.BridgeHealth |
|
|
|
ctx context.Context |
|
|
|
Server *http.Server |
|
|
|
Cleanup func() |
|
|
|
wg sync.WaitGroup |
|
|
|
} |
|
|
|
|
|
|
|
// New creates a ServerApp: loads config, creates logger, connects DB, creates Kafka manager and writers. |
|
|
|
@@ -98,16 +101,22 @@ func (a *ServerApp) Init(ctx context.Context) error { |
|
|
|
slog.Error("UpdateDB", "err", err) |
|
|
|
} |
|
|
|
|
|
|
|
readerTopics := []string{"locevents", "alertbeacons", "health"} |
|
|
|
readerTopics := []string{"locevents", "alertbeacons", "healthlocation", "healthdecoder", "healthbridge"} |
|
|
|
a.KafkaManager.PopulateKafkaManager(a.Cfg.KafkaURL, "server", readerTopics) |
|
|
|
slog.Info("Kafka readers initialized", "topics", readerTopics) |
|
|
|
|
|
|
|
a.ChLoc = make(chan model.HTTPLocation, config.SMALL_CHANNEL_SIZE) |
|
|
|
a.ChEvents = make(chan appcontext.BeaconEvent, config.MEDIUM_CHANNEL_SIZE) |
|
|
|
a.ChHealthLocation = make(chan appcontext.LocationHealth, config.SMALL_CHANNEL_SIZE) |
|
|
|
a.ChHealthDecoder = make(chan appcontext.DecoderHealth, config.SMALL_CHANNEL_SIZE) |
|
|
|
a.ChHealthBridge = make(chan appcontext.BridgeHealth, config.SMALL_CHANNEL_SIZE) |
|
|
|
|
|
|
|
a.wg.Add(2) |
|
|
|
a.wg.Add(5) |
|
|
|
go kafkaclient.Consume(a.KafkaManager.GetReader("locevents"), a.ChLoc, ctx, &a.wg) |
|
|
|
go kafkaclient.Consume(a.KafkaManager.GetReader("alertbeacons"), a.ChEvents, ctx, &a.wg) |
|
|
|
go kafkaclient.Consume(a.KafkaManager.GetReader("healthlocation"), a.ChHealthLocation, ctx, &a.wg) |
|
|
|
go kafkaclient.Consume(a.KafkaManager.GetReader("healthdecoder"), a.ChHealthDecoder, ctx, &a.wg) |
|
|
|
go kafkaclient.Consume(a.KafkaManager.GetReader("healthbridge"), a.ChHealthBridge, ctx, &a.wg) |
|
|
|
|
|
|
|
a.Server = &http.Server{ |
|
|
|
Addr: a.Cfg.HTTPAddr, |
|
|
|
|