• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Golang yagnats.NewClient函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Golang中github.com/cloudfoundry/yagnats.NewClient函数的典型用法代码示例。如果您正苦于以下问题:Golang NewClient函数的具体用法?Golang NewClient怎么用?Golang NewClient使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了NewClient函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。

示例1: NewHandlerProvider

func NewHandlerProvider(settings boshsettings.Service, logger boshlog.Logger) (p mbusHandlerProvider) {
	p.settings = settings
	p.handlers = map[string]Handler{
		"nats": newNatsHandler(settings, logger, yagnats.NewClient()),
	}
	return
}
开发者ID:ian-plosker,项目名称:bosh,代码行数:7,代码来源:handler_provider.go


示例2: main

func main() {
	c := make(chan os.Signal, 1)
	signal.Notify(c, os.Interrupt)

	log.Printf("Sending messages...\n")

	client := yagnats.NewClient()
	err := client.Connect(&yagnats.ConnectionInfo{"127.0.0.1:4222", "nats", "nats"})
	if err != nil {
		log.Fatalf("Error connecting: %s\n", err)
	}

	seen := 0

	client.Subscribe("foo", func(msg *yagnats.Message) {
		seen += 1
	})

	go func() {
		for {
			client.Publish("foo", []byte("hi"))
		}
	}()

	<-c
	log.Printf("Messages processed: %d\n", seen)
}
开发者ID:nimbus-cloud,项目名称:gorouter,代码行数:27,代码来源:stress.go


示例3: connectToMessageBus

func connectToMessageBus(l logger.Logger, conf *config.Config) yagnats.NATSClient {
	members := []yagnats.ConnectionProvider{}

	for _, natsConf := range conf.NATS {
		members = append(members, &yagnats.ConnectionInfo{
			Addr: fmt.Sprintf("%s:%d", natsConf.Host, natsConf.Port),

			Username: natsConf.User,
			Password: natsConf.Password,
		})
	}

	connectionInfo := &yagnats.ConnectionCluster{
		Members: members,
	}

	natsClient := yagnats.NewClient()

	err := natsClient.Connect(connectionInfo)

	if err != nil {
		l.Error("Failed to connect to the message bus", err)
		os.Exit(1)
	}

	return natsClient
}
开发者ID:tomzhang,项目名称:golang-devops-stuff,代码行数:27,代码来源:common.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),
	)
	Ω(err).ShouldNot(HaveOccurred(), "Make sure to have gnatsd on your path")

	runner.natsSession = sess

	connectionInfo := &yagnats.ConnectionInfo{
		Addr: fmt.Sprintf("127.0.0.1:%d", runner.port),
	}

	messageBus := yagnats.NewClient()

	Eventually(func() error {
		return messageBus.Connect(connectionInfo)
	}, 5, 0.1).ShouldNot(HaveOccurred())

	runner.MessageBus = messageBus
}
开发者ID:tomzhang,项目名称:golang-devops-stuff,代码行数:33,代码来源:nats_runner.go


示例5: TestHandlerProviderGetReturnsNatsHandler

func TestHandlerProviderGetReturnsNatsHandler(t *testing.T) {
	deps, provider := buildProvider("nats://0.0.0.0")
	handler, err := provider.Get(deps.platform, deps.dirProvider)

	assert.NoError(t, err)
	assert.IsType(t, NewNatsHandler(deps.settings, deps.logger, yagnats.NewClient()), handler)
}
开发者ID:reneedv,项目名称:bosh,代码行数:7,代码来源:handler_provider_test.go


示例6: Get

func (p mbusHandlerProvider) Get() (handler Handler, err error) {
	if p.handler != nil {
		handler = p.handler
		return
	}

	mbusUrl, err := url.Parse(p.settings.GetMbusUrl())
	if err != nil {
		err = bosherr.WrapError(err, "Parsing handler URL")
		return
	}

	switch mbusUrl.Scheme {
	case "nats":
		handler = newNatsHandler(p.settings, p.logger, yagnats.NewClient())
	case "https":
		handler = newHttpsHandler(mbusUrl, p.logger)
	default:
		err = bosherr.New("Message Bus Handler with scheme %s could not be found", mbusUrl.Scheme)
	}

	p.handler = handler

	return
}
开发者ID:kangaroo,项目名称:bosh,代码行数:25,代码来源:handler_provider.go


示例7: main

