當前位置: 首頁>>代碼示例>>Golang>>正文


Golang pubsub.Client類代碼示例

本文整理匯總了Golang中google/golang.org/cloud/pubsub.Client的典型用法代碼示例。如果您正苦於以下問題:Golang Client類的具體用法?Golang Client怎麽用?Golang Client使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


在下文中一共展示了Client類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

示例1: deleteSubscription

func deleteSubscription(client *pubsub.Client, argv []string) {
	checkArgs(argv, 2)
	sub := argv[1]
	err := client.Subscription(sub).Delete(context.Background())
	if err != nil {
		log.Fatalf("Deleting Subscription failed: %v", err)
	}
	fmt.Printf("Subscription %s was deleted.\n", sub)
}
開發者ID:trythings,項目名稱:trythings,代碼行數:9,代碼來源:main.go

示例2: createTopic

func createTopic(client *pubsub.Client, argv []string) {
	checkArgs(argv, 2)
	topic := argv[1]
	_, err := client.NewTopic(context.Background(), topic)
	if err != nil {
		log.Fatalf("Creating topic failed: %v", err)
	}
	fmt.Printf("Topic %s was created.\n", topic)
}
開發者ID:trythings,項目名稱:trythings,代碼行數:9,代碼來源:main.go

示例3: deleteTopic

func deleteTopic(client *pubsub.Client, argv []string) {
	checkArgs(argv, 2)
	topic := argv[1]
	err := client.Topic(topic).Delete(context.Background())
	if err != nil {
		log.Fatalf("Deleting topic failed: %v", err)
	}
	fmt.Printf("Topic %s was deleted.\n", topic)
}
開發者ID:trythings,項目名稱:trythings,代碼行數:9,代碼來源:main.go

示例4: checkTopicExists

func checkTopicExists(client *pubsub.Client, argv []string) {
	checkArgs(argv, 1)
	topic := argv[1]
	exists, err := client.Topic(topic).Exists(context.Background())
	if err != nil {
		log.Fatalf("Checking topic exists failed: %v", err)
	}
	fmt.Println(exists)
}
開發者ID:trythings,項目名稱:trythings,代碼行數:9,代碼來源:main.go

示例5: checkSubscriptionExists

func checkSubscriptionExists(client *pubsub.Client, argv []string) {
	checkArgs(argv, 1)
	sub := argv[1]
	exists, err := client.Subscription(sub).Exists(context.Background())
	if err != nil {
		log.Fatalf("Checking subscription exists failed: %v", err)
	}
	fmt.Println(exists)
}
開發者ID:trythings,項目名稱:trythings,代碼行數:9,代碼來源:main.go

示例6: createSubscription

func createSubscription(client *pubsub.Client, argv []string) {
	checkArgs(argv, 3)
	sub := argv[1]
	topic := argv[2]
	_, err := client.NewSubscription(context.Background(), sub, client.Topic(topic), 0, nil)
	if err != nil {
		log.Fatalf("Creating Subscription failed: %v", err)
	}
	fmt.Printf("Subscription %s was created.\n", sub)
}
開發者ID:trythings,項目名稱:trythings,代碼行數:10,代碼來源:main.go

示例7: listTopics

func listTopics(client *pubsub.Client, argv []string) {
	checkArgs(argv, 1)
	topics, err := client.Topics(context.Background())
	if err != nil {
		log.Fatalf("Listing topics failed: %v", err)
	}
	for _, t := range topics {
		fmt.Println(t.Name())
	}
}
開發者ID:takbok,項目名稱:shared-contacts-admin,代碼行數:10,代碼來源:main.go

示例8: listSubscriptions

func listSubscriptions(client *pubsub.Client, argv []string) {
	checkArgs(argv, 1)
	subs, err := client.Subscriptions(context.Background())
	if err != nil {
		log.Fatalf("Listing subscriptions failed: %v", err)
	}
	for _, s := range subs {
		fmt.Println(s.Name())
	}
}
開發者ID:takbok,項目名稱:shared-contacts-admin,代碼行數:10,代碼來源:main.go

示例9: publish

func publish(client *pubsub.Client, argv []string) {
	checkArgs(argv, 3)
	topic := argv[1]
	message := argv[2]
	msgIDs, err := client.Topic(topic).Publish(context.Background(), &pubsub.Message{
		Data: []byte(message),
	})
	if err != nil {
		log.Fatalf("Publish failed, %v", err)
	}
	fmt.Printf("Message '%s' published to topic %s and the message id is %s\n", message, topic, msgIDs[0])
}
開發者ID:trythings,項目名稱:trythings,代碼行數:12,代碼來源:main.go

