// NewService loads configs and starts listeners func NewService(config *Config) Service { // setup echo echo := echo.New() echopprof.Wrapper(echo) logger := log.New(os.Stderr, "EVENT CONSUMER:", log.Ldate|log.Ltime|log.Lshortfile) DBAdaptor := database.NewAdaptor(strings.Split(config.CassandraInterfaces, ","), config.CassandraUser, config.CassandraPassword) CacheAdaptor := cache.NewAdaptor(config.CacheURL, config.CacheRedisPassword) service := Service{ Logger: logger, config: config, Router: Routes( // add each dependent service as a dependency to the router dependencies{ config: config, DBAdaptor: DBAdaptor, CacheAdaptor: CacheAdaptor, Router: echo, }, ), DBAdaptor: DBAdaptor, } return service }
func NewService(config *Config) Service { logger := log.New(os.Stderr, "EVENT CONSUMER:", log.Ldate|log.Ltime|log.Lshortfile) DBAdaptor := database.NewAdaptor(strings.Split(config.CassandraInterfaces, ","), config.CassandraUser, config.CassandraPassword) dispatcher := NewDispatcher(config.MaxWorker, config.MaxJobQueue, logger, DBAdaptor) return Service{ Logger: logger, config: config, Dispatcher: dispatcher, DBAdaptor: DBAdaptor, } }
func setUp(cmd *cobra.Command, args []string) { fmt.Println("[+] Running Cassandra set up ") var config consumerapi.Config if err := envconfig.Process("CONSUMER", &config); err != nil { log.Fatal("Error occurred during startup:", err.Error()) } cluster := gocql.NewCluster(strings.Split(config.CassandraInterfaces, ",")...) cluster.ProtoVersion = 3 session, err := cluster.CreateSession() if err != nil { log.Print(err.Error()) return } q := session.Query("CREATE KEYSPACE IF NOT EXISTS events WITH REPLICATION = { 'class' : 'SimpleStrategy', 'replication_factor' : 1};", "") if err := q.Exec(); err != nil { log.Print(err.Error()) } DBAdaptor := database.NewAdaptor(strings.Split(config.CassandraInterfaces, ","), config.CassandraUser, config.CassandraPassword) for _, indexField := range database.IndexFields { eventsTable := DBAdaptor.GetEventMultimapTable(indexField) if err := eventsTable.Create(); err != nil { log.Print(err.Error()) } } eventTable := DBAdaptor.GetTimeSeriesEventTable() if err := eventTable.Create(); err != nil { log.Print(err.Error()) } eventMapTable := DBAdaptor.GetEventMapTable() if err := eventMapTable.Create(); err != nil { log.Print(err.Error()) } }