func main() {
	c := make(chan os.Signal, 1)
	signal.Notify(c, os.Interrupt)

	log.Printf("Receiving messages...\n")

	client := yagnats.NewClient()
	err := client.Connect(&yagnats.ConnectionInfo{"127.0.0.1:4222", "nats", "nats"})
	if err != nil {
		log.Fatalf("Error connecting: %s\n", err)
	}

	seen := 0

	client.Subscribe("foo", func(msg *yagnats.Message) {
		for i := 0; i < 1000000; i++ {
			fmt.Printf("")
		}
		seen += 1
		fmt.Printf("got it! %d\n", seen)
	})

	<-c
	log.Printf("Messages processed: %d\n", seen)
}
开发者ID:johntdyer,项目名称:golang-devops-stuff,代码行数:25,代码来源:slow-consumer.go


示例8: Get

func (p MbusHandlerProvider) Get(
	platform boshplatform.Platform,
	dirProvider boshdir.DirectoriesProvider,
) (handler boshhandler.Handler, err error) {
	if p.handler != nil {
		handler = p.handler
		return
	}

	mbusURL, err := url.Parse(p.settings.GetMbusURL())
	if err != nil {
		err = bosherr.WrapError(err, "Parsing handler URL")
		return
	}

	switch mbusURL.Scheme {
	case "nats":
		handler = NewNatsHandler(p.settings, p.logger, yagnats.NewClient())
	case "https":
		handler = micro.NewHTTPSHandler(mbusURL, p.logger, platform.GetFs(), dirProvider)
	default:
		err = bosherr.New("Message Bus Handler with scheme %s could not be found", mbusURL.Scheme)
	}

	p.handler = handler

	return
}
开发者ID:Jane4PKU,项目名称:bosh,代码行数:28,代码来源:handler_provider.go


示例9: init

func init() {
	Describe("Testing with Ginkgo", func() {
		It("handler provider get returns nats handler", func() {
			deps, provider := buildProvider("nats://0.0.0.0")
			handler, err := provider.Get(deps.platform, deps.dirProvider)

			Expect(err).ToNot(HaveOccurred())
			assert.IsType(GinkgoT(), NewNatsHandler(deps.settings, deps.logger, yagnats.NewClient()), handler)
		})
		It("handler provider get returns https handler", func() {

			deps, provider := buildProvider("https://0.0.0.0")
			handler, err := provider.Get(deps.platform, deps.dirProvider)

			Expect(err).ToNot(HaveOccurred())
			assert.IsType(GinkgoT(), micro.HttpsHandler{}, handler)
		})
		It("handler provider get returns an error if not supported", func() {

			deps, provider := buildProvider("foo://0.0.0.0")
			_, err := provider.Get(deps.platform, deps.dirProvider)

			Expect(err).To(HaveOccurred())
		})
	})
}
开发者ID:velankanisys,项目名称:bosh,代码行数:26,代码来源:handler_provider_test.go


示例10: NewHandlerProvider

func NewHandlerProvider(settings boshsettings.Settings) (p mbusHandlerProvider) {
	p.settings = settings
	p.handlers = map[string]Handler{
		"nats": newNatsHandler(yagnats.NewClient(), settings),
	}
	return
}
开发者ID:nicregez,项目名称:bosh,代码行数:7,代码来源:handler_provider.go


示例11: connect

func (adapter *NatsAdapter) connect() error {
	addr := fmt.Sprintf("%s:%d", adapter.host, adapter.port)

	client := nats.NewClient()

	client.ConnectedCallback = func() {
		if adapter.connectedCallback != nil {
			adapter.connectedCallback()
		}
	}

	if adapter.logger != nil {
		client.Logger = adapter.logger
	}

	err := client.Connect(&nats.ConnectionInfo{
		Addr:     addr,
		Username: adapter.user,
		Password: adapter.password,
	})

	if err != nil {
		return err
	}

	adapter.client = client
	adapter.rand = rand.New(rand.NewSource(time.Now().UnixNano()))

	for _, sub := range adapter.subscriptions {
		subscribeInNats(adapter, sub)
	}

	return nil
}
开发者ID:nogoodbay,项目名称:go_cfmessagebus,代码行数:34,代码来源:nats.go


示例12: main

func main() {
	c := make(chan os.Signal, 1)
	signal.Notify(c, os.Interrupt)

	log.Printf("Sending messages...\n")

	client := yagnats.NewClient()
	err := client.Connect(&yagnats.ConnectionInfo{
		Addr:     "127.0.0.1:4222",
		Username: "nats",
		Password: "nats",
	})
	if err != nil {
		log.Fatalf("Error connecting: %s\n", err)
	}

	bigbyte := make([]byte, 512000)
	go func() {
		for {
			client.Publish("foo", bigbyte)
		}
	}()

	<-c
	log.Printf("Bye!\n")
}
开发者ID:aemengo,项目名称:yagnats,代码行数:26,代码来源:fast-producer.go


