func main() { r := runner.New(Name) if err := r.Init(); err != nil { fmt.Println(err) return } appConfig := config.MustRead(r.Conf.Path) // create a realtime service provider instance. pubnub := models.NewPubNub(appConfig.GateKeeper.Pubnub, r.Log) defer pubnub.Close() // When we use the same RMQ connection for both, we received // 'Exception (504) Reason: "CHANNEL_ERROR - unexpected method in connection state running"' // error at some point. It needs debugging. rmqBroker, err := runner.NewRabbitMQ(r.Conf, r.Log).Connect() if err != nil { fmt.Println(err) return } defer rmqBroker.Conn().Close() broker := models.NewBroker(rmqBroker, r.Log) r.SetContext(dispatcher.NewController(r.Bongo.Broker.MQ, pubnub, broker)) r.ListenFor("dispatcher_channel_updated", (*dispatcher.Controller).UpdateChannel) r.ListenFor("dispatcher_message_updated", (*dispatcher.Controller).UpdateMessage) r.ListenFor("dispatcher_notify_user", (*dispatcher.Controller).NotifyUser) r.ListenFor("dispatcher_notify_group", (*dispatcher.Controller).NotifyGroup) r.ListenFor("event.channel_participant_removed_from_channel", (*dispatcher.Controller).RevokeChannelAccess) r.Listen() r.Wait() }
func main() { r := runner.New(Name) if err := r.Init(); err != nil { fmt.Println(err) return } appConfig := config.MustRead(r.Conf.Path) modelhelper.Initialize(appConfig.Mongo) defer modelhelper.Close() // create a realtime service provider instance. pubnub := models.NewPubNub(appConfig.GateKeeper.Pubnub, r.Log) defer pubnub.Close() mc := mux.NewConfig(Name, appConfig.GateKeeper.Host, appConfig.GateKeeper.Port) m := mux.New(mc, r.Log, r.Metrics) h := api.NewHandler(pubnub, appConfig, r.Log) h.AddHandlers(m) // consume messages from RMQ // Gatekeeper is not using RMQ, but runner is creating a message queue for // each worker. We need to discard the messages in the queue, otherwise // all the messages are piled up go r.Listen() m.Listen() defer m.Close() r.Wait() }
func main() { r := runner.New(Name) if err := r.Init(); err != nil { fmt.Println(err) return } defer r.Close() appConfig := config.MustRead(r.Conf.Path) modelhelper.Initialize(appConfig.Mongo) pubnub := models.NewPubNub(appConfig.GateKeeper.Pubnub, r.Log) defer pubnub.Close() handler, err := controller.New(r.Log, pubnub) if err != nil { panic(err) } if *flagSchedule { r.ShutdownHandler = handler.Shutdown if err := handler.Schedule(); err != nil { panic(err) } r.Wait() return } if *flagPubNub { handler.GrantPublicAccess() return } handler.Start() }