You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

633 lines
26 KiB

  1. // Copyright 2019 Google LLC
  2. //
  3. // Licensed under the Apache License, Version 2.0 (the "License");
  4. // you may not use this file except in compliance with the License.
  5. // You may obtain a copy of the License at
  6. //
  7. // https://www.apache.org/licenses/LICENSE-2.0
  8. //
  9. // Unless required by applicable law or agreed to in writing, software
  10. // distributed under the License is distributed on an "AS IS" BASIS,
  11. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. // See the License for the specific language governing permissions and
  13. // limitations under the License.
  14. // Code generated by gapic-generator. DO NOT EDIT.
  15. package pubsub
  16. import (
  17. "context"
  18. "math"
  19. "time"
  20. "github.com/golang/protobuf/proto"
  21. gax "github.com/googleapis/gax-go/v2"
  22. "google.golang.org/api/iterator"
  23. "google.golang.org/api/option"
  24. "google.golang.org/api/transport"
  25. pubsubpb "google.golang.org/genproto/googleapis/pubsub/v1"
  26. "google.golang.org/grpc"
  27. "google.golang.org/grpc/codes"
  28. "google.golang.org/grpc/metadata"
  29. )
  30. // SubscriberCallOptions contains the retry settings for each method of SubscriberClient.
  31. type SubscriberCallOptions struct {
  32. CreateSubscription []gax.CallOption
  33. GetSubscription []gax.CallOption
  34. UpdateSubscription []gax.CallOption
  35. ListSubscriptions []gax.CallOption
  36. DeleteSubscription []gax.CallOption
  37. ModifyAckDeadline []gax.CallOption
  38. Acknowledge []gax.CallOption
  39. Pull []gax.CallOption
  40. StreamingPull []gax.CallOption
  41. ModifyPushConfig []gax.CallOption
  42. ListSnapshots []gax.CallOption
  43. CreateSnapshot []gax.CallOption
  44. UpdateSnapshot []gax.CallOption
  45. DeleteSnapshot []gax.CallOption
  46. Seek []gax.CallOption
  47. }
  48. func defaultSubscriberClientOptions() []option.ClientOption {
  49. return []option.ClientOption{
  50. option.WithEndpoint("pubsub.googleapis.com:443"),
  51. option.WithScopes(DefaultAuthScopes()...),
  52. }
  53. }
  54. func defaultSubscriberCallOptions() *SubscriberCallOptions {
  55. retry := map[[2]string][]gax.CallOption{
  56. {"default", "idempotent"}: {
  57. gax.WithRetry(func() gax.Retryer {
  58. return gax.OnCodes([]codes.Code{
  59. codes.Aborted,
  60. codes.Unavailable,
  61. codes.Unknown,
  62. }, gax.Backoff{
  63. Initial: 100 * time.Millisecond,
  64. Max: 60000 * time.Millisecond,
  65. Multiplier: 1.3,
  66. })
  67. }),
  68. },
  69. {"default", "non_idempotent"}: {
  70. gax.WithRetry(func() gax.Retryer {
  71. return gax.OnCodes([]codes.Code{
  72. codes.Unavailable,
  73. }, gax.Backoff{
  74. Initial: 100 * time.Millisecond,
  75. Max: 60000 * time.Millisecond,
  76. Multiplier: 1.3,
  77. })
  78. }),
  79. },
  80. {"messaging", "idempotent"}: {
  81. gax.WithRetry(func() gax.Retryer {
  82. return gax.OnCodes([]codes.Code{
  83. codes.Aborted,
  84. codes.Unavailable,
  85. codes.Unknown,
  86. }, gax.Backoff{
  87. Initial: 100 * time.Millisecond,
  88. Max: 60000 * time.Millisecond,
  89. Multiplier: 1.3,
  90. })
  91. }),
  92. },
  93. {"messaging", "non_idempotent"}: {
  94. gax.WithRetry(func() gax.Retryer {
  95. return gax.OnCodes([]codes.Code{
  96. codes.Unavailable,
  97. }, gax.Backoff{
  98. Initial: 100 * time.Millisecond,
  99. Max: 60000 * time.Millisecond,
  100. Multiplier: 1.3,
  101. })
  102. }),
  103. },
  104. }
  105. return &SubscriberCallOptions{
  106. CreateSubscription: retry[[2]string{"default", "idempotent"}],
  107. GetSubscription: retry[[2]string{"default", "idempotent"}],
  108. UpdateSubscription: retry[[2]string{"default", "non_idempotent"}],
  109. ListSubscriptions: retry[[2]string{"default", "idempotent"}],
  110. DeleteSubscription: retry[[2]string{"default", "non_idempotent"}],
  111. ModifyAckDeadline: retry[[2]string{"default", "non_idempotent"}],
  112. Acknowledge: retry[[2]string{"messaging", "non_idempotent"}],
  113. Pull: retry[[2]string{"messaging", "idempotent"}],
  114. StreamingPull: retry[[2]string{"streaming_messaging", "none"}],
  115. ModifyPushConfig: retry[[2]string{"default", "non_idempotent"}],
  116. ListSnapshots: retry[[2]string{"default", "idempotent"}],
  117. CreateSnapshot: retry[[2]string{"default", "non_idempotent"}],
  118. UpdateSnapshot: retry[[2]string{"default", "non_idempotent"}],
  119. DeleteSnapshot: retry[[2]string{"default", "non_idempotent"}],
  120. Seek: retry[[2]string{"default", "idempotent"}],
  121. }
  122. }
  123. // SubscriberClient is a client for interacting with Google Cloud Pub/Sub API.
  124. //
  125. // Methods, except Close, may be called concurrently. However, fields must not be modified concurrently with method calls.
  126. type SubscriberClient struct {
  127. // The connection to the service.
  128. conn *grpc.ClientConn
  129. // The gRPC API client.
  130. subscriberClient pubsubpb.SubscriberClient
  131. // The call options for this service.
  132. CallOptions *SubscriberCallOptions
  133. // The x-goog-* metadata to be sent with each request.
  134. xGoogMetadata metadata.MD
  135. }
  136. // NewSubscriberClient creates a new subscriber client.
  137. //
  138. // The service that an application uses to manipulate subscriptions and to
  139. // consume messages from a subscription via the Pull method or by
  140. // establishing a bi-directional stream using the StreamingPull method.
  141. func NewSubscriberClient(ctx context.Context, opts ...option.ClientOption) (*SubscriberClient, error) {
  142. conn, err := transport.DialGRPC(ctx, append(defaultSubscriberClientOptions(), opts...)...)
  143. if err != nil {
  144. return nil, err
  145. }
  146. c := &SubscriberClient{
  147. conn: conn,
  148. CallOptions: defaultSubscriberCallOptions(),
  149. subscriberClient: pubsubpb.NewSubscriberClient(conn),
  150. }
  151. c.SetGoogleClientInfo()
  152. return c, nil
  153. }
  154. // Connection returns the client's connection to the API service.
  155. func (c *SubscriberClient) Connection() *grpc.ClientConn {
  156. return c.conn
  157. }
  158. // Close closes the connection to the API service. The user should invoke this when
  159. // the client is no longer required.
  160. func (c *SubscriberClient) Close() error {
  161. return c.conn.Close()
  162. }
  163. // SetGoogleClientInfo sets the name and version of the application in
  164. // the `x-goog-api-client` header passed on each request. Intended for
  165. // use by Google-written clients.
  166. func (c *SubscriberClient) SetGoogleClientInfo(keyval ...string) {
  167. kv := append([]string{"gl-go", versionGo()}, keyval...)
  168. kv = append(kv, "gapic", versionClient, "gax", gax.Version, "grpc", grpc.Version)
  169. c.xGoogMetadata = metadata.Pairs("x-goog-api-client", gax.XGoogHeader(kv...))
  170. }
  171. // CreateSubscription creates a subscription to a given topic. See the
  172. // <a href="https://cloud.google.com/pubsub/docs/admin#resource_names">
  173. // resource name rules</a>.
  174. // If the subscription already exists, returns ALREADY_EXISTS.
  175. // If the corresponding topic doesn't exist, returns NOT_FOUND.
  176. //
  177. // If the name is not provided in the request, the server will assign a random
  178. // name for this subscription on the same project as the topic, conforming
  179. // to the
  180. // resource name
  181. // format (at https://cloud.google.com/pubsub/docs/admin#resource_names). The
  182. // generated name is populated in the returned Subscription object. Note that
  183. // for REST API requests, you must specify a name in the request.
  184. func (c *SubscriberClient) CreateSubscription(ctx context.Context, req *pubsubpb.Subscription, opts ...gax.CallOption) (*pubsubpb.Subscription, error) {
  185. ctx = insertMetadata(ctx, c.xGoogMetadata)
  186. opts = append(c.CallOptions.CreateSubscription[0:len(c.CallOptions.CreateSubscription):len(c.CallOptions.CreateSubscription)], opts...)
  187. var resp *pubsubpb.Subscription
  188. err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
  189. var err error
  190. resp, err = c.subscriberClient.CreateSubscription(ctx, req, settings.GRPC...)
  191. return err
  192. }, opts...)
  193. if err != nil {
  194. return nil, err
  195. }
  196. return resp, nil
  197. }
  198. // GetSubscription gets the configuration details of a subscription.
  199. func (c *SubscriberClient) GetSubscription(ctx context.Context, req *pubsubpb.GetSubscriptionRequest, opts ...gax.CallOption) (*pubsubpb.Subscription, error) {
  200. ctx = insertMetadata(ctx, c.xGoogMetadata)
  201. opts = append(c.CallOptions.GetSubscription[0:len(c.CallOptions.GetSubscription):len(c.CallOptions.GetSubscription)], opts...)
  202. var resp *pubsubpb.Subscription
  203. err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
  204. var err error
  205. resp, err = c.subscriberClient.GetSubscription(ctx, req, settings.GRPC...)
  206. return err
  207. }, opts...)
  208. if err != nil {
  209. return nil, err
  210. }
  211. return resp, nil
  212. }
  213. // UpdateSubscription updates an existing subscription. Note that certain properties of a
  214. // subscription, such as its topic, are not modifiable.
  215. func (c *SubscriberClient) UpdateSubscription(ctx context.Context, req *pubsubpb.UpdateSubscriptionRequest, opts ...gax.CallOption) (*pubsubpb.Subscription, error) {
  216. ctx = insertMetadata(ctx, c.xGoogMetadata)
  217. opts = append(c.CallOptions.UpdateSubscription[0:len(c.CallOptions.UpdateSubscription):len(c.CallOptions.UpdateSubscription)], opts...)
  218. var resp *pubsubpb.Subscription
  219. err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
  220. var err error
  221. resp, err = c.subscriberClient.UpdateSubscription(ctx, req, settings.GRPC...)
  222. return err
  223. }, opts...)
  224. if err != nil {
  225. return nil, err
  226. }
  227. return resp, nil
  228. }
  229. // ListSubscriptions lists matching subscriptions.
  230. func (c *SubscriberClient) ListSubscriptions(ctx context.Context, req *pubsubpb.ListSubscriptionsRequest, opts ...gax.CallOption) *SubscriptionIterator {
  231. ctx = insertMetadata(ctx, c.xGoogMetadata)
  232. opts = append(c.CallOptions.ListSubscriptions[0:len(c.CallOptions.ListSubscriptions):len(c.CallOptions.ListSubscriptions)], opts...)
  233. it := &SubscriptionIterator{}
  234. req = proto.Clone(req).(*pubsubpb.ListSubscriptionsRequest)
  235. it.InternalFetch = func(pageSize int, pageToken string) ([]*pubsubpb.Subscription, string, error) {
  236. var resp *pubsubpb.ListSubscriptionsResponse
  237. req.PageToken = pageToken
  238. if pageSize > math.MaxInt32 {
  239. req.PageSize = math.MaxInt32
  240. } else {
  241. req.PageSize = int32(pageSize)
  242. }
  243. err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
  244. var err error
  245. resp, err = c.subscriberClient.ListSubscriptions(ctx, req, settings.GRPC...)
  246. return err
  247. }, opts...)
  248. if err != nil {
  249. return nil, "", err
  250. }
  251. return resp.Subscriptions, resp.NextPageToken, nil
  252. }
  253. fetch := func(pageSize int, pageToken string) (string, error) {
  254. items, nextPageToken, err := it.InternalFetch(pageSize, pageToken)
  255. if err != nil {
  256. return "", err
  257. }
  258. it.items = append(it.items, items...)
  259. return nextPageToken, nil
  260. }
  261. it.pageInfo, it.nextFunc = iterator.NewPageInfo(fetch, it.bufLen, it.takeBuf)
  262. it.pageInfo.MaxSize = int(req.PageSize)
  263. return it
  264. }
  265. // DeleteSubscription deletes an existing subscription. All messages retained in the subscription
  266. // are immediately dropped. Calls to Pull after deletion will return
  267. // NOT_FOUND. After a subscription is deleted, a new one may be created with
  268. // the same name, but the new one has no association with the old
  269. // subscription or its topic unless the same topic is specified.
  270. func (c *SubscriberClient) DeleteSubscription(ctx context.Context, req *pubsubpb.DeleteSubscriptionRequest, opts ...gax.CallOption) error {
  271. ctx = insertMetadata(ctx, c.xGoogMetadata)
  272. opts = append(c.CallOptions.DeleteSubscription[0:len(c.CallOptions.DeleteSubscription):len(c.CallOptions.DeleteSubscription)], opts...)
  273. err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
  274. var err error
  275. _, err = c.subscriberClient.DeleteSubscription(ctx, req, settings.GRPC...)
  276. return err
  277. }, opts...)
  278. return err
  279. }
  280. // ModifyAckDeadline modifies the ack deadline for a specific message. This method is useful
  281. // to indicate that more time is needed to process a message by the
  282. // subscriber, or to make the message available for redelivery if the
  283. // processing was interrupted. Note that this does not modify the
  284. // subscription-level ackDeadlineSeconds used for subsequent messages.
  285. func (c *SubscriberClient) ModifyAckDeadline(ctx context.Context, req *pubsubpb.ModifyAckDeadlineRequest, opts ...gax.CallOption) error {
  286. ctx = insertMetadata(ctx, c.xGoogMetadata)
  287. opts = append(c.CallOptions.ModifyAckDeadline[0:len(c.CallOptions.ModifyAckDeadline):len(c.CallOptions.ModifyAckDeadline)], opts...)
  288. err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
  289. var err error
  290. _, err = c.subscriberClient.ModifyAckDeadline(ctx, req, settings.GRPC...)
  291. return err
  292. }, opts...)
  293. return err
  294. }
  295. // Acknowledge acknowledges the messages associated with the ack_ids in the
  296. // AcknowledgeRequest. The Pub/Sub system can remove the relevant messages
  297. // from the subscription.
  298. //
  299. // Acknowledging a message whose ack deadline has expired may succeed,
  300. // but such a message may be redelivered later. Acknowledging a message more
  301. // than once will not result in an error.
  302. func (c *SubscriberClient) Acknowledge(ctx context.Context, req *pubsubpb.AcknowledgeRequest, opts ...gax.CallOption) error {
  303. ctx = insertMetadata(ctx, c.xGoogMetadata)
  304. opts = append(c.CallOptions.Acknowledge[0:len(c.CallOptions.Acknowledge):len(c.CallOptions.Acknowledge)], opts...)
  305. err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
  306. var err error
  307. _, err = c.subscriberClient.Acknowledge(ctx, req, settings.GRPC...)
  308. return err
  309. }, opts...)
  310. return err
  311. }
  312. // Pull pulls messages from the server. The server may return UNAVAILABLE if
  313. // there are too many concurrent pull requests pending for the given
  314. // subscription.
  315. func (c *SubscriberClient) Pull(ctx context.Context, req *pubsubpb.PullRequest, opts ...gax.CallOption) (*pubsubpb.PullResponse, error) {
  316. ctx = insertMetadata(ctx, c.xGoogMetadata)
  317. opts = append(c.CallOptions.Pull[0:len(c.CallOptions.Pull):len(c.CallOptions.Pull)], opts...)
  318. var resp *pubsubpb.PullResponse
  319. err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
  320. var err error
  321. resp, err = c.subscriberClient.Pull(ctx, req, settings.GRPC...)
  322. return err
  323. }, opts...)
  324. if err != nil {
  325. return nil, err
  326. }
  327. return resp, nil
  328. }
  329. // StreamingPull establishes a stream with the server, which sends messages down to the
  330. // client. The client streams acknowledgements and ack deadline modifications
  331. // back to the server. The server will close the stream and return the status
  332. // on any error. The server may close the stream with status UNAVAILABLE to
  333. // reassign server-side resources, in which case, the client should
  334. // re-establish the stream. Flow control can be achieved by configuring the
  335. // underlying RPC channel.
  336. func (c *SubscriberClient) StreamingPull(ctx context.Context, opts ...gax.CallOption) (pubsubpb.Subscriber_StreamingPullClient, error) {
  337. ctx = insertMetadata(ctx, c.xGoogMetadata)
  338. opts = append(c.CallOptions.StreamingPull[0:len(c.CallOptions.StreamingPull):len(c.CallOptions.StreamingPull)], opts...)
  339. var resp pubsubpb.Subscriber_StreamingPullClient
  340. err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
  341. var err error
  342. resp, err = c.subscriberClient.StreamingPull(ctx, settings.GRPC...)
  343. return err
  344. }, opts...)
  345. if err != nil {
  346. return nil, err
  347. }
  348. return resp, nil
  349. }
  350. // ModifyPushConfig modifies the PushConfig for a specified subscription.
  351. //
  352. // This may be used to change a push subscription to a pull one (signified by
  353. // an empty PushConfig) or vice versa, or change the endpoint URL and other
  354. // attributes of a push subscription. Messages will accumulate for delivery
  355. // continuously through the call regardless of changes to the PushConfig.
  356. func (c *SubscriberClient) ModifyPushConfig(ctx context.Context, req *pubsubpb.ModifyPushConfigRequest, opts ...gax.CallOption) error {
  357. ctx = insertMetadata(ctx, c.xGoogMetadata)
  358. opts = append(c.CallOptions.ModifyPushConfig[0:len(c.CallOptions.ModifyPushConfig):len(c.CallOptions.ModifyPushConfig)], opts...)
  359. err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
  360. var err error
  361. _, err = c.subscriberClient.ModifyPushConfig(ctx, req, settings.GRPC...)
  362. return err
  363. }, opts...)
  364. return err
  365. }
  366. // ListSnapshots lists the existing snapshots. Snapshots are used in
  367. // <a href="https://cloud.google.com/pubsub/docs/replay-overview">Seek</a>
  368. // operations, which allow
  369. // you to manage message acknowledgments in bulk. That is, you can set the
  370. // acknowledgment state of messages in an existing subscription to the state
  371. // captured by a snapshot.<br><br>
  372. // <b>BETA:</b> This feature is part of a beta release. This API might be
  373. // changed in backward-incompatible ways and is not recommended for production
  374. // use. It is not subject to any SLA or deprecation policy.
  375. func (c *SubscriberClient) ListSnapshots(ctx context.Context, req *pubsubpb.ListSnapshotsRequest, opts ...gax.CallOption) *SnapshotIterator {
  376. ctx = insertMetadata(ctx, c.xGoogMetadata)
  377. opts = append(c.CallOptions.ListSnapshots[0:len(c.CallOptions.ListSnapshots):len(c.CallOptions.ListSnapshots)], opts...)
  378. it := &SnapshotIterator{}
  379. req = proto.Clone(req).(*pubsubpb.ListSnapshotsRequest)
  380. it.InternalFetch = func(pageSize int, pageToken string) ([]*pubsubpb.Snapshot, string, error) {
  381. var resp *pubsubpb.ListSnapshotsResponse
  382. req.PageToken = pageToken
  383. if pageSize > math.MaxInt32 {
  384. req.PageSize = math.MaxInt32
  385. } else {
  386. req.PageSize = int32(pageSize)
  387. }
  388. err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
  389. var err error
  390. resp, err = c.subscriberClient.ListSnapshots(ctx, req, settings.GRPC...)
  391. return err
  392. }, opts...)
  393. if err != nil {
  394. return nil, "", err
  395. }
  396. return resp.Snapshots, resp.NextPageToken, nil
  397. }
  398. fetch := func(pageSize int, pageToken string) (string, error) {
  399. items, nextPageToken, err := it.InternalFetch(pageSize, pageToken)
  400. if err != nil {
  401. return "", err
  402. }
  403. it.items = append(it.items, items...)
  404. return nextPageToken, nil
  405. }
  406. it.pageInfo, it.nextFunc = iterator.NewPageInfo(fetch, it.bufLen, it.takeBuf)
  407. it.pageInfo.MaxSize = int(req.PageSize)
  408. return it
  409. }
  410. // CreateSnapshot creates a snapshot from the requested subscription. Snapshots are used in
  411. // <a href="https://cloud.google.com/pubsub/docs/replay-overview">Seek</a>
  412. // operations, which allow
  413. // you to manage message acknowledgments in bulk. That is, you can set the
  414. // acknowledgment state of messages in an existing subscription to the state
  415. // captured by a snapshot.
  416. // <br><br>
  417. // <b>BETA:</b> This feature is part of a beta release. This API might be
  418. // changed in backward-incompatible ways and is not recommended for production
  419. // use. It is not subject to any SLA or deprecation policy.<br><br>
  420. // If the snapshot already exists, returns ALREADY_EXISTS.
  421. // If the requested subscription doesn't exist, returns NOT_FOUND.
  422. // If the backlog in the subscription is too old -- and the resulting snapshot
  423. // would expire in less than 1 hour -- then FAILED_PRECONDITION is returned.
  424. // See also the Snapshot.expire_time field. If the name is not provided in
  425. // the request, the server will assign a random
  426. // name for this snapshot on the same project as the subscription, conforming
  427. // to the
  428. // resource name
  429. // format (at https://cloud.google.com/pubsub/docs/admin#resource_names). The
  430. // generated name is populated in the returned Snapshot object. Note that for
  431. // REST API requests, you must specify a name in the request.
  432. func (c *SubscriberClient) CreateSnapshot(ctx context.Context, req *pubsubpb.CreateSnapshotRequest, opts ...gax.CallOption) (*pubsubpb.Snapshot, error) {
  433. ctx = insertMetadata(ctx, c.xGoogMetadata)
  434. opts = append(c.CallOptions.CreateSnapshot[0:len(c.CallOptions.CreateSnapshot):len(c.CallOptions.CreateSnapshot)], opts...)
  435. var resp *pubsubpb.Snapshot
  436. err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
  437. var err error
  438. resp, err = c.subscriberClient.CreateSnapshot(ctx, req, settings.GRPC...)
  439. return err
  440. }, opts...)
  441. if err != nil {
  442. return nil, err
  443. }
  444. return resp, nil
  445. }
  446. // UpdateSnapshot updates an existing snapshot. Snapshots are used in
  447. // <a href="https://cloud.google.com/pubsub/docs/replay-overview">Seek</a>
  448. // operations, which allow
  449. // you to manage message acknowledgments in bulk. That is, you can set the
  450. // acknowledgment state of messages in an existing subscription to the state
  451. // captured by a snapshot.<br><br>
  452. // <b>BETA:</b> This feature is part of a beta release. This API might be
  453. // changed in backward-incompatible ways and is not recommended for production
  454. // use. It is not subject to any SLA or deprecation policy.
  455. // Note that certain properties of a snapshot are not modifiable.
  456. func (c *SubscriberClient) UpdateSnapshot(ctx context.Context, req *pubsubpb.UpdateSnapshotRequest, opts ...gax.CallOption) (*pubsubpb.Snapshot, error) {
  457. ctx = insertMetadata(ctx, c.xGoogMetadata)
  458. opts = append(c.CallOptions.UpdateSnapshot[0:len(c.CallOptions.UpdateSnapshot):len(c.CallOptions.UpdateSnapshot)], opts...)
  459. var resp *pubsubpb.Snapshot
  460. err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
  461. var err error
  462. resp, err = c.subscriberClient.UpdateSnapshot(ctx, req, settings.GRPC...)
  463. return err
  464. }, opts...)
  465. if err != nil {
  466. return nil, err
  467. }
  468. return resp, nil
  469. }
  470. // DeleteSnapshot removes an existing snapshot. Snapshots are used in
  471. // <a href="https://cloud.google.com/pubsub/docs/replay-overview">Seek</a>
  472. // operations, which allow
  473. // you to manage message acknowledgments in bulk. That is, you can set the
  474. // acknowledgment state of messages in an existing subscription to the state
  475. // captured by a snapshot.<br><br>
  476. // <b>BETA:</b> This feature is part of a beta release. This API might be
  477. // changed in backward-incompatible ways and is not recommended for production
  478. // use. It is not subject to any SLA or deprecation policy.
  479. // When the snapshot is deleted, all messages retained in the snapshot
  480. // are immediately dropped. After a snapshot is deleted, a new one may be
  481. // created with the same name, but the new one has no association with the old
  482. // snapshot or its subscription, unless the same subscription is specified.
  483. func (c *SubscriberClient) DeleteSnapshot(ctx context.Context, req *pubsubpb.DeleteSnapshotRequest, opts ...gax.CallOption) error {
  484. ctx = insertMetadata(ctx, c.xGoogMetadata)
  485. opts = append(c.CallOptions.DeleteSnapshot[0:len(c.CallOptions.DeleteSnapshot):len(c.CallOptions.DeleteSnapshot)], opts...)
  486. err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
  487. var err error
  488. _, err = c.subscriberClient.DeleteSnapshot(ctx, req, settings.GRPC...)
  489. return err
  490. }, opts...)
  491. return err
  492. }
  493. // Seek seeks an existing subscription to a point in time or to a given snapshot,
  494. // whichever is provided in the request. Snapshots are used in
  495. // <a href="https://cloud.google.com/pubsub/docs/replay-overview">Seek</a>
  496. // operations, which allow
  497. // you to manage message acknowledgments in bulk. That is, you can set the
  498. // acknowledgment state of messages in an existing subscription to the state
  499. // captured by a snapshot. Note that both the subscription and the snapshot
  500. // must be on the same topic.<br><br>
  501. // <b>BETA:</b> This feature is part of a beta release. This API might be
  502. // changed in backward-incompatible ways and is not recommended for production
  503. // use. It is not subject to any SLA or deprecation policy.
  504. func (c *SubscriberClient) Seek(ctx context.Context, req *pubsubpb.SeekRequest, opts ...gax.CallOption) (*pubsubpb.SeekResponse, error) {
  505. ctx = insertMetadata(ctx, c.xGoogMetadata)
  506. opts = append(c.CallOptions.Seek[0:len(c.CallOptions.Seek):len(c.CallOptions.Seek)], opts...)
  507. var resp *pubsubpb.SeekResponse
  508. err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
  509. var err error
  510. resp, err = c.subscriberClient.Seek(ctx, req, settings.GRPC...)
  511. return err
  512. }, opts...)
  513. if err != nil {
  514. return nil, err
  515. }
  516. return resp, nil
  517. }
  518. // SnapshotIterator manages a stream of *pubsubpb.Snapshot.
  519. type SnapshotIterator struct {
  520. items []*pubsubpb.Snapshot
  521. pageInfo *iterator.PageInfo
  522. nextFunc func() error
  523. // InternalFetch is for use by the Google Cloud Libraries only.
  524. // It is not part of the stable interface of this package.
  525. //
  526. // InternalFetch returns results from a single call to the underlying RPC.
  527. // The number of results is no greater than pageSize.
  528. // If there are no more results, nextPageToken is empty and err is nil.
  529. InternalFetch func(pageSize int, pageToken string) (results []*pubsubpb.Snapshot, nextPageToken string, err error)
  530. }
  531. // PageInfo supports pagination. See the google.golang.org/api/iterator package for details.
  532. func (it *SnapshotIterator) PageInfo() *iterator.PageInfo {
  533. return it.pageInfo
  534. }
  535. // Next returns the next result. Its second return value is iterator.Done if there are no more
  536. // results. Once Next returns Done, all subsequent calls will return Done.
  537. func (it *SnapshotIterator) Next() (*pubsubpb.Snapshot, error) {
  538. var item *pubsubpb.Snapshot
  539. if err := it.nextFunc(); err != nil {
  540. return item, err
  541. }
  542. item = it.items[0]
  543. it.items = it.items[1:]
  544. return item, nil
  545. }
  546. func (it *SnapshotIterator) bufLen() int {
  547. return len(it.items)
  548. }
  549. func (it *SnapshotIterator) takeBuf() interface{} {
  550. b := it.items
  551. it.items = nil
  552. return b
  553. }
  554. // SubscriptionIterator manages a stream of *pubsubpb.Subscription.
  555. type SubscriptionIterator struct {
  556. items []*pubsubpb.Subscription
  557. pageInfo *iterator.PageInfo
  558. nextFunc func() error
  559. // InternalFetch is for use by the Google Cloud Libraries only.
  560. // It is not part of the stable interface of this package.
  561. //
  562. // InternalFetch returns results from a single call to the underlying RPC.
  563. // The number of results is no greater than pageSize.
  564. // If there are no more results, nextPageToken is empty and err is nil.
  565. InternalFetch func(pageSize int, pageToken string) (results []*pubsubpb.Subscription, nextPageToken string, err error)
  566. }
  567. // PageInfo supports pagination. See the google.golang.org/api/iterator package for details.
  568. func (it *SubscriptionIterator) PageInfo() *iterator.PageInfo {
  569. return it.pageInfo
  570. }
  571. // Next returns the next result. Its second return value is iterator.Done if there are no more
  572. // results. Once Next returns Done, all subsequent calls will return Done.
  573. func (it *SubscriptionIterator) Next() (*pubsubpb.Subscription, error) {
  574. var item *pubsubpb.Subscription
  575. if err := it.nextFunc(); err != nil {
  576. return item, err
  577. }
  578. item = it.items[0]
  579. it.items = it.items[1:]
  580. return item, nil
  581. }
  582. func (it *SubscriptionIterator) bufLen() int {
  583. return len(it.items)
  584. }
  585. func (it *SubscriptionIterator) takeBuf() interface{} {
  586. b := it.items
  587. it.items = nil
  588. return b
  589. }