Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(12)

Side by Side Diff: common/gcloud/pubsub/subscriber/source.go

Issue 1838303002: Use native Pub/Sub library primitives. (Closed) Base URL: https://github.com/luci/luci-go@logdog-go1.6
Patch Set: Use "Topic" instead of "NewTopic" ... don't want to create :) Created 4 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « common/gcloud/pubsub/scopes.go ('k') | common/gcloud/pubsub/subscriber/subscriber.go » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 package subscriber
6
7 import (
8 "github.com/luci/luci-go/common/gcloud/pubsub"
9 "golang.org/x/net/context"
10 )
11
12 // Source is used to pull Pub/Sub messages in batches.
13 type Source interface {
14 // Pull retrieves up to the specified number of of Pub/Sub messages to
15 // process.
16 Pull(context.Context, int) ([]*pubsub.Message, error)
17 }
18
19 // PubSubSource is a Source implementation built on top of a pubsub.PubSub.
20 type pubSubSource struct {
21 ps pubsub.Connection
22 sub pubsub.Subscription
23 }
24
25 // NewSource generates a new Source by wrapping a pubsub.Connection
26 // implementation. This Source is bound to a single subscription.
27 func NewSource(ps pubsub.Connection, s pubsub.Subscription) Source {
28 return &pubSubSource{
29 ps: ps,
30 sub: s,
31 }
32 }
33
34 func (s *pubSubSource) Pull(c context.Context, batchSize int) (msgs []*pubsub.Me ssage, err error) {
35 return s.ps.Pull(c, s.sub, batchSize)
36 }
OLDNEW
« no previous file with comments | « common/gcloud/pubsub/scopes.go ('k') | common/gcloud/pubsub/subscriber/subscriber.go » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698