示例13: buildMessageBus

func buildMessageBus(registrar *Registrar) (messageBus yagnats.NATSClient) {

	messageBus = yagnats.NewClient()
	natsServers := []yagnats.ConnectionProvider{}

	for _, server := range registrar.Config.MessageBusServers {
		registrar.logger.Info(
			"Adding NATS server",
			lager.Data{"server": server},
		)
		natsServers = append(natsServers, &yagnats.ConnectionInfo{
			server.Host,
			server.User,
			server.Password,
			nil,
		})
	}

	natsInfo := &yagnats.ConnectionCluster{natsServers}

	err := messageBus.Connect(natsInfo)

	if err != nil {
		registrar.logger.Info(
			"Error connecting to NATS",
			lager.Data{"error": err.Error()},
		)
		panic("Failed to connect to NATS bus.")
	}

	registrar.logger.Info("Successfully connected to NATS.")

	return
}
开发者ID:MatthiasWinzeler,项目名称:route-registrar,代码行数:34,代码来源:registrar.go


示例14: main

func main() {
	flag.Parse()

	nats := yagnats.NewClient()

	natsMembers := []yagnats.ConnectionProvider{}

	if *natsAddresses == "" {
		log.Fatalln("must specify at least one nats address (-natsAddresses=1.2.3.4:5678)")
	}

	if *ip == "" {
		log.Fatalln("must specify IP to route to (-ip=X)")
	}

	for _, addr := range strings.Split(*natsAddresses, ",") {
		log.Println("configuring nats server:", addr)
		natsMembers = append(natsMembers, &yagnats.ConnectionInfo{
			Addr:     addr,
			Username: *natsUsername,
			Password: *natsPassword,
		})
	}

	if len(natsMembers) == 0 {
		log.Fatalln("must specify at least one nats address")
	}

	natsInfo := &yagnats.ConnectionCluster{natsMembers}

	for {
		err := nats.Connect(natsInfo)
		if err == nil {
			break
		}

		log.Println("failed to connect to NATS:", err)
		time.Sleep(1 * time.Second)
	}

	client := gibson.NewCFRouterClient(*ip, nats)

	client.Greet()

	for _, route := range strings.Split(*routes, ",") {
		routePair := strings.Split(route, ":")
		if len(routePair) != 2 {
			log.Fatalln("invalid route configuration:", *routes)
		}

		port, err := strconv.Atoi(routePair[0])
		if err != nil {
			log.Fatalln("invalid route port:", err)
		}

		client.Register(port, routePair[1])
	}

	select {}
}
开发者ID:MatthiasWinzeler,项目名称:gibson,代码行数:60,代码来源:main.go


示例15: NewRouter

func NewRouter(c *config.Config) *Router {
	router := &Router{
		config: c,
	}

	// setup number of procs
	if router.config.GoMaxProcs != 0 {
		runtime.GOMAXPROCS(router.config.GoMaxProcs)
	}

	router.mbusClient = yagnats.NewClient()

	router.registry = registry.NewCFRegistry(router.config, router.mbusClient)
	router.registry.StartPruningCycle()

	router.varz = varz.NewVarz(router.registry)
	args := proxy.ProxyArgs{
		EndpointTimeout: router.config.EndpointTimeout,
		Ip:              router.config.Ip,
		TraceKey:        router.config.TraceKey,
		Registry:        router.registry,
		Reporter:        router.varz,
		Logger:          access_log.CreateRunningAccessLogger(router.config),
	}
	router.proxy = proxy.NewProxy(args)

	var host string
	if router.config.Status.Port != 0 {
		host = fmt.Sprintf("%s:%d", router.config.Ip, router.config.Status.Port)
	}

	varz := &vcap.Varz{
		UniqueVarz: router.varz,
	}
	varz.LogCounts = log.Counter

	healthz := &vcap.Healthz{
		LockableObject: router.registry,
	}

	router.component = &vcap.VcapComponent{
		Type:        "Router",
		Index:       router.config.Index,
		Host:        host,
		Credentials: []string{router.config.Status.User, router.config.Status.Pass},
		Config:      router.config,
		Varz:        varz,
		Healthz:     healthz,
		InfoRoutes: map[string]json.Marshaler{
			"/routes": router.registry,
		},
	}

	vcap.StartComponent(router.component)

	return router
}
开发者ID:BrianMMcClain,项目名称:gorouter,代码行数:57,代码来源:router.go


