google-cloud-pubsub 1.1.3 → 1.10.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (33) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +122 -0
  3. data/EMULATOR.md +1 -1
  4. data/TROUBLESHOOTING.md +2 -8
  5. data/lib/google/cloud/pubsub/async_publisher.rb +15 -19
  6. data/lib/google/cloud/pubsub/project.rb +18 -26
  7. data/lib/google/cloud/pubsub/received_message.rb +38 -0
  8. data/lib/google/cloud/pubsub/retry_policy.rb +90 -0
  9. data/lib/google/cloud/pubsub/service.rb +37 -15
  10. data/lib/google/cloud/pubsub/subscriber/inventory.rb +43 -15
  11. data/lib/google/cloud/pubsub/subscriber/stream.rb +7 -8
  12. data/lib/google/cloud/pubsub/subscriber.rb +86 -15
  13. data/lib/google/cloud/pubsub/subscription/push_config.rb +2 -2
  14. data/lib/google/cloud/pubsub/subscription.rb +296 -6
  15. data/lib/google/cloud/pubsub/topic.rb +65 -2
  16. data/lib/google/cloud/pubsub/v1/credentials.rb +1 -1
  17. data/lib/google/cloud/pubsub/v1/doc/google/iam/v1/iam_policy.rb +1 -1
  18. data/lib/google/cloud/pubsub/v1/doc/google/iam/v1/options.rb +1 -1
  19. data/lib/google/cloud/pubsub/v1/doc/google/iam/v1/policy.rb +1 -1
  20. data/lib/google/cloud/pubsub/v1/doc/google/protobuf/duration.rb +1 -1
  21. data/lib/google/cloud/pubsub/v1/doc/google/protobuf/empty.rb +1 -1
  22. data/lib/google/cloud/pubsub/v1/doc/google/protobuf/field_mask.rb +1 -1
  23. data/lib/google/cloud/pubsub/v1/doc/google/protobuf/timestamp.rb +1 -1
  24. data/lib/google/cloud/pubsub/v1/doc/google/pubsub/v1/pubsub.rb +168 -79
  25. data/lib/google/cloud/pubsub/v1/doc/google/type/expr.rb +1 -1
  26. data/lib/google/cloud/pubsub/v1/publisher_client.rb +175 -33
  27. data/lib/google/cloud/pubsub/v1/publisher_client_config.json +16 -1
  28. data/lib/google/cloud/pubsub/v1/subscriber_client.rb +145 -64
  29. data/lib/google/cloud/pubsub/v1/subscriber_client_config.json +12 -3
  30. data/lib/google/cloud/pubsub/version.rb +1 -1
  31. data/lib/google/pubsub/v1/pubsub_pb.rb +20 -0
  32. data/lib/google/pubsub/v1/pubsub_services_pb.rb +7 -3
  33. metadata +6 -5
@@ -1,4 +1,4 @@
1
- # Copyright 2019 Google LLC
1
+ # Copyright 2020 Google LLC
2
2
  #
3
3
  # Licensed under the Apache License, Version 2.0 (the "License");
4
4
  # you may not use this file except in compliance with the License.
@@ -64,7 +64,11 @@ module Google
64
64
  "list_topic_subscriptions" => Google::Gax::PageDescriptor.new(
65
65
  "page_token",
66
66
  "next_page_token",
67
- "subscriptions")
67
+ "subscriptions"),
68
+ "list_topic_snapshots" => Google::Gax::PageDescriptor.new(
69
+ "page_token",
70
+ "next_page_token",
71
+ "snapshots")
68
72
  }.freeze
69
73
 
70
74
  private_constant :PAGE_DESCRIPTORS
@@ -94,6 +98,12 @@ module Google
94
98
 
95
99
  private_constant :PROJECT_PATH_TEMPLATE
96
100
 
101
+ SUBSCRIPTION_PATH_TEMPLATE = Google::Gax::PathTemplate.new(
102
+ "projects/{project}/subscriptions/{subscription}"
103
+ )
104
+
105
+ private_constant :SUBSCRIPTION_PATH_TEMPLATE
106
+
97
107
  TOPIC_PATH_TEMPLATE = Google::Gax::PathTemplate.new(
98
108
  "projects/{project}/topics/{topic}"
99
109
  )
@@ -109,6 +119,17 @@ module Google
109
119
  )
110
120
  end
111
121
 
