1
0
mirror of https://github.com/mainflux/mainflux.git synced 2025-04-26 13:48:53 +08:00
Sammy Kerata Oina 83ff4e12ea
MF-512 - Change service default ports (#1737)
* Change service Default ports

Updated ports:
- auth http 9000
- auth grpc 7000
- provision http 9001
- things http 9002
- things auth http 9003
- things auth grpc 7001
- twins http 9004
- users http 9005
- bootstrap http 9006
- cassandra-reader http 9007
- cassandra-writer http 9008
- influxdb-reader http 9009
- influxdb-writer http 9010
- lora http 9011
- mongodb reader http 9012
- mongodb writer http 9013
- postgres-reader http 9014
- postgrs-writer http 9015
- smpp-notifier http 9016
- smtp-notifier http 9017
- timescale-reader http 9018
- timescale-writer http 9019

Signed-off-by: SammyOina <sammyoina@gmail.com>

* change default service ports on env and sh

Signed-off-by: SammyOina <sammyoina@gmail.com>

* change things url default port

Signed-off-by: SammyOina <sammyoina@gmail.com>

* change default ports order by importance
- auth http 9000
- auth grpc 7000
- things http 9001
- things auth http 9002
- things auth grpc 7001
- users http 9003
- cassandra-reader http 9004
- cassandra-writer http 9005
- influxdb-reader http 9006
- influxdb-writer http 9007
- mongodb reader http 9008
- mongodb writer http 9009
- postgres-reader http 9010
- postgres-writer http 9011
- timescale-reader http 9012
- timescale-writer http 9013
- bootstrap http 9014
- smpp-notifier http 9015
- smtp-notifier http 9016
- provision http 9017
- lora http 9018
- twins http 9019

Signed-off-by: SammyOina <sammyoina@gmail.com>

* lower port number in auth service

Signed-off-by: SammyOina <sammyoina@gmail.com>

* change things and users port
- things 9000
- things auth 9001
- things auth grpc 7000
- users 9002

Signed-off-by: SammyOina <sammyoina@gmail.com>

* update documentaton to new port numbers

Signed-off-by: SammyOina <sammyoina@gmail.com>

* update test and metrics

Signed-off-by: SammyOina <sammyoina@gmail.com>

* update host on metrics

Signed-off-by: SammyOina <sammyoina@gmail.com>

* resolving conflics

Signed-off-by: SammyOina <sammyoina@gmail.com>

* set http adapter port to :80

Signed-off-by: SammyOina <sammyoina@gmail.com>

* reassign http port on metrics to :80

Signed-off-by: SammyOina <sammyoina@gmail.com>

* reassign http adapter port

Signed-off-by: SammyOina <sammyoina@gmail.com>

* set http adapter port to 8008

Signed-off-by: SammyOina <sammyoina@gmail.com>

* document http adapter default port

Signed-off-by: SammyOina <sammyoina@gmail.com>

---------

Signed-off-by: SammyOina <sammyoina@gmail.com>
2023-03-23 21:55:11 +01:00

97 lines
2.9 KiB
Go

// Copyright (c) Mainflux
// SPDX-License-Identifier: Apache-2.0
package main
import (
"context"
"fmt"
"log"
"os"
"github.com/mainflux/mainflux/consumers"
"github.com/mainflux/mainflux/consumers/writers/api"
"github.com/mainflux/mainflux/consumers/writers/mongodb"
"github.com/mainflux/mainflux/internal"
mongoClient "github.com/mainflux/mainflux/internal/clients/mongo"
"github.com/mainflux/mainflux/internal/env"
"github.com/mainflux/mainflux/internal/server"
httpserver "github.com/mainflux/mainflux/internal/server/http"
mflog "github.com/mainflux/mainflux/logger"
"github.com/mainflux/mainflux/pkg/messaging/brokers"
"go.mongodb.org/mongo-driver/mongo"
"golang.org/x/sync/errgroup"
)
const (
svcName = "mongodb-writer"
envPrefix = "MF_MONGO_WRITER_"
envPrefixDB = "MF_MONGO_WRITER_DB_"
envPrefixHttp = "MF_MONGO_WRITER_HTTP_"
defSvcHttpPort = "9008"
)
type config struct {
LogLevel string `env:"MF_MONGO_WRITER_LOG_LEVEL" envDefault:"info"`
ConfigPath string `env:"MF_MONGO_WRITER_CONFIG_PATH" envDefault:"/config.toml"`
BrokerURL string `env:"MF_BROKER_URL" envDefault:"nats://localhost:4222"`
}
func main() {
ctx, cancel := context.WithCancel(context.Background())
g, ctx := errgroup.WithContext(ctx)
cfg := config{}
if err := env.Parse(&cfg); err != nil {
log.Fatalf("failed to load %s configuration : %s", svcName, err)
}
logger, err := mflog.New(os.Stdout, cfg.LogLevel)
if err != nil {
log.Fatalf("failed to init logger: %s", err)
}
pubSub, err := brokers.NewPubSub(cfg.BrokerURL, "", logger)
if err != nil {
logger.Fatal(fmt.Sprintf("failed to connect to message broker: %s", err))
}
defer pubSub.Close()
db, err := mongoClient.Setup(envPrefixDB)
if err != nil {
logger.Fatal(fmt.Sprintf("failed to setup mongo database : %s", err))
}
repo := newService(db, logger)
if err := consumers.Start(svcName, pubSub, repo, cfg.ConfigPath, logger); err != nil {
logger.Fatal(fmt.Sprintf("failed to start MongoDB writer: %s", err))
}
httpServerConfig := server.Config{Port: defSvcHttpPort}
if err := env.Parse(&httpServerConfig, env.Options{Prefix: envPrefixHttp, AltPrefix: envPrefix}); err != nil {
logger.Fatal(fmt.Sprintf("failed to load %s HTTP server configuration : %s", svcName, err))
}
hs := httpserver.New(ctx, cancel, svcName, httpServerConfig, api.MakeHandler(svcName), logger)
g.Go(func() error {
return hs.Start()
})
g.Go(func() error {
return server.StopSignalHandler(ctx, cancel, logger, svcName, hs)
})
if err := g.Wait(); err != nil {
logger.Error(fmt.Sprintf("MongoDB writer service terminated: %s", err))
}
}
func newService(db *mongo.Database, logger mflog.Logger) consumers.Consumer {
repo := mongodb.New(db)
repo = api.LoggingMiddleware(repo, logger)
counter, latency := internal.MakeMetrics("mongodb", "message_writer")
repo = api.MetricsMiddleware(repo, counter, latency)
return repo
}