1

我在尝试订阅 Podio Push 服务时遇到了一些意外错误。我使用这里定义的 golang 并发模式,这里是用于订阅的bayeux 客户端库。

基本上,流程首先尝试检索项目,然后订阅与项目对象一起提供的推送对象。有一个通道对象,我存储每个任务(taskLoad:~每个 item_id 及其检索所需的凭据)

item := new(podio.Item)
item, err = podio.GetItem(itemId)
if err != nil {
    log.Errorf("PODIO", "Could not get item %d -> %s", itemId, err)

    return
}

并且,稍后在另一个函数中

messages := make(chan *bayeux.Message)
server := GetBayeux()
defer server.Close()

if err = push.Subscribe(server, messages); err != nil {
    // log err, with item details
    log.Errorf("PODIO", "%s", err, push)

    // re-enqueue the task in taskLoad channel
    go enqueueTask(true, messages, sigrepeat, timer)

    // release sigwait channel on subscription error
    <-sigwait

    return
}

这里GetBayeuxfunc 只是一个包装客户端的单例

func GetBayeux() *bayeux.Client {
    bayeuxOnce.Do(func() {
        Bayeux = bayeux.NewClient("https://push.podio.com/faye", nil)
    })

    return Bayeux
}

大约有大约 15000 个项目要听,我应该订阅每个项目,但不幸的是,有时我在处理订阅时遇到这些错误之一

401:k9jx3v4qq276k9q84gokpqirhjrfbyd:Unknown client [{"channel":"/item/9164xxxxx","signature":"46bd8ab3ef2a31297d8f4f5ddxxxx","timestamp":"2018-01-02T14:34:02Z","expires_in":21600}]

或者

HTTP Status 400 [{"channel":"/item/9158xxxxx","signature":"31bf8b4697ca2fda69bd7fd532d08xxxxxx","timestamp":"2018-01-02T14:37:02Z","expires_in":21600}]

或者

[WRN] Bayeux connect failed: HTTP Status 400

或者

Bayeux connect failed: Post https://push.podio.com/faye: http2: server sent GOAWAY and closed the connection; LastStreamID=1999, ErrCode=NO_ERROR, debug=""

所以现在,我想知道为什么会出现这些错误,最重要的是如何修复它们以确保收听范围内的所有项目。

如果有人知道,并发访问podio推送服务是否有任何限制?

谢谢

更新 2019-01-07

是单身人士搞砸了这个过程。因为它在 goroutine 上下文中,所以有些订阅是不允许的,因为服务器已被另一个 goroutine 关闭。修复是公开Unsubscribe方法并使用它而不是关闭客户端与服务器断开连接的方法。

defer server.Close()

变成了

defer push.Unsubscribe(server)

4

0 回答 0