| OLD | NEW |
| (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 } | |
| OLD | NEW |