示例10: publishMessageBatches

// publish publishes a series of messages to the named topic.
func publishMessageBatches(client *pubsub.Client, topicName string, workerID int, rep *reporter) {
	var r uint64
	topic := client.Topic(topicName)
	for !shouldQuit() {
		msgPrefix := fmt.Sprintf("Worker: %d, Round: %d,", workerID, r)
		if _, err := topic.Publish(context.Background(), genMessages(msgPrefix)...); err != nil {
			log.Printf("Publish failed, %v\n", err)
			return
		}
		r++
		rep.Inc(*size)
	}
}
開發者ID:trythings,項目名稱:trythings,代碼行數:14,代碼來源:main.go

示例11: listSubscriptions

func listSubscriptions(client *pubsub.Client, argv []string) {
	ctx := context.Background()
	checkArgs(argv, 1)
	subs := client.Subscriptions(ctx)
	for {
		switch sub, err := subs.Next(); err {
		case nil:
			fmt.Println(sub.Name())
		case pubsub.Done:
			return
		default:
			log.Fatalf("Listing subscriptions failed: %v", err)
		}
	}
}
開發者ID:trythings,項目名稱:trythings,代碼行數:15,代碼來源:main.go

示例12: listTopics

func listTopics(client *pubsub.Client, argv []string) {
	ctx := context.Background()
	checkArgs(argv, 1)
	topics := client.Topics(ctx)
	for {
		switch topic, err := topics.Next(); err {
		case nil:
			fmt.Println(topic.Name())
		case pubsub.Done:
			return
		default:
			log.Fatalf("Listing topics failed: %v", err)
		}
	}
}
開發者ID:trythings,項目名稱:trythings,代碼行數:15,代碼來源:main.go

示例13: showSubscription

func showSubscription(client *pubsub.Client, argv []string) {
	checkArgs(argv, 2)
	sub := argv[1]
	conf, err := client.Subscription(sub).Config(context.Background())
	if err != nil {
		log.Fatalf("Getting Subscription failed: %v", err)
	}
	fmt.Printf("%+v\n", conf)
	exists, err := conf.Topic.Exists(context.Background())
	if err != nil {
		log.Fatalf("Checking whether topic exists: %v", err)
	}
	if !exists {
		fmt.Println("The topic for this subscription has been deleted.")
	}
}
開發者ID:trythings,項目名稱:trythings,代碼行數:16,代碼來源:main.go

示例14: publishLoop

func publishLoop(client *pubsub.Client, topic string, workerid int, result chan<- int) {
	var r uint64
	for {
		msgs := make([]*pubsub.Message, *size)
		for i := 0; i < *size; i++ {
			msgs[i] = &pubsub.Message{
				Data: []byte(fmt.Sprintf("Worker: %d, Round: %d, Message: %d", workerid, r, i)),
			}
		}
		_, err := client.Topic(topic).Publish(context.Background(), msgs...)
		if err != nil {
			log.Printf("Publish failed, %v\n", err)
			return
		}
		r++
		if *reportMPS {
			result <- *size
		}
	}
}
開發者ID:Celluliodio,項目名稱:flannel,代碼行數:20,代碼來源:main.go

示例15: pullMessages

// pullMessages reads messages from a subscription, and farms them out to a
// number of goroutines for processing.
func pullMessages(client *pubsub.Client, argv []string) {
	checkArgs(argv, 3)
	sub := client.Subscription(argv[1])

	workers, err := strconv.Atoi(argv[2])
	if err != nil {
		log.Fatalf("Atoi failed, %v", err)
	}

	rep := newReporter("Received")
	defer rep.Stop()

	msgs := make(chan *pubsub.Message)
	for i := 0; i < int(workers); i++ {
		go processMessages(msgs, rep, !*reportMPS)
	}

	it, err := sub.Pull(context.Background(), pubsub.MaxExtension(time.Minute))
	if err != nil {
		log.Fatalf("failed to construct iterator: %v", err)
	}
	defer it.Stop()

	for !shouldQuit() {
		m, err := it.Next()
		if err != nil {
			log.Fatalf("error reading from iterator: %v", err)
		}
		msgs <- m
	}

	// Shut down all processMessages goroutines.
	close(msgs)

	// The deferred call to it.Stop will block until each m.Done has been
	// called on each message.
}
開發者ID:trythings,項目名稱:trythings,代碼行數:39,代碼來源:main.go


注:本文中的google/golang.org/cloud/pubsub.Client類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。