122
+ # Returns a fully-qualified subscription resource name string.
123
+ # @param project [String]
124
+ # @param subscription [String]
125
+ # @return [String]
126
+ def self.subscription_path project, subscription
127
+ SUBSCRIPTION_PATH_TEMPLATE.render(
128
+ :"project" => project,
129
+ :"subscription" => subscription
130
+ )
131
+ end
132
+
112
133
  # Returns a fully-qualified topic resource name string.
113
134
  # @param project [String]
114
135
  # @param topic [String]
@@ -198,6 +219,9 @@ module Google
198
219
  google_api_client.freeze
199
220
 
200
221
  headers = { :"x-goog-api-client" => google_api_client }
222
+ if credentials.respond_to?(:quota_project_id) && credentials.quota_project_id
223
+ headers[:"x-goog-user-project"] = credentials.quota_project_id
224
+ end
201
225
  headers.merge!(metadata) unless metadata.nil?
202
226
  client_config_file = Pathname.new(__dir__).join(
203
227
  "publisher_client_config.json"
@@ -289,6 +313,14 @@ module Google
289
313
  {'topic' => request.topic}
290
314
  end
291
315
  )
316
+ @list_topic_snapshots = Google::Gax.create_api_call(
317
+ @publisher_stub.method(:list_topic_snapshots),
318
+ defaults["list_topic_snapshots"],
319
+ exception_transformer: exception_transformer,
320
+ params_extractor: proc do |request|
321
+ {'topic' => request.topic}
322
+ end
323
+ )
292
324
  @delete_topic = Google::Gax.create_api_call(
293
325
  @publisher_stub.method(:delete_topic),
294
326
  defaults["delete_topic"],
@@ -321,6 +353,14 @@ module Google
321
353
  {'resource' => request.resource}
322
354
  end
323
355
  )
356
+ @detach_subscription = Google::Gax.create_api_call(
357
+ @publisher_stub.method(:detach_subscription),
358
+ defaults["detach_subscription"],
359
+ exception_transformer: exception_transformer,
360
+ params_extractor: proc do |request|
361
+ {'subscription' => request.subscription}
362
+ end
363
+ )
324
364
  end
325
365
 
326
366
  # Service calls
@@ -330,7 +370,7 @@ module Google
330
370
  # resource name rules</a>.
331
371
  #
332
372
  # @param name [String]
333
- # The name of the topic. It must have the format
373
+ # Required. The name of the topic. It must have the format
334
374
  # `"projects/{project}/topics/{topic}"`. `{topic}` must start with a letter,
335
375
  # and contain only letters (`[A-Za-z]`), numbers (`[0-9]`), dashes (`-`),
336
376
  # underscores (`_`), periods (`.`), tildes (`~`), plus (`+`) or percent
@@ -386,15 +426,15 @@ module Google
386
426
  # topic are not modifiable.
387
427
  #
388
428
  # @param topic [Google::Cloud::PubSub::V1::Topic | Hash]
389
- # The updated topic object.
429
+ # Required. The updated topic object.
390
430
  # A hash of the same form as `Google::Cloud::PubSub::V1::Topic`
391
431
  # can also be provided.
392
432
  # @param update_mask [Google::Protobuf::FieldMask | Hash]
393
- # Indicates which fields in the provided topic to update. Must be specified
394
- # and non-empty. Note that if `update_mask` contains
395
- # "message_storage_policy" then the new value will be determined based on the
396
- # policy configured at the project or organization level. The
397
- # `message_storage_policy` must not be set in the `topic` provided above.
433
+ # Required. Indicates which fields in the provided topic to update. Must be
434
+ # specified and non-empty. Note that if `update_mask` contains
435
+ # "message_storage_policy" but the `message_storage_policy` is not set in
436
+ # the `topic` provided above, then the updated value is determined by the
437
+ # policy configured at the project or organization level.
398
438
  # A hash of the same form as `Google::Protobuf::FieldMask`
399
439
  # can also be provided.
400
440
  # @param options [Google::Gax::CallOptions]
@@ -434,10 +474,10 @@ module Google
434
474
  # does not exist.
435
475
  #
436
476
  # @param topic [String]
437
- # The messages in the request will be published on this topic.
477
+ # Required. The messages in the request will be published on this topic.
438
478
  # Format is `projects/{project}/topics/{topic}`.
439
479
  # @param messages [Array<Google::Cloud::PubSub::V1::PubsubMessage | Hash>]
440
- # The messages to publish.
480
+ # Required. The messages to publish.
441
481
  # A hash of the same form as `Google::Cloud::PubSub::V1::PubsubMessage`