示例16: main

func main() {
	flag.Parse()

	if *natsAddrs == "" {
		panic("need either nats addr")
	}

	client := yagnats.NewClient()

	clusterInfo := &yagnats.ConnectionCluster{}

	for _, addr := range strings.Split(*natsAddrs, ",") {
		clusterInfo.Members = append(clusterInfo.Members, &yagnats.ConnectionInfo{
			Addr: addr,
		})
	}

	err := client.Connect(clusterInfo)

	if err != nil {
		log.Fatalln("no nats:", err)
	}

	semaphore := make(chan bool, *maxConcurrent)

	repclient := repnatsclient.New(client, *timeout)

	client.SubscribeWithQueue("diego.auction", "auction-channel", func(msg *yagnats.Message) {
		semaphore <- true
		defer func() {
			<-semaphore
		}()

		var auctionRequest types.AuctionRequest
		err := json.Unmarshal(msg.Payload, &auctionRequest)
		if err != nil {
			client.Publish(msg.ReplyTo, errorResponse)
			return
		}

		auctionResult := auctioneer.Auction(repclient, auctionRequest)
		payload, _ := json.Marshal(auctionResult)

		client.Publish(msg.ReplyTo, payload)
	})

	fmt.Println("auctioneering")

	select {}
}
开发者ID:vito,项目名称:auction,代码行数:50,代码来源:main.go


示例17: newMessageBus

func newMessageBus(c *config.Config) (yagnats.NATSClient, error) {
	natsClient := yagnats.NewClient()
	natsMembers := []yagnats.ConnectionProvider{}

	for _, info := range c.Nats {
		natsMembers = append(natsMembers, &yagnats.ConnectionInfo{
			Addr:     fmt.Sprintf("%s:%d", info.Host, info.Port),
			Username: info.User,
			Password: info.Pass,
		})
	}

	err := natsClient.Connect(&yagnats.ConnectionCluster{
		Members: natsMembers,
	})

	return natsClient, err
}
开发者ID:KeyOfSpectator,项目名称:gorouter,代码行数:18,代码来源:main_test.go


示例18: main

func main() {
	cfg := flag.String("c", "cfg.json", "configuration file")
	flag.Parse()
	err := config.ParseConfig(*cfg)
	if err != nil {
		fmt.Println(err.Error())
		return
	}

	agent := agent.New("Huawei", 3, yagnats.NewClient())

	err = agent.Setup()
	if err != nil {
		fmt.Println(err.Error())
	}

	agent.Hearbeat()
}
开发者ID:yj2317916,项目名称:yj-agent,代码行数:18,代码来源:main.go


示例19: main

func main() {
	flag.Parse()

	store := etcd.NewClient(strings.Split(*etcdCluster, ","))

	nats := yagnats.NewClient()

	natsInfo := &yagnats.ConnectionInfo{
		Addr:     *natsAddr,
		Username: *natsUser,
		Password: *natsPass,
	}

	err := nats.Connect(natsInfo)
	if err != nil {
		log.Fatalln(err)
	}

	node := executor.NewNode(store, time.Duration(*heartbeatInterval)*time.Second)

	starter := starter.NewStarter(node)

	go hero.SaveLives(store, starter)

	_, err = nats.Subscribe("app.start", func(msg *yagnats.Message) {
		var startMsg messages.AppStart
		err := json.Unmarshal([]byte(msg.Payload), &startMsg)
		if err != nil {
			log.Println("failed to unmarshal", msg.Payload)
			return
		}

		starter.Start(startMsg.Guid, startMsg.Index)
	})

	if err != nil {
		log.Fatalln(err)
	}

	for {
		time.Sleep(1 * time.Second)
		node.LogRegistry()
	}
}
开发者ID:vito,项目名称:executor-pool-spike,代码行数:44,代码来源:main.go


示例20: 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")

	connectionInfo := &yagnats.ConnectionInfo{
		Addr: fmt.Sprintf("127.0.0.1:%d", runner.port),
	}

	messageBus := yagnats.NewClient()

	Eventually(func() error {
		return messageBus.Connect(connectionInfo)
	}, 5, 0.1).ShouldNot(HaveOccurred())

	runner.MessageBus = messageBus
}
开发者ID:nkts,项目名称:golang-devops-stuff,代码行数:23,代码来源:nats_runner.go



注:本文中的github.com/cloudfoundry/yagnats.NewClient函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Golang yagnats.NATSClient类代码示例发布时间:2022-05-23
下一篇:
Golang yagnats.Connect函数代码示例发布时间:2022-05-23
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap