func main() { testService := NewTestService() config := skylib.GetServiceConfigFromFlags() config.Name = "TestService" config.Version = "1" config.Region = "Clearwater" var err error mlogger, err := skylib.NewMongoLogger("localhost", "skynet", "log", config) clogger := skylib.NewConsoleLogger(os.Stdout) config.Log = skylib.NewMultiLogger(mlogger, clogger) if err != nil { config.Log.Item("Could not connect to mongo db for logging") } service := skylib.CreateService(testService, config) // handle panic so that we remove ourselves from the pool in case of catastrophic failure defer func() { service.Shutdown() if err := recover(); err != nil { log.Println("Unrecovered error occured: ", err) } }() // If we pass false here service will not be Registered // we could do other work/tasks by implementing the Started method and calling Register() when we're ready service.Start(true) }
func main() { c := make(chan os.Signal, 1) config := &skylib.ClientConfig{ DoozerConfig: &skylib.DoozerConfig{ Uri: "127.0.0.1:8046", AutoDiscover: true, }, } var err error config.Log, err = skylib.NewMongoLogger("localhost", "skynet", "log") if err != nil { config.Log = skylib.NewConsoleLogger(os.Stderr) config.Log.Item("Could not connect to mongo db for logging") } client := skylib.NewClient(config) // This will not fail if no services currently exist, as connections are created on demand // this saves from chicken and egg issues with dependencies between services service := client.GetService("TestService", "", "", "") // any version, any region, any host // This on the other hand will fail if it can't find a service to connect to ret, err := service.Send("Upcase", "Upcase me!!") if err != nil { fmt.Println(err) return } fmt.Println(ret) watchSignals(c) }
// Daemon() will run and maintain skynet services. // // Daemon() will initially deploy those specified in the file given in the "-config" option // // Daemon() will run the "SkynetDeployment" service, which can be used to remotely spawn // new services on the host. func Daemon(q *skylib.Query, argv []string) { config, args := skylib.GetServiceConfigFromFlags(argv...) config.Name = "SkynetDaemon" config.Version = "1" config.Region = "Jersey" var err error mlogger, err := skylib.NewMongoLogger("localhost", "skynet", "log", config) clogger := skylib.NewConsoleLogger(os.Stdout) config.Log = skylib.NewMultiLogger(mlogger, clogger) if err != nil { config.Log.Item("Could not connect to mongo db for logging") } deployment := &SkynetDaemon{ Log: config.Log, Services: map[string]*SubService{}, } service := skylib.CreateService(deployment, config) // handle panic so that we remove ourselves from the pool in case of catastrophic failure defer func() { service.Shutdown() if err := recover(); err != nil { log.Println("Unrecovered error occured: ", err) } }() if len(args) == 2 { err := deployConfig(deployment, args[0]) if err != nil { config.Log.Item(err) } } // If we pass false here service will not be Registered // we could do other work/tasks by implementing the Started method and calling Register() when we're ready service.Start(true) }