442
482
  # can also be provided.
443
483
  # @param options [Google::Gax::CallOptions]
@@ -474,7 +514,7 @@ module Google
474
514
  # Gets the configuration of a topic.
475
515
  #
476
516
  # @param topic [String]
477
- # The name of the topic to get.
517
+ # Required. The name of the topic to get.
478
518
  # Format is `projects/{project}/topics/{topic}`.
479
519
  # @param options [Google::Gax::CallOptions]
480
520
  # Overrides the default settings for this call, e.g, timeout,
@@ -505,7 +545,7 @@ module Google
505
545
  # Lists matching topics.
506
546
  #
507
547
  # @param project [String]
508
- # The name of the project in which to list topics.
548
+ # Required. The name of the project in which to list topics.
509
549
  # Format is `projects/{project-id}`.
510
550
  # @param page_size [Integer]
511
551
  # The maximum number of resources contained in the underlying API
@@ -557,10 +597,10 @@ module Google
557
597
  @list_topics.call(req, options, &block)
558
598
  end
559
599
 
560
- # Lists the names of the subscriptions on this topic.
600
+ # Lists the names of the attached subscriptions on this topic.
561
601
  #
562
602
  # @param topic [String]
563
- # The name of the topic that subscriptions are attached to.
603
+ # Required. The name of the topic that subscriptions are attached to.
564
604
  # Format is `projects/{project}/topics/{topic}`.
565
605
  # @param page_size [Integer]
566
606
  # The maximum number of resources contained in the underlying API
@@ -612,6 +652,66 @@ module Google
612
652
  @list_topic_subscriptions.call(req, options, &block)
613
653
  end
614
654
 
655
+ # Lists the names of the snapshots on this topic. Snapshots are used in
656
+ # <a href="https://cloud.google.com/pubsub/docs/replay-overview">Seek</a>
657
+ # operations, which allow
658
+ # you to manage message acknowledgments in bulk. That is, you can set the
659
+ # acknowledgment state of messages in an existing subscription to the state
660
+ # captured by a snapshot.
661
+ #
662
+ # @param topic [String]
663
+ # Required. The name of the topic that snapshots are attached to.
664
+ # Format is `projects/{project}/topics/{topic}`.
665
+ # @param page_size [Integer]
666
+ # The maximum number of resources contained in the underlying API
667
+ # response. If page streaming is performed per-resource, this
668
+ # parameter does not affect the return value. If page streaming is
669
+ # performed per-page, this determines the maximum number of
670
+ # resources in a page.
671
+ # @param options [Google::Gax::CallOptions]
672
+ # Overrides the default settings for this call, e.g, timeout,
673
+ # retries, etc.
674
+ # @yield [result, operation] Access the result along with the RPC operation
675
+ # @yieldparam result [Google::Gax::PagedEnumerable<String>]
676
+ # @yieldparam operation [GRPC::ActiveCall::Operation]
677
+ # @return [Google::Gax::PagedEnumerable<String>]
678
+ # An enumerable of String instances.
679
+ # See Google::Gax::PagedEnumerable documentation for other
680
+ # operations such as per-page iteration or access to the response
681
+ # object.
682
+ # @raise [Google::Gax::GaxError] if the RPC is aborted.
683
+ # @example
684
+ # require "google/cloud/pubsub"
685
+ #
686
+ # publisher_client = Google::Cloud::PubSub::Publisher.new(version: :v1)
687
+ # formatted_topic = Google::Cloud::PubSub::V1::PublisherClient.topic_path("[PROJECT]", "[TOPIC]")
688
+ #
689
+ # # Iterate over all results.
690
+ # publisher_client.list_topic_snapshots(formatted_topic).each do |element|
691
+ # # Process element.
692
+ # end
693
+ #
694
+ # # Or iterate over results one page at a time.
695
+ # publisher_client.list_topic_snapshots(formatted_topic).each_page do |page|
696
+ # # Process each page at a time.
697
+ # page.each do |element|
698
+ # # Process element.
699
+ # end
700
+ # end
701
+
702
+ def list_topic_snapshots \
703
+ topic,
704
+ page_size: nil,
705
+ options: nil,
706
+ &block
707
+ req = {
708
+ topic: topic,
709
+ page_size: page_size
710
+ }.delete_if { |_, v| v.nil? }
711
+ req = Google::Gax::to_proto(req, Google::Cloud::PubSub::V1::ListTopicSnapshotsRequest)
712
+ @list_topic_snapshots.call(req, options, &block)
713
+ end
714
+
615
715
  # Deletes the topic with the given name. Returns `NOT_FOUND` if the topic
