本文整理汇总了Golang中github.com/cloudfoundry/yagnats.Connect函数的典型用法代码示例。如果您正苦于以下问题:Golang Connect函数的具体用法?Golang Connect怎么用?Golang Connect使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了Connect函数的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: connectToNatsServer
func connectToNatsServer(c *config.Config, logger *steno.Logger) yagnats.NATSConn {
var natsClient yagnats.NATSConn
var err error
natsServers := c.NatsServers()
attempts := 3
for attempts > 0 {
natsClient, err = yagnats.Connect(natsServers)
if err == nil {
break
} else {
attempts--
time.Sleep(100 * time.Millisecond)
}
}
if err != nil {
logger.Errorf("Error connecting to NATS: %s\n", err)
os.Exit(1)
}
natsClient.AddClosedCB(func(conn *nats.Conn) {
logger.Errorf("Close on NATS client. nats.Conn: %+v", *conn)
os.Exit(1)
})
return natsClient
}
开发者ID:jungle0755,项目名称:gorouter,代码行数:28,代码来源:main.go
示例2: connectToMessageBus
func connectToMessageBus(l logger.Logger, conf *config.Config) yagnats.NATSConn {
members := make([]string, len(conf.NATS))
for _, natsConf := range conf.NATS {
uri := url.URL{
Scheme: "nats",
User: url.UserPassword(natsConf.User, natsConf.Password),
Host: fmt.Sprintf("%s:%d", natsConf.Host, natsConf.Port),
}
members = append(members, uri.String())
}
natsClient, err := yagnats.Connect(members)
if err != nil {
l.Error("Failed to connect to the message bus", err)
os.Exit(1)
}
natsClient.AddReconnectedCB(func(conn *nats.Conn) {
l.Info(fmt.Sprintf("NATS Client Reconnected. Server URL: %s", conn.Opts.Url))
})
natsClient.AddClosedCB(func(conn *nats.Conn) {
err := errors.New(fmt.Sprintf("NATS Client Closed. nats.Conn: %+v", conn))
l.Error("NATS Closed", err)
os.Exit(1)
})
return natsClient
}
开发者ID:nagyistge,项目名称:hm9000,代码行数:30,代码来源:common.go
示例3: connectToNatsServer
func connectToNatsServer(logger lager.Logger, c *config.Config) yagnats.NATSConn {
var natsClient yagnats.NATSConn
var err error
natsServers := c.NatsServers()
attempts := 3
for attempts > 0 {
natsClient, err = yagnats.Connect(natsServers)
if err == nil {
break
} else {
attempts--
time.Sleep(100 * time.Millisecond)
}
}
if err != nil {
logger.Fatal("nats-connection-error", err)
}
natsClient.AddClosedCB(func(conn *nats.Conn) {
logger.Fatal("nats-connection-closed", errors.New("unexpected close"), lager.Data{"connection": *conn})
})
return natsClient
}
开发者ID:sunatthegilddotcom,项目名称:gorouter,代码行数:26,代码来源:main.go
示例4: Start
func (runner *NATSRunner) Start() {
if runner.natsSession != nil {
panic("starting an already started NATS runner!!!")
}
_, err := exec.LookPath("gnatsd")
if err != nil {
fmt.Println("You need gnatsd installed!")
os.Exit(1)
}
cmd := exec.Command("gnatsd", "-p", strconv.Itoa(runner.port))
sess, err := gexec.Start(
cmd,
gexec.NewPrefixedWriter("\x1b[32m[o]\x1b[34m[gnatsd]\x1b[0m ", ginkgo.GinkgoWriter),
gexec.NewPrefixedWriter("\x1b[91m[e]\x1b[34m[gnatsd]\x1b[0m ", ginkgo.GinkgoWriter),
)
Expect(err).NotTo(HaveOccurred(), "Make sure to have gnatsd on your path")
runner.natsSession = sess
Expect(err).NotTo(HaveOccurred())
var messageBus yagnats.NATSConn
Eventually(func() error {
messageBus, err = yagnats.Connect([]string{fmt.Sprintf("nats://127.0.0.1:%d", runner.port)})
return err
}, 5, 0.1).ShouldNot(HaveOccurred())
runner.MessageBus = messageBus
}
开发者ID:qinguoan,项目名称:vulcan,代码行数:31,代码来源:nats_runner.go
示例5: newMessageBus
func newMessageBus(c *config.Config) (yagnats.NATSConn, error) {
natsMembers := make([]string, len(c.Nats))
for _, info := range c.Nats {
uri := url.URL{
Scheme: "nats",
User: url.UserPassword(info.User, info.Pass),
Host: fmt.Sprintf("%s:%d", info.Host, info.Port),
}
natsMembers = append(natsMembers, uri.String())
}
return yagnats.Connect(natsMembers)
}
开发者ID:jungle0755,项目名称:gorouter,代码行数:13,代码来源:main_test.go
示例6: Start
func (runner *NATSRunner) Start() {
_, err := exec.LookPath("gnatsd")
if err != nil {
fmt.Println("You need gnatsd installed!")
os.Exit(1)
}
runner.natsCommand = exec.Command("gnatsd", "-p", strconv.Itoa(runner.port))
err = runner.natsCommand.Start()
Ω(err).ShouldNot(HaveOccurred(), "Make sure to have gnatsd on your path")
var messageBus yagnats.NATSConn
Eventually(func() error {
messageBus, err = yagnats.Connect([]string{fmt.Sprintf("nats://127.0.0.1:%d", runner.port)})
return err
}, 5, 0.1).ShouldNot(HaveOccurred())
runner.MessageBus = messageBus
}
开发者ID:nagyistge,项目名称:hm9000,代码行数:18,代码来源:nats_runner.go
示例7: StartFakeRouter
func StartFakeRouter() {
var startMessage = func() []byte {
d := RouterStart{
MinimumRegisterIntervalInSeconds: 20,
}
value, _ := json.Marshal(d)
return value
}
natsMembers := make([]string, 1)
uri := url.URL{
Scheme: "nats",
User: url.UserPassword("", ""),
Host: "127.0.0.1:4222",
}
natsMembers = append(natsMembers, uri.String())
var natsClient yagnats.NATSConn
var err error
for i := 0; i < 10; i++ {
natsClient, err = yagnats.Connect(natsMembers)
if err == nil {
break
}
time.Sleep(time.Second)
}
Expect(err).ToNot(HaveOccurred())
natsClient.Subscribe("router.register", func(msg *nats.Msg) {
})
natsClient.Subscribe("router.greet", func(msg *nats.Msg) {
natsClient.Publish(msg.Reply, startMessage())
})
natsClient.Publish("router.start", startMessage())
}
开发者ID:lyuyun,项目名称:loggregator,代码行数:38,代码来源:integration_test_suite_test.go
示例8: main
func main() {
c := config.DefaultConfig()
logCounter := vcap.NewLogCounter()
if configFile != "" {
c = config.InitConfigFromFile(configFile)
}
InitLoggerFromConfig(c, logCounter)
logger := steno.NewLogger("router.main")
err := dropsonde.Initialize(c.Logging.MetronAddress, c.Logging.JobName)
if err != nil {
logger.Errorf("Dropsonde failed to initialize: %s", err.Error())
os.Exit(1)
}
// setup number of procs
if c.GoMaxProcs != 0 {
runtime.GOMAXPROCS(c.GoMaxProcs)
}
if c.DebugAddr != "" {
cf_debug_server.Run(c.DebugAddr)
}
natsServers := c.NatsServers()
var natsClient yagnats.NATSConn
attempts := 3
for attempts > 0 {
natsClient, err = yagnats.Connect(natsServers)
if err == nil {
break
} else {
attempts--
time.Sleep(100 * time.Millisecond)
}
}
if err != nil {
logger.Errorf("Error connecting to NATS: %s\n", err)
os.Exit(1)
}
natsClient.AddClosedCB(func(conn *nats.Conn) {
logger.Errorf("Close on NATS client. nats.Conn: %+v", *conn)
os.Exit(1)
})
registry := rregistry.NewRouteRegistry(c, natsClient)
if c.RoutingApiEnabled() {
logger.Info("Setting up routing_api route fetcher")
tokenFetcher := token_fetcher.NewTokenFetcher(&c.OAuth)
routingApiUri := fmt.Sprintf("%s:%d", c.RoutingApi.Uri, c.RoutingApi.Port)
routingApiClient := routing_api.NewClient(routingApiUri)
routeFetcher := route_fetcher.NewRouteFetcher(steno.NewLogger("router.route_fetcher"), tokenFetcher, registry, c, routingApiClient, 1)
routeFetcher.StartFetchCycle()
routeFetcher.StartEventCycle()
}
varz := rvarz.NewVarz(registry)
accessLogger, err := access_log.CreateRunningAccessLogger(c)
if err != nil {
logger.Fatalf("Error creating access logger: %s\n", err)
}
args := proxy.ProxyArgs{
EndpointTimeout: c.EndpointTimeout,
Ip: c.Ip,
TraceKey: c.TraceKey,
Registry: registry,
Reporter: varz,
AccessLogger: accessLogger,
SecureCookies: c.SecureCookies,
}
p := proxy.NewProxy(args)
router, err := router.NewRouter(c, p, natsClient, registry, varz, logCounter)
if err != nil {
logger.Errorf("An error occurred: %s", err.Error())
os.Exit(1)
}
signals := make(chan os.Signal, 1)
signal.Notify(signals, syscall.SIGTERM, syscall.SIGINT, syscall.SIGUSR1)
errChan := router.Run()
logger.Info("gorouter.started")
select {
case err := <-errChan:
if err != nil {
logger.Errorf("Error occurred: %s", err.Error())
os.Exit(1)
}
case sig := <-signals:
go func() {
//.........这里部分代码省略.........
开发者ID:trainchou,项目名称:gorouter,代码行数:101,代码来源:main.go
示例9: main
func main() {
c := config.DefaultConfig()
logCounter := vcap.NewLogCounter()
if configFile != "" {
c = config.InitConfigFromFile(configFile)
}
//config := configuration.Bootstrap()
InitLoggerFromConfig(c, logCounter)
logger := steno.NewLogger("ila.main")
logger.Info("started")
natsMembers := make([]string, len(c.Nats))
for _, info := range c.Nats {
uri := url.URL{
Scheme: "nats",
User: url.UserPassword(info.User, info.Pass),
Host: fmt.Sprintf("%s:%d", info.Host, info.Port),
}
natsMembers = append(natsMembers, uri.String())
}
natsClient, err := yagnats.Connect(natsMembers)
if err != nil {
logger.Fatalf("Error connecting to NATS: %s\n", err)
}
nman := manager.NewNatsManager(natsClient, c)
//nman.StartAppScalingControl()
nman.StartInstancesExamination()
nman.StartDeaExamination()
signals := make(chan os.Signal, 1)
signal.Notify(signals, syscall.SIGTERM, syscall.SIGINT, syscall.SIGUSR1)
//errChan := router.Run()
logger.Info("ila.started")
select {
//case err := <-errChan:
//if err != nil {
//logger.Errorf("Error occurred: %s", err.Error())
//os.Exit(1)
//}
case sig := <-signals:
go func() {
for sig := range signals {
logger.Infod(
map[string]interface{}{
"signal": sig.String(),
},
"ila.signal.ignored",
)
}
}()
if sig == syscall.SIGUSR1 {
logger.Infod(
map[string]interface{}{
"timeout": time.Now().String(),
},
"ila.timeout",
)
}
stoppingAt := time.Now()
logger.Infod(
map[string]interface{}{
"took": time.Since(stoppingAt).String(),
},
"ila.stopped",
)
}
os.Exit(0)
}
开发者ID:mgazz,项目名称:ila,代码行数:86,代码来源:main.go
注:本文中的github.com/cloudfoundry/yagnats.Connect函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论