func main() { certFile := os.Getenv("RPCMQ_CERT") keyFile := os.Getenv("RPCMQ_KEY") caFile := os.Getenv("RPCMQ_CA") cert, err := tls.LoadX509KeyPair(certFile, keyFile) if err != nil { log.Fatalf("LoadX509KeyPair: %v", err) } caCert, err := ioutil.ReadFile(caFile) if err != nil { log.Fatalf("ReadFile: %v", err) } caCertPool := x509.NewCertPool() caCertPool.AppendCertsFromPEM(caCert) tlsConfig := &tls.Config{ Certificates: []tls.Certificate{cert}, RootCAs: caCertPool, } s := rpcmq.NewServer("amqps://amqp_broker:5671", "rpc-queue", "rpc-exchange", "direct") s.TLSConfig = tlsConfig if err := s.Register("toUpper", toUpper); err != nil { log.Fatalf("Register: %v", err) } if err := s.Init(); err != nil { log.Fatalf("Init: %v", err) } defer s.Shutdown() time.Sleep(1 * time.Minute) }
func main() { s := rpcmq.NewServer("amqp://amqp_broker:5672", "rpc-queue", "rpc-exchange", "fanout") if err := s.Register("toUpper", toUpper); err != nil { log.Fatalf("Register: %v", err) } if err := s.Init(); err != nil { log.Fatalf("Init: %v", err) } defer s.Shutdown() <-time.After(10 * time.Second) }
func main() { rpcmq.Log = log.New(os.Stderr, "server ", log.LstdFlags) s := rpcmq.NewServer("amqp://amqp_broker:5672", "rpc-queue", "rpc-exchange", "direct") if err := s.Register("echo", echo); err != nil { log.Fatalf("Register: %v", err) } if err := s.Init(); err != nil { log.Fatalf("Init: %v", err) } defer s.Shutdown() select {} }
func main() { if len(os.Args) != 2 { fmt.Printf("usage: godan-worker <configuration file>\n") os.Exit(2) } var err error config, err = loadConfig(os.Args[1]) if err != nil { log.Fatal(err) } cmds := make(chan monmq.Command) monmq.Log = log.New(os.Stderr, "", log.LstdFlags) a = monmq.NewAgent("amqp://"+config.Monmq.Host+":"+config.Monmq.Port, "mon-exchange", config.Name) a.HardShutdownFunc = func(data []byte) ([]byte, error) { cmds <- monmq.HardShutdown return nil, nil } a.SoftShutdownFunc = func(data []byte) ([]byte, error) { cmds <- monmq.SoftShutdown return nil, nil } a.ResumeFunc = func(data []byte) ([]byte, error) { cmds <- monmq.Resume return nil, nil } a.PauseFunc = func(data []byte) ([]byte, error) { cmds <- monmq.Pause return nil, nil } if err := a.Init(); err != nil { log.Fatalf("Init: %v", err) } s := rpcmq.NewServer("amqp://"+config.Rpcmq.Host+":"+config.Rpcmq.Port, config.Rpcmq.Queue, config.Rpcmq.Exchange, config.Rpcmq.ExchangeType) if err := s.Register("getService", getService); err != nil { log.Fatalf("Register: %v", err) } s.DeliveryMode = rpcmq.Transient s.Parallel = config.Monmq.Parallel if err := s.Init(); err != nil { log.Fatalf("Init: %v", err) } paused := false loop: for { switch <-cmds { case monmq.HardShutdown: log.Println("Hard shutdown...") break loop case monmq.SoftShutdown: log.Println("Soft shutdown...") s.Shutdown() a.Shutdown() break loop case monmq.Pause: if paused { continue } log.Println("Pause...") s.Shutdown() paused = true case monmq.Resume: if !paused { continue } log.Println("Resume...") if err := s.Init(); err != nil { log.Fatalln("Server init:", err) } paused = false } } }