当前位置: 首页>>代码示例>>Golang>>正文


Golang Client.Topic方法代码示例

本文整理汇总了Golang中google/golang.org/cloud/pubsub.Client.Topic方法的典型用法代码示例。如果您正苦于以下问题:Golang Client.Topic方法的具体用法?Golang Client.Topic怎么用?Golang Client.Topic使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在google/golang.org/cloud/pubsub.Client的用法示例。


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

示例1: 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

示例2: 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

示例3: 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

示例4: listTopicSubscriptions

func listTopicSubscriptions(client *pubsub.Client, argv []string) {
	checkArgs(argv, 2)
	topic := argv[1]
	subs, err := client.Topic(topic).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,代码行数:11,代码来源:main.go

示例5: 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

示例6: 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

示例7: listTopicSubscriptions

func listTopicSubscriptions(client *pubsub.Client, argv []string) {
	ctx := context.Background()
	checkArgs(argv, 2)
	topic := argv[1]
	subs := client.Topic(topic).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,代码行数:16,代码来源:main.go

示例8: 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

示例9: init

		ctx := context.Background()
		pubsubClient := initClient()
		gctx := cloud.NewContext(Gceproject, pubsubClient)

		var psClient *pubsub.Client
		if KeyPath != "" {
			psClient = JWTClientInit(&ctx)
		} else {
			psClient = GCEClientInit(&ctx, Gceproject)
		}
		if psClient == nil {
			log.Errorf("PubSub client is nil")
			os.Exit(1)
		}

		topic := psClient.Topic(Topic)
		bytes := []byte(fmt.Sprintf("helloworld %v", time.Now()))
		ids, err := topic.Publish(gctx, &pubsub.Message{Data: bytes})
		if err != nil {
			log.Errorf("error publishing messages: %v", err)
			os.Exit(1)
		}
		for _, id := range ids {
			log.Infof("%#v", id)
		}
	},
}

func init() {
	RootCmd.AddCommand(pubCmd)
}
开发者ID:Ropes,项目名称:pubbing,代码行数:31,代码来源:pub.go


注:本文中的google/golang.org/cloud/pubsub.Client.Topic方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。