616
716
  # does not exist. After a topic is deleted, a new topic may be created with
617
717
  # the same name; this is an entirely new topic with none of the old
@@ -619,7 +719,7 @@ module Google
619
719
  # not deleted, but their `topic` field is set to `_deleted-topic_`.
620
720
  #
621
721
  # @param topic [String]
622
- # Name of the topic to delete.
722
+ # Required. Name of the topic to delete.
623
723
  # Format is `projects/{project}/topics/{topic}`.
624
724
  # @param options [Google::Gax::CallOptions]
625
725
  # Overrides the default settings for this call, e.g, timeout,
@@ -647,8 +747,11 @@ module Google
647
747
  nil
648
748
  end
649
749
 
650
- # Sets the access control policy on the specified resource. Replaces any
651
- # existing policy.
750
+ # Sets the access control policy on the specified resource. Replaces
751
+ # any existing policy.
752
+ #
753
+ # Can return `NOT_FOUND`, `INVALID_ARGUMENT`, and `PERMISSION_DENIED`
754
+ # errors.
652
755
  #
653
756
  # @param resource [String]
654
757
  # REQUIRED: The resource for which the policy is being specified.
@@ -672,11 +775,13 @@ module Google
672
775
  # require "google/cloud/pubsub"
673
776
  #
674
777
  # publisher_client = Google::Cloud::PubSub::Publisher.new(version: :v1)
675
- # formatted_resource = Google::Cloud::PubSub::V1::PublisherClient.topic_path("[PROJECT]", "[TOPIC]")
778
+ #
779
+ # # TODO: Initialize `resource`:
780
+ # resource = ''
676
781
  #
677
782
  # # TODO: Initialize `policy`:
678
783
  # policy = {}
679
- # response = publisher_client.set_iam_policy(formatted_resource, policy)
784
+ # response = publisher_client.set_iam_policy(resource, policy)
680
785
 
681
786
  def set_iam_policy \
682
787
  resource,
@@ -691,9 +796,8 @@ module Google
691
796
  @set_iam_policy.call(req, options, &block)
692
797
  end
693
798
 
694
- # Gets the access control policy for a resource.
695
- # Returns an empty policy if the resource exists and does not have a policy
696
- # set.
799
+ # Gets the access control policy for a resource. Returns an empty policy
800
+ # if the resource exists and does not have a policy set.
697
801
  #
698
802
  # @param resource [String]
699
803
  # REQUIRED: The resource for which the policy is being requested.
@@ -715,8 +819,10 @@ module Google
715
819
  # require "google/cloud/pubsub"
716
820
  #
717
821
  # publisher_client = Google::Cloud::PubSub::Publisher.new(version: :v1)
718
- # formatted_resource = Google::Cloud::PubSub::V1::PublisherClient.topic_path("[PROJECT]", "[TOPIC]")
719
- # response = publisher_client.get_iam_policy(formatted_resource)
822
+ #
823
+ # # TODO: Initialize `resource`:
824
+ # resource = ''
825
+ # response = publisher_client.get_iam_policy(resource)
720
826
 
721
827
  def get_iam_policy \
722
828
  resource,
@@ -731,13 +837,13 @@ module Google
731
837
  @get_iam_policy.call(req, options, &block)
732
838
  end
733
839
 
734
- # Returns permissions that a caller has on the specified resource.
735
- # If the resource does not exist, this will return an empty set of
736
- # permissions, not a NOT_FOUND error.
840
+ # Returns permissions that a caller has on the specified resource. If the
841
+ # resource does not exist, this will return an empty set of
842
+ # permissions, not a `NOT_FOUND` error.
737
843
  #
738
- # Note: This operation is designed to be used for building permission-aware
739
- # UIs and command-line tools, not for authorization checking. This operation
740
- # may "fail open" without warning.
844
+ # Note: This operation is designed to be used for building
845
+ # permission-aware UIs and command-line tools, not for authorization
846
+ # checking. This operation may "fail open" without warning.
741
847
  #
742
848
  # @param resource [String]
743
849
  # REQUIRED: The resource for which the policy detail is being requested.
@@ -759,11 +865,13 @@ module Google
759
865
  # require "google/cloud/pubsub"
760
866
  #
761
867
  # publisher_client = Google::Cloud::PubSub::Publisher.new(version: :v1)
