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


Golang Client.Subscription方法代碼示例

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


在下文中一共展示了Client.Subscription方法的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的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: 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

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

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

示例5:

        // Configure connection to pubsub
        ctx := context.Background()
        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)
        }
        log.Debugf("client: %#v", psClient)

        // Create message iterator from client
        sub := psClient.Subscription(subscription)
        it, err := sub.Pull(ctx, pubsub.MaxExtension(time.Minute*1))
        if err != nil {
            log.Errorf("error creating pubsub iterator: %v", err)
        }
        defer it.Stop()

        msgs := make(chan *pubsub.Message)
        go func() {
            for !shouldQuit(quit) {
                m, err := it.Next()
                if err != nil {
                    switch err {
                    case pubsub.Done:
                        log.Infof("pubsub interator finished")
                    default:
開發者ID:Ropes,項目名稱:pubbing,代碼行數:31,代碼來源:sub.go


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