Files
janus/schema/schema_util.go

42 lines
1.2 KiB
Go
Raw Normal View History

package schema
2021-03-30 13:16:00 +05:30
import (
"com.navi.medici.janus/config"
"com.navi.medici.janus/utils"
2021-05-12 15:26:13 +05:30
"fmt"
2021-03-30 13:16:00 +05:30
"github.com/riferrei/srclient"
"go.uber.org/zap"
"strings"
2021-03-30 13:16:00 +05:30
)
var (
SchemaRegistryEndpoint string
TopicList []string
SchemaVersionMap = make(map[string]int)
logger *zap.Logger
2021-03-30 13:16:00 +05:30
)
func InitializeSchemaHandler(configuration config.Configurations) {
logger = utils.GetLogger()
SchemaRegistryEndpoint = configuration.SchemaRegistry.Endpoint
TopicList = strings.Split(configuration.SchemaRegistry.Topics, ",")
// initialize schema version map which contains latest schema version for topic(s)
GetSchemaVersions()
}
2021-03-30 13:16:00 +05:30
2021-05-07 20:35:35 +05:30
func GetSchemaVersions() {
2021-03-30 13:16:00 +05:30
2021-05-07 20:35:35 +05:30
schemaRegistryClient := srclient.CreateSchemaRegistryClient(SchemaRegistryEndpoint)
2021-03-30 13:16:00 +05:30
schemaRegistryClient.CodecCreationEnabled(false)
2021-05-07 20:35:35 +05:30
for _, topic := range TopicList {
2021-03-30 13:16:00 +05:30
schema, err := schemaRegistryClient.GetLatestSchema(topic, false)
if err != nil {
logger.Error("error in fetching latest schema", zap.Error(err))
2021-03-30 13:16:00 +05:30
} else {
schemaId := schema.ID()
SchemaVersionMap[topic] = schemaId
2021-03-30 13:16:00 +05:30
}
}
logger.Debug("Schema Version Map", zap.String("", fmt.Sprintf("%v", SchemaVersionMap)))
2021-05-12 15:26:13 +05:30
}