762
- # formatted_resource = Google::Cloud::PubSub::V1::PublisherClient.topic_path("[PROJECT]", "[TOPIC]")
868
+ #
869
+ # # TODO: Initialize `resource`:
870
+ # resource = ''
763
871
  #
764
872
  # # TODO: Initialize `permissions`:
765
873
  # permissions = []
766
- # response = publisher_client.test_iam_permissions(formatted_resource, permissions)
874
+ # response = publisher_client.test_iam_permissions(resource, permissions)
767
875
 
768
876
  def test_iam_permissions \
769
877
  resource,
@@ -777,6 +885,40 @@ module Google
777
885
  req = Google::Gax::to_proto(req, Google::Iam::V1::TestIamPermissionsRequest)
778
886
  @test_iam_permissions.call(req, options, &block)
779
887
  end
888
+
889
+ # Detaches a subscription from this topic. All messages retained in the
890
+ # subscription are dropped. Subsequent `Pull` and `StreamingPull` requests
891
+ # will return FAILED_PRECONDITION. If the subscription is a push
892
+ # subscription, pushes to the endpoint will stop.
893
+ #
894
+ # @param subscription [String]
895
+ # Required. The subscription to detach.
896
+ # Format is `projects/{project}/subscriptions/{subscription}`.
897
+ # @param options [Google::Gax::CallOptions]
898
+ # Overrides the default settings for this call, e.g, timeout,
899
+ # retries, etc.
900
+ # @yield [result, operation] Access the result along with the RPC operation
901
+ # @yieldparam result [Google::Cloud::PubSub::V1::DetachSubscriptionResponse]
902
+ # @yieldparam operation [GRPC::ActiveCall::Operation]
903
+ # @return [Google::Cloud::PubSub::V1::DetachSubscriptionResponse]
904
+ # @raise [Google::Gax::GaxError] if the RPC is aborted.
905
+ # @example
906
+ # require "google/cloud/pubsub"
907
+ #
908
+ # publisher_client = Google::Cloud::PubSub::Publisher.new(version: :v1)
909
+ # formatted_subscription = Google::Cloud::PubSub::V1::PublisherClient.subscription_path("[PROJECT]", "[SUBSCRIPTION]")
910
+ # response = publisher_client.detach_subscription(formatted_subscription)
911
+
912
+ def detach_subscription \
913
+ subscription,
914
+ options: nil,
915
+ &block
916
+ req = {
917
+ subscription: subscription
918
+ }.delete_if { |_, v| v.nil? }
919
+ req = Google::Gax::to_proto(req, Google::Cloud::PubSub::V1::DetachSubscriptionRequest)
920
+ @detach_subscription.call(req, options, &block)
921
+ end
780
922
  end
781
923
  end
782
924
  end
@@ -7,9 +7,14 @@
7
7
  "UNAVAILABLE",
8
8
  "UNKNOWN"
9
9
  ],
10
+ "non_idempotent2": [],
10
11
  "non_idempotent": [
11
12
  "UNAVAILABLE"
12
13
  ],
14
+ "idempotent2": [
15
+ "DEADLINE_EXCEEDED",
16
+ "UNAVAILABLE"
17
+ ],
13
18
  "none": [],
14
19
  "publish": [
15
20
  "ABORTED",
@@ -53,7 +58,7 @@
53
58
  "retry_params_name": "default"
54
59
  },
55
60
  "Publish": {
56
- "timeout_millis": 60000,
61
+ "timeout_millis": 20000,
57
62
  "retry_codes_name": "publish",
58
63
  "retry_params_name": "messaging",
59
64
  "bundling": {
@@ -79,6 +84,11 @@
79
84
  "retry_codes_name": "idempotent",
80
85
  "retry_params_name": "default"
81
86
  },
87
+ "ListTopicSnapshots": {
88
+ "timeout_millis": 60000,
89
+ "retry_codes_name": "idempotent2",
90
+ "retry_params_name": "default"
91
+ },
82
92
  "DeleteTopic": {
83
93
  "timeout_millis": 60000,
84
94
  "retry_codes_name": "non_idempotent",
@@ -98,6 +108,11 @@
98
108
  "timeout_millis": 60000,
99
109
  "retry_codes_name": "non_idempotent",
100
110
  "retry_params_name": "default"
111
+ },
112
+ "DetachSubscription": {
113
+ "timeout_millis": 60000,
114
+ "retry_codes_name": "non_idempotent2",
115
+ "retry_params_name": "default"
101
116
  }
102
117
  }
103
118
  }