google-cloud-pubsub 0.31.1 → 0.32.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (28) hide show
  1. checksums.yaml +4 -4
  2. data/.yardopts +1 -0
  3. data/README.md +8 -8
  4. data/lib/google/cloud/pubsub/async_publisher.rb +4 -0
  5. data/lib/google/cloud/pubsub/credentials.rb +2 -14
  6. data/lib/google/cloud/pubsub/subscriber.rb +85 -0
  7. data/lib/google/cloud/pubsub/subscriber/async_stream_pusher.rb +24 -19
  8. data/lib/google/cloud/pubsub/subscriber/async_unary_pusher.rb +45 -26
  9. data/lib/google/cloud/pubsub/subscriber/inventory.rb +136 -0
  10. data/lib/google/cloud/pubsub/subscriber/stream.rb +80 -138
  11. data/lib/google/cloud/pubsub/subscription.rb +2 -2
  12. data/lib/google/cloud/pubsub/topic.rb +4 -4
  13. data/lib/google/cloud/pubsub/v1/credentials.rb +38 -0
  14. data/lib/google/cloud/pubsub/v1/doc/google/iam/v1/iam_policy.rb +62 -0
  15. data/lib/google/cloud/pubsub/v1/doc/google/iam/v1/policy.rb +127 -0
  16. data/lib/google/cloud/pubsub/v1/doc/google/protobuf/duration.rb +1 -1
  17. data/lib/google/cloud/pubsub/v1/doc/google/protobuf/empty.rb +28 -0
  18. data/lib/google/cloud/pubsub/v1/doc/google/protobuf/field_mask.rb +1 -1
  19. data/lib/google/cloud/pubsub/v1/doc/google/protobuf/timestamp.rb +1 -1
  20. data/lib/google/cloud/pubsub/v1/doc/google/pubsub/v1/pubsub.rb +113 -31
  21. data/lib/google/cloud/pubsub/v1/publisher_client.rb +180 -109
  22. data/lib/google/cloud/pubsub/v1/subscriber_client.rb +322 -193
  23. data/lib/google/cloud/pubsub/v1/subscriber_client_config.json +1 -1
  24. data/lib/google/cloud/pubsub/version.rb +1 -1
  25. data/lib/google/pubsub/v1/pubsub_pb.rb +21 -0
  26. data/lib/google/pubsub/v1/pubsub_services_pb.rb +87 -73
  27. metadata +23 -5
  28. data/lib/google/cloud/pubsub/v1/doc/overview.rb +0 -75
@@ -1,4 +1,4 @@
1
- # Copyright 2017 Google LLC
1
+ # Copyright 2018 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.
@@ -0,0 +1,28 @@
1
+ # Copyright 2018 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
+
15
+ module Google
16
+ module Protobuf
17
+ # A generic empty message that you can re-use to avoid defining duplicated
18
+ # empty messages in your APIs. A typical example is to use it as the request
19
+ # or the response type of an API method. For instance:
20
+ #
21
+ # service Foo {
22
+ # rpc Bar(google.protobuf.Empty) returns (google.protobuf.Empty);
23
+ # }
24
+ #
25
+ # The JSON representation for +Empty+ is empty JSON object +{}+.
26
+ class Empty; end
27
+ end
28
+ end
@@ -1,4 +1,4 @@
1
- # Copyright 2017 Google LLC
1
+ # Copyright 2018 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.
@@ -1,4 +1,4 @@
1
- # Copyright 2017 Google LLC
1
+ # Copyright 2018 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.
@@ -1,4 +1,4 @@
1
- # Copyright 2017 Google LLC
1
+ # Copyright 2018 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.
@@ -14,20 +14,17 @@
14
14
 
15
15
  module Google
16
16
  module Pubsub
17
- ##
18
- # # Google Cloud Pub/Sub API Contents
19
- #
20
- # | Class | Description |
21
- # | ----- | ----------- |
22
- # | [PublisherClient][] | Provides reliable, many-to-many, asynchronous messaging between applications. |
23
- # | [SubscriberClient][] | Provides reliable, many-to-many, asynchronous messaging between applications. |
24
- # | [Data Types][] | Data types for Google::Cloud::Pubsub::V1 |
25
- #
26
- # [PublisherClient]: https://googlecloudplatform.github.io/google-cloud-ruby/#/docs/google-cloud-pubsub/latest/google/pubsub/v1/publisherclient
27
- # [SubscriberClient]: https://googlecloudplatform.github.io/google-cloud-ruby/#/docs/google-cloud-pubsub/latest/google/pubsub/v1/subscriberclient
28
- # [Data Types]: https://googlecloudplatform.github.io/google-cloud-ruby/#/docs/google-cloud-pubsub/latest/google/pubsub/v1/datatypes
29
- #
30
17
  module V1
18
+ # @!attribute [rw] allowed_persistence_regions
19
+ # @return [Array<String>]
20
+ # The list of GCP regions where messages that are published to the topic may
21
+ # be persisted in storage. Messages published by publishers running in
22
+ # non-allowed GCP regions (or running outside of GCP altogether) will be
23
+ # routed for storage in one of the allowed regions. An empty list indicates a
24
+ # misconfiguration at the project or organization level, which will result in
25
+ # all Publish operations failing.
26
+ class MessageStoragePolicy; end
27
+
31
28
  # A topic resource.
32
29
  # @!attribute [rw] name
33
30
  # @return [String]
@@ -40,6 +37,14 @@ module Google
40
37
  # @!attribute [rw] labels
41
38
  # @return [Hash{String => String}]
42
39
  # User labels.
40
+ # @!attribute [rw] message_storage_policy
41
+ # @return [Google::Pubsub::V1::MessageStoragePolicy]
42
+ # Policy constraining how messages published to the topic may be stored. It
43
+ # is determined when the topic is created based on the policy configured at
44
+ # the project level. It must not be set by the caller in the request to
45
+ # CreateTopic or to UpdateTopic. This field will be populated in the
46
+ # responses for GetTopic, CreateTopic, and UpdateTopic: if not present in the
47
+ # response, then no constraints are in effect.
43
48
  class Topic; end
44
49
 
45
50
  # A message data and its attributes. The message payload must not be empty;
@@ -73,11 +78,14 @@ module Google
73
78
  # Request for the UpdateTopic method.
74
79
  # @!attribute [rw] topic
75
80
  # @return [Google::Pubsub::V1::Topic]
76
- # The topic to update.
81
+ # The updated topic object.
77
82
  # @!attribute [rw] update_mask
78
83
  # @return [Google::Protobuf::FieldMask]
79
- # Indicates which fields in the provided topic to update.
80
- # Must be specified and non-empty.
84
+ # Indicates which fields in the provided topic to update. Must be specified
85
+ # and non-empty. Note that if +update_mask+ contains
86
+ # "message_storage_policy" then the new value will be determined based on the
87
+ # policy configured at the project or organization level. The
88
+ # +message_storage_policy+ must not be set in the +topic+ provided above.
81
89
  class UpdateTopicRequest; end
82
90
 
83
91
  # Request for the Publish method.
@@ -149,6 +157,38 @@ module Google
149
157
  # +ListTopicSubscriptionsRequest+ to get more subscriptions.
150
158
  class ListTopicSubscriptionsResponse; end
151
159
 
160
+ # Request for the +ListTopicSnapshots+ method.<br><br>
161
+ # <b>ALPHA:</b> This feature is part of an alpha release. This API might be
162
+ # changed in backward-incompatible ways and is not recommended for production
163
+ # use. It is not subject to any SLA or deprecation policy.
164
+ # @!attribute [rw] topic
165
+ # @return [String]
166
+ # The name of the topic that snapshots are attached to.
167
+ # Format is +projects/{project}/topics/{topic}+.
168
+ # @!attribute [rw] page_size
169
+ # @return [Integer]
170
+ # Maximum number of snapshot names to return.
171
+ # @!attribute [rw] page_token
172
+ # @return [String]
173
+ # The value returned by the last +ListTopicSnapshotsResponse+; indicates
174
+ # that this is a continuation of a prior +ListTopicSnapshots+ call, and
175
+ # that the system should return the next page of data.
176
+ class ListTopicSnapshotsRequest; end
177
+
178
+ # Response for the +ListTopicSnapshots+ method.<br><br>
179
+ # <b>ALPHA:</b> This feature is part of an alpha release. This API might be
180
+ # changed in backward-incompatible ways and is not recommended for production
181
+ # use. It is not subject to any SLA or deprecation policy.
182
+ # @!attribute [rw] snapshots
183
+ # @return [Array<String>]
184
+ # The names of the snapshots that match the request.
185
+ # @!attribute [rw] next_page_token
186
+ # @return [String]
187
+ # If not empty, indicates that there may be more snapshots that match
188
+ # the request; this value should be passed in a new
189
+ # +ListTopicSnapshotsRequest+ to get more snapshots.
190
+ class ListTopicSnapshotsResponse; end
191
+
152
192
  # Request for the +DeleteTopic+ method.
153
193
  # @!attribute [rw] topic
154
194
  # @return [String]
@@ -164,7 +204,7 @@ module Google
164
204
  # start with a letter, and contain only letters (+[A-Za-z]+), numbers
165
205
  # (+[0-9]+), dashes (+-+), underscores (+_+), periods (+.+), tildes (+~+),
166
206
  # plus (+++) or percent signs (+%+). It must be between 3 and 255 characters
167
- # in length, and it must not start with +"goog"+.
207
+ # in length, and it must not start with +"goog"+
168
208
  # @!attribute [rw] topic
169
209
  # @return [String]
170
210
  # The name of the topic from which this subscription is receiving messages.
@@ -187,7 +227,8 @@ module Google
187
227
  # For pull subscriptions, this value is used as the initial value for the ack
188
228
  # deadline. To override this value for a given message, call
189
229
  # +ModifyAckDeadline+ with the corresponding +ack_id+ if using
190
- # pull.
230
+ # non-streaming pull or send the +ack_id+ in a
231
+ # +StreamingModifyAckDeadlineRequest+ if using streaming pull.
191
232
  # The minimum custom deadline you can specify is 10 seconds.
192
233
  # The maximum custom deadline you can specify is 600 seconds (10 minutes).
193
234
  # If this parameter is 0, a default value of 10 seconds is used.
@@ -202,7 +243,10 @@ module Google
202
243
  # Indicates whether to retain acknowledged messages. If true, then
203
244
  # messages are not expunged from the subscription's backlog, even if they are
204
245
  # acknowledged, until they fall out of the +message_retention_duration+
205
- # window.
246
+ # window.<br><br>
247
+ # <b>ALPHA:</b> This feature is part of an alpha release. This API might be
248
+ # changed in backward-incompatible ways and is not recommended for production
249
+ # use. It is not subject to any SLA or deprecation policy.
206
250
  # @!attribute [rw] message_retention_duration
207
251
  # @return [Google::Protobuf::Duration]
208
252
  # How long to retain unacknowledged messages in the subscription's backlog,
@@ -210,7 +254,10 @@ module Google
210
254
  # If +retain_acked_messages+ is true, then this also configures the retention
211
255
  # of acknowledged messages, and thus configures how far back in time a +Seek+
212
256
  # can be done. Defaults to 7 days. Cannot be more than 7 days or less than 10
213
- # minutes.
257
+ # minutes.<br><br>
258
+ # <b>ALPHA:</b> This feature is part of an alpha release. This API might be
259
+ # changed in backward-incompatible ways and is not recommended for production
260
+ # use. It is not subject to any SLA or deprecation policy.
214
261
  # @!attribute [rw] labels
215
262
  # @return [Hash{String => String}]
216
263
  # User labels.
@@ -317,7 +364,7 @@ module Google
317
364
  # An empty +pushConfig+ indicates that the Pub/Sub system should
318
365
  # stop pushing messages from the given subscription and allow
319
366
  # messages to be pulled and acknowledged - effectively pausing
320
- # the subscription if +Pull+ is not called.
367
+ # the subscription if +Pull+ or +StreamingPull+ is not called.
321
368
  class ModifyPushConfigRequest; end
322
369
 
323
370
  # Request for the +Pull+ method.
@@ -429,7 +476,10 @@ module Google
429
476
  # Received Pub/Sub messages. This will not be empty.
430
477
  class StreamingPullResponse; end
431
478
 
432
- # Request for the +CreateSnapshot+ method.
479
+ # Request for the +CreateSnapshot+ method.<br><br>
480
+ # <b>ALPHA:</b> This feature is part of an alpha release. This API might be changed in
481
+ # backward-incompatible ways and is not recommended for production use.
482
+ # It is not subject to any SLA or deprecation policy.
433
483
  # @!attribute [rw] name
434
484
  # @return [String]
435
485
  # Optional user-provided name for this snapshot.
@@ -448,19 +498,28 @@ module Google
448
498
  # (b) Any messages published to the subscription's topic following the
449
499
  # successful completion of the CreateSnapshot request.
450
500
  # Format is +projects/{project}/subscriptions/{sub}+.
501
+ # @!attribute [rw] labels
502
+ # @return [Hash{String => String}]
503
+ # User labels.
451
504
  class CreateSnapshotRequest; end
452
505
 
453
- # Request for the UpdateSnapshot method.
506
+ # Request for the UpdateSnapshot method.<br><br>
507
+ # <b>ALPHA:</b> This feature is part of an alpha release. This API might be
508
+ # changed in backward-incompatible ways and is not recommended for production
509
+ # use. It is not subject to any SLA or deprecation policy.
454
510
  # @!attribute [rw] snapshot
455
511
  # @return [Google::Pubsub::V1::Snapshot]
456
- # The updated snpashot object.
512
+ # The updated snapshot object.
457
513
  # @!attribute [rw] update_mask
458
514
  # @return [Google::Protobuf::FieldMask]
459
515
  # Indicates which fields in the provided snapshot to update.
460
516
  # Must be specified and non-empty.
461
517
  class UpdateSnapshotRequest; end
462
518
 
463
- # A snapshot resource.
519
+ # A snapshot resource.<br><br>
520
+ # <b>ALPHA:</b> This feature is part of an alpha release. This API might be
521
+ # changed in backward-incompatible ways and is not recommended for production
522
+ # use. It is not subject to any SLA or deprecation policy.
464
523
  # @!attribute [rw] name
465
524
  # @return [String]
466
525
  # The name of the snapshot.
@@ -477,13 +536,27 @@ module Google
477
536
  # For example, consider a subscription whose oldest unacked message is 3 days
478
537
  # old. If a snapshot is created from this subscription, the snapshot -- which
479
538
  # will always capture this 3-day-old backlog as long as the snapshot
480
- # exists -- will expire in 4 days.
539
+ # exists -- will expire in 4 days. The service will refuse to create a
540
+ # snapshot that would expire in less than 1 hour after creation.
481
541
  # @!attribute [rw] labels
482
542
  # @return [Hash{String => String}]
483
543
  # User labels.
484
544
  class Snapshot; end
485
545
 
486
- # Request for the +ListSnapshots+ method.
546
+ # Request for the GetSnapshot method.<br><br>
547
+ # <b>ALPHA:</b> This feature is part of an alpha release. This API might be
548
+ # changed in backward-incompatible ways and is not recommended for production
549
+ # use. It is not subject to any SLA or deprecation policy.
550
+ # @!attribute [rw] snapshot
551
+ # @return [String]
552
+ # The name of the snapshot to get.
553
+ # Format is +projects/{project}/snapshots/{snap}+.
554
+ class GetSnapshotRequest; end
555
+
556
+ # Request for the +ListSnapshots+ method.<br><br>
557
+ # <b>ALPHA:</b> This feature is part of an alpha release. This API might be
558
+ # changed in backward-incompatible ways and is not recommended for production
559
+ # use. It is not subject to any SLA or deprecation policy.
487
560
  # @!attribute [rw] project
488
561
  # @return [String]
489
562
  # The name of the cloud project that snapshots belong to.
@@ -498,7 +571,10 @@ module Google
498
571
  # should return the next page of data.
499
572
  class ListSnapshotsRequest; end
500
573
 
501
- # Response for the +ListSnapshots+ method.
574
+ # Response for the +ListSnapshots+ method.<br><br>
575
+ # <b>ALPHA:</b> This feature is part of an alpha release. This API might be
576
+ # changed in backward-incompatible ways and is not recommended for production
577
+ # use. It is not subject to any SLA or deprecation policy.
502
578
  # @!attribute [rw] snapshots
503
579
  # @return [Array<Google::Pubsub::V1::Snapshot>]
504
580
  # The resulting snapshots.
@@ -508,14 +584,20 @@ module Google
508
584
  # request; this value should be passed in a new +ListSnapshotsRequest+.
509
585
  class ListSnapshotsResponse; end
510
586
 
511
- # Request for the +DeleteSnapshot+ method.
587
+ # Request for the +DeleteSnapshot+ method.<br><br>
588
+ # <b>ALPHA:</b> This feature is part of an alpha release. This API might be
589
+ # changed in backward-incompatible ways and is not recommended for production
590
+ # use. It is not subject to any SLA or deprecation policy.
512
591
  # @!attribute [rw] snapshot
513
592
  # @return [String]
514
593
  # The name of the snapshot to delete.
515
594
  # Format is +projects/{project}/snapshots/{snap}+.
516
595
  class DeleteSnapshotRequest; end
517
596
 
518
- # Request for the +Seek+ method.
597
+ # Request for the +Seek+ method.<br><br>
598
+ # <b>ALPHA:</b> This feature is part of an alpha release. This API might be
599
+ # changed in backward-incompatible ways and is not recommended for production
600
+ # use. It is not subject to any SLA or deprecation policy.
519
601
  # @!attribute [rw] subscription
520
602
  # @return [String]
521
603
  # The subscription to affect.
@@ -1,4 +1,4 @@
1
- # Copyright 2017 Google LLC
1
+ # Copyright 2018 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.
@@ -18,9 +18,6 @@
18
18
  # and updates to that file get reflected here through a refresh process.
19
19
  # For the short term, the refresh process will only be runnable by Google
20
20
  # engineers.
21
- #
22
- # The only allowed edits are to method and file documentation. A 3-way
23
- # merge preserves those additions if the generated source changes.
24
21
 
25
22
  require "json"
26
23
  require "pathname"
@@ -29,7 +26,7 @@ require "google/gax"
29
26
 
30
27
  require "google/iam/v1/iam_policy_pb"
31
28
  require "google/pubsub/v1/pubsub_pb"
32
- require "google/cloud/pubsub/credentials"
29
+ require "google/cloud/pubsub/v1/credentials"
33
30
 
34
31
  module Google
35
32
  module Cloud
@@ -51,6 +48,9 @@ module Google
51
48
  # The default port of the service.
52
49
  DEFAULT_SERVICE_PORT = 443
53
50
 
51
+ # The default set of gRPC interceptors.
52
+ GRPC_INTERCEPTORS = []
53
+
54
54
  DEFAULT_TIMEOUT = 30
55
55
 
56
56
  PAGE_DESCRIPTORS = {
@@ -84,11 +84,6 @@ module Google
84
84
  "https://www.googleapis.com/auth/pubsub"
85
85
  ].freeze
86
86
 
87
- PROJECT_PATH_TEMPLATE = Google::Gax::PathTemplate.new(
88
- "projects/{project}"
89
- )
90
-
91
- private_constant :PROJECT_PATH_TEMPLATE
92
87
 
93
88
  TOPIC_PATH_TEMPLATE = Google::Gax::PathTemplate.new(
94
89
  "projects/{project}/topics/{topic}"
@@ -96,14 +91,11 @@ module Google
96
91
 
97
92
  private_constant :TOPIC_PATH_TEMPLATE
98
93
 
99
- # Returns a fully-qualified project resource name string.
100
- # @param project [String]
101
- # @return [String]
102
- def self.project_path project
103
- PROJECT_PATH_TEMPLATE.render(
104
- :"project" => project
105
- )
106
- end
94
+ PROJECT_PATH_TEMPLATE = Google::Gax::PathTemplate.new(
95
+ "projects/{project}"
96
+ )
97
+
98
+ private_constant :PROJECT_PATH_TEMPLATE
107
99
 
108
100
  # Returns a fully-qualified topic resource name string.
109
101
  # @param project [String]
@@ -116,6 +108,15 @@ module Google
116
108
  )
117
109
  end
118
110
 
111
+ # Returns a fully-qualified project resource name string.
112
+ # @param project [String]
113
+ # @return [String]
114
+ def self.project_path project
115
+ PROJECT_PATH_TEMPLATE.render(
116
+ :"project" => project
117
+ )
118
+ end
119
+
119
120
  # @param credentials [Google::Auth::Credentials, String, Hash, GRPC::Core::Channel, GRPC::Core::ChannelCredentials, Proc]
120
121
  # Provides the means for authenticating requests made by the client. This parameter can
121
122
  # be many types.
@@ -140,16 +141,18 @@ module Google
140
141
  # or the specified config is missing data points.
141
142
  # @param timeout [Numeric]
142
143
  # The default timeout, in seconds, for calls made through this client.
144
+ # @param metadata [Hash]
145
+ # Default metadata to be sent with each request. This can be overridden on a per call basis.
146
+ # @param exception_transformer [Proc]
147
+ # An optional proc that intercepts any exceptions raised during an API call to inject
148
+ # custom error handling.
143
149
  def initialize \
144
- service_path: SERVICE_ADDRESS,
145
- port: DEFAULT_SERVICE_PORT,
146
- channel: nil,
147
- chan_creds: nil,
148
- updater_proc: nil,
149
150
  credentials: nil,
150
151
  scopes: ALL_SCOPES,
151
152
  client_config: {},
152
153
  timeout: DEFAULT_TIMEOUT,
154
+ metadata: nil,
155
+ exception_transformer: nil,
153
156
  lib_name: nil,
154
157
  lib_version: ""
155
158
  # These require statements are intentionally placed here to initialize
@@ -159,21 +162,10 @@ module Google
159
162
  require "google/iam/v1/iam_policy_services_pb"
160
163
  require "google/pubsub/v1/pubsub_services_pb"
161
164
 
162
- if channel || chan_creds || updater_proc
163
- warn "The `channel`, `chan_creds`, and `updater_proc` parameters will be removed " \
164
- "on 2017/09/08"
165
- credentials ||= channel
166
- credentials ||= chan_creds
167
- credentials ||= updater_proc
168
- end
169
- if service_path != SERVICE_ADDRESS || port != DEFAULT_SERVICE_PORT
170
- warn "`service_path` and `port` parameters are deprecated and will be removed"
171
- end
172
-
173
- credentials ||= Google::Cloud::Pubsub::Credentials.default
165
+ credentials ||= Google::Cloud::Pubsub::V1::Credentials.default
174
166
 
175
167
  if credentials.is_a?(String) || credentials.is_a?(Hash)
176
- updater_proc = Google::Cloud::Pubsub::Credentials.new(credentials).updater_proc
168
+ updater_proc = Google::Cloud::Pubsub::V1::Credentials.new(credentials).updater_proc
177
169
  end
178
170
  if credentials.is_a?(GRPC::Core::Channel)
179
171
  channel = credentials
@@ -188,13 +180,16 @@ module Google
188
180
  updater_proc = credentials.updater_proc
189
181
  end
190
182
 
183
+ package_version = Gem.loaded_specs['google-cloud-pubsub'].version.version
184
+
191
185
  google_api_client = "gl-ruby/#{RUBY_VERSION}"
192
186
  google_api_client << " #{lib_name}/#{lib_version}" if lib_name
193
- google_api_client << " gapic/0.1.0 gax/#{Google::Gax::VERSION}"
187
+ google_api_client << " gapic/#{package_version} gax/#{Google::Gax::VERSION}"
194
188
  google_api_client << " grpc/#{GRPC::VERSION}"
195
189
  google_api_client.freeze
196
190
 
197
191
  headers = { :"x-goog-api-client" => google_api_client }
192
+ headers.merge!(metadata) unless metadata.nil?
198
193
  client_config_file = Pathname.new(__dir__).join(
199
194
  "publisher_client_config.json"
200
195
  )
@@ -208,9 +203,14 @@ module Google
208
203
  bundle_descriptors: BUNDLE_DESCRIPTORS,
209
204
  page_descriptors: PAGE_DESCRIPTORS,
210
205
  errors: Google::Gax::Grpc::API_ERRORS,
211
- kwargs: headers
206
+ metadata: headers
212
207
  )
213
208
  end
209
+
210
+ # Allow overriding the service path/port in subclasses.
211
+ service_path = self.class::SERVICE_ADDRESS
212
+ port = self.class::DEFAULT_SERVICE_PORT
213
+ interceptors = self.class::GRPC_INTERCEPTORS
214
214
  @iam_policy_stub = Google::Gax::Grpc.create_stub(
215
215
  service_path,
216
216
  port,
@@ -218,6 +218,7 @@ module Google
218
218
  channel: channel,
219
219
  updater_proc: updater_proc,
220
220
  scopes: scopes,
221
+ interceptors: interceptors,
221
222
  &Google::Iam::V1::IAMPolicy::Stub.method(:new)
222
223
  )
223
224
  @publisher_stub = Google::Gax::Grpc.create_stub(
@@ -227,54 +228,66 @@ module Google
227
228
  channel: channel,
228
229
  updater_proc: updater_proc,
229
230
  scopes: scopes,
231
+ interceptors: interceptors,
230
232
  &Google::Pubsub::V1::Publisher::Stub.method(:new)
231
233
  )
232
234
 
233
- @set_iam_policy = Google::Gax.create_api_call(
234
- @iam_policy_stub.method(:set_iam_policy),
235
- defaults["set_iam_policy"]
236
- )
237
- @get_iam_policy = Google::Gax.create_api_call(
238
- @iam_policy_stub.method(:get_iam_policy),
239
- defaults["get_iam_policy"]
240
- )
241
- @test_iam_permissions = Google::Gax.create_api_call(
242
- @iam_policy_stub.method(:test_iam_permissions),
243
- defaults["test_iam_permissions"]
244
- )
245
235
  @create_topic = Google::Gax.create_api_call(
246
236
  @publisher_stub.method(:create_topic),
247
- defaults["create_topic"]
237
+ defaults["create_topic"],
238
+ exception_transformer: exception_transformer
248
239
  )
249
240
  @update_topic = Google::Gax.create_api_call(
250
241
  @publisher_stub.method(:update_topic),
251
- defaults["update_topic"]
242
+ defaults["update_topic"],
243
+ exception_transformer: exception_transformer
252
244
  )
253
245
  @publish = Google::Gax.create_api_call(
254
246
  @publisher_stub.method(:publish),
255
- defaults["publish"]
247
+ defaults["publish"],
248
+ exception_transformer: exception_transformer
256
249
  )
257
250
  @get_topic = Google::Gax.create_api_call(
258
251
  @publisher_stub.method(:get_topic),
259
- defaults["get_topic"]
252
+ defaults["get_topic"],
253
+ exception_transformer: exception_transformer
260
254
  )
261
255
  @list_topics = Google::Gax.create_api_call(
262
256
  @publisher_stub.method(:list_topics),
263
- defaults["list_topics"]
257
+ defaults["list_topics"],
258
+ exception_transformer: exception_transformer
264
259
  )
265
260
  @list_topic_subscriptions = Google::Gax.create_api_call(
266
261
  @publisher_stub.method(:list_topic_subscriptions),
267
- defaults["list_topic_subscriptions"]
262
+ defaults["list_topic_subscriptions"],
263
+ exception_transformer: exception_transformer
268
264
  )
269
265
  @delete_topic = Google::Gax.create_api_call(
270
266
  @publisher_stub.method(:delete_topic),
271
- defaults["delete_topic"]
267
+ defaults["delete_topic"],
268
+ exception_transformer: exception_transformer
269
+ )
270
+ @set_iam_policy = Google::Gax.create_api_call(
271
+ @iam_policy_stub.method(:set_iam_policy),
272
+ defaults["set_iam_policy"],
273
+ exception_transformer: exception_transformer
274
+ )
275
+ @get_iam_policy = Google::Gax.create_api_call(
276
+ @iam_policy_stub.method(:get_iam_policy),
277
+ defaults["get_iam_policy"],
278
+ exception_transformer: exception_transformer
279
+ )
280
+ @test_iam_permissions = Google::Gax.create_api_call(
281
+ @iam_policy_stub.method(:test_iam_permissions),
282
+ defaults["test_iam_permissions"],
283
+ exception_transformer: exception_transformer
272
284
  )
273
285
  end
274
286
 
275
287
  # Service calls
276
288
 
277
- # Creates the given topic with the given name.
289
+ # Creates the given topic with the given name. See the
290
+ # <a href="/pubsub/docs/admin#resource_names"> resource name rules</a>.
278
291
  #
279
292
  # @param name [String]
280
293
  # The name of the topic. It must have the format
@@ -285,69 +298,91 @@ module Google
285
298
  # must not start with +"goog"+.
286
299
  # @param labels [Hash{String => String}]
287
300
  # User labels.
301
+ # @param message_storage_policy [Google::Pubsub::V1::MessageStoragePolicy | Hash]
302
+ # Policy constraining how messages published to the topic may be stored. It
303
+ # is determined when the topic is created based on the policy configured at
304
+ # the project level. It must not be set by the caller in the request to
305
+ # CreateTopic or to UpdateTopic. This field will be populated in the
306
+ # responses for GetTopic, CreateTopic, and UpdateTopic: if not present in the
307
+ # response, then no constraints are in effect.
308
+ # A hash of the same form as `Google::Pubsub::V1::MessageStoragePolicy`
309
+ # can also be provided.
288
310
  # @param options [Google::Gax::CallOptions]
289
311
  # Overrides the default settings for this call, e.g, timeout,
290
312
  # retries, etc.
313
+ # @yield [result, operation] Access the result along with the RPC operation
314
+ # @yieldparam result [Google::Pubsub::V1::Topic]
315
+ # @yieldparam operation [GRPC::ActiveCall::Operation]
291
316
  # @return [Google::Pubsub::V1::Topic]
292
317
  # @raise [Google::Gax::GaxError] if the RPC is aborted.
293
318
  # @example
294
- # require "google/cloud/pubsub/v1"
319
+ # require "google/cloud/pubsub"
295
320
  #
296
- # publisher_client = Google::Cloud::Pubsub::V1::Publisher.new
321
+ # publisher_client = Google::Cloud::Pubsub::Publisher.new(version: :v1)
297
322
  # formatted_name = Google::Cloud::Pubsub::V1::PublisherClient.topic_path("[PROJECT]", "[TOPIC]")
298
323
  # response = publisher_client.create_topic(formatted_name)
299
324
 
300
325
  def create_topic \
301
326
  name,
302
327
  labels: nil,
303
- options: nil
328
+ message_storage_policy: nil,
329
+ options: nil,
330
+ &block
304
331
  req = {
305
332
  name: name,
306
- labels: labels
333
+ labels: labels,
334
+ message_storage_policy: message_storage_policy
307
335
  }.delete_if { |_, v| v.nil? }
308
336
  req = Google::Gax::to_proto(req, Google::Pubsub::V1::Topic)
309
- @create_topic.call(req, options)
337
+ @create_topic.call(req, options, &block)
310
338
  end
311
339
 
312
- # Updates an existing topic. Note that certain properties of a topic are not
313
- # modifiable. Options settings follow the style guide:
314
- # NOTE: The style guide requires body: "topic" instead of body: "*".
315
- # Keeping the latter for internal consistency in V1, however it should be
316
- # corrected in V2. See
317
- # https://cloud.google.com/apis/design/standard_methods#update for details.
340
+ # Updates an existing topic. Note that certain properties of a
341
+ # topic are not modifiable.
318
342
  #
319
343
  # @param topic [Google::Pubsub::V1::Topic | Hash]
320
- # The topic to update.
344
+ # The updated topic object.
321
345
  # A hash of the same form as `Google::Pubsub::V1::Topic`
322
346
  # can also be provided.
323
347
  # @param update_mask [Google::Protobuf::FieldMask | Hash]
324
- # Indicates which fields in the provided topic to update.
325
- # Must be specified and non-empty.
348
+ # Indicates which fields in the provided topic to update. Must be specified
349
+ # and non-empty. Note that if +update_mask+ contains
350
+ # "message_storage_policy" then the new value will be determined based on the
351
+ # policy configured at the project or organization level. The
352
+ # +message_storage_policy+ must not be set in the +topic+ provided above.
326
353
  # A hash of the same form as `Google::Protobuf::FieldMask`
327
354
  # can also be provided.
328
355
  # @param options [Google::Gax::CallOptions]
329
356
  # Overrides the default settings for this call, e.g, timeout,
330
357
  # retries, etc.
358
+ # @yield [result, operation] Access the result along with the RPC operation
359
+ # @yieldparam result [Google::Pubsub::V1::Topic]
360
+ # @yieldparam operation [GRPC::ActiveCall::Operation]
331
361
  # @return [Google::Pubsub::V1::Topic]
332
362
  # @raise [Google::Gax::GaxError] if the RPC is aborted.
333
363
  # @example
334
- # require "google/cloud/pubsub/v1"
364
+ # require "google/cloud/pubsub"
365
+ #
366
+ # publisher_client = Google::Cloud::Pubsub::Publisher.new(version: :v1)
335
367
  #
336
- # publisher_client = Google::Cloud::Pubsub::V1::Publisher.new
368
+ # # TODO: Initialize +topic+:
337
369
  # topic = {}
370
+ #
371
+ # # TODO: Initialize +update_mask+:
338
372
  # update_mask = {}
339
373
  # response = publisher_client.update_topic(topic, update_mask)
340
374
 
341
375
  def update_topic \
342
376
  topic,
343
377
  update_mask,
344
- options: nil
378
+ options: nil,
379
+ &block
345
380
  req = {
346
381
  topic: topic,
347
382
  update_mask: update_mask
348
383
  }.delete_if { |_, v| v.nil? }
349
384
  req = Google::Gax::to_proto(req, Google::Pubsub::V1::UpdateTopicRequest)
350
- @update_topic.call(req, options)
385
+ @update_topic.call(req, options, &block)
351
386
  end
352
387
 
353
388
  # Adds one or more messages to the topic. Returns +NOT_FOUND+ if the topic
@@ -364,12 +399,15 @@ module Google
364
399
  # @param options [Google::Gax::CallOptions]
365
400
  # Overrides the default settings for this call, e.g, timeout,
366
401
  # retries, etc.
402
+ # @yield [result, operation] Access the result along with the RPC operation
403
+ # @yieldparam result [Google::Pubsub::V1::PublishResponse]
404
+ # @yieldparam operation [GRPC::ActiveCall::Operation]
367
405
  # @return [Google::Pubsub::V1::PublishResponse]
368
406
  # @raise [Google::Gax::GaxError] if the RPC is aborted.
369
407
  # @example
370
- # require "google/cloud/pubsub/v1"
408
+ # require "google/cloud/pubsub"
371
409
  #
372
- # publisher_client = Google::Cloud::Pubsub::V1::Publisher.new
410
+ # publisher_client = Google::Cloud::Pubsub::Publisher.new(version: :v1)
373
411
  # formatted_topic = Google::Cloud::Pubsub::V1::PublisherClient.topic_path("[PROJECT]", "[TOPIC]")
374
412
  # data = ''
375
413
  # messages_element = { data: data }
@@ -379,13 +417,14 @@ module Google
379
417
  def publish \
380
418
  topic,
381
419
  messages,
382
- options: nil
420
+ options: nil,
421
+ &block
383
422
  req = {
384
423
  topic: topic,
385
424
  messages: messages
386
425
  }.delete_if { |_, v| v.nil? }
387
426
  req = Google::Gax::to_proto(req, Google::Pubsub::V1::PublishRequest)
388
- @publish.call(req, options)
427
+ @publish.call(req, options, &block)
389
428
  end
390
429
 
391
430
  # Gets the configuration of a topic.
@@ -396,23 +435,27 @@ module Google
396
435
  # @param options [Google::Gax::CallOptions]
397
436
  # Overrides the default settings for this call, e.g, timeout,
398
437
  # retries, etc.
438
+ # @yield [result, operation] Access the result along with the RPC operation
439
+ # @yieldparam result [Google::Pubsub::V1::Topic]
440
+ # @yieldparam operation [GRPC::ActiveCall::Operation]
399
441
  # @return [Google::Pubsub::V1::Topic]
400
442
  # @raise [Google::Gax::GaxError] if the RPC is aborted.
401
443
  # @example
402
- # require "google/cloud/pubsub/v1"
444
+ # require "google/cloud/pubsub"
403
445
  #
404
- # publisher_client = Google::Cloud::Pubsub::V1::Publisher.new
446
+ # publisher_client = Google::Cloud::Pubsub::Publisher.new(version: :v1)
405
447
  # formatted_topic = Google::Cloud::Pubsub::V1::PublisherClient.topic_path("[PROJECT]", "[TOPIC]")
406
448
  # response = publisher_client.get_topic(formatted_topic)
407
449
 
408
450
  def get_topic \
409
451
  topic,
410
- options: nil
452
+ options: nil,
453
+ &block
411
454
  req = {
412
455
  topic: topic
413
456
  }.delete_if { |_, v| v.nil? }
414
457
  req = Google::Gax::to_proto(req, Google::Pubsub::V1::GetTopicRequest)
415
- @get_topic.call(req, options)
458
+ @get_topic.call(req, options, &block)
416
459
  end
417
460
 
418
461
  # Lists matching topics.
@@ -429,6 +472,9 @@ module Google
429
472
  # @param options [Google::Gax::CallOptions]
430
473
  # Overrides the default settings for this call, e.g, timeout,
431
474
  # retries, etc.
475
+ # @yield [result, operation] Access the result along with the RPC operation
476
+ # @yieldparam result [Google::Gax::PagedEnumerable<Google::Pubsub::V1::Topic>]
477
+ # @yieldparam operation [GRPC::ActiveCall::Operation]
432
478
  # @return [Google::Gax::PagedEnumerable<Google::Pubsub::V1::Topic>]
433
479
  # An enumerable of Google::Pubsub::V1::Topic instances.
434
480
  # See Google::Gax::PagedEnumerable documentation for other
@@ -436,9 +482,9 @@ module Google
436
482
  # object.
437
483
  # @raise [Google::Gax::GaxError] if the RPC is aborted.
438
484
  # @example
439
- # require "google/cloud/pubsub/v1"
485
+ # require "google/cloud/pubsub"
440
486
  #
441
- # publisher_client = Google::Cloud::Pubsub::V1::Publisher.new
487
+ # publisher_client = Google::Cloud::Pubsub::Publisher.new(version: :v1)
442
488
  # formatted_project = Google::Cloud::Pubsub::V1::PublisherClient.project_path("[PROJECT]")
443
489
  #
444
490
  # # Iterate over all results.
@@ -457,16 +503,17 @@ module Google
457
503
  def list_topics \
458
504
  project,
459
505
  page_size: nil,
460
- options: nil
506
+ options: nil,
507
+ &block
461
508
  req = {
462
509
  project: project,
463
510
  page_size: page_size
464
511
  }.delete_if { |_, v| v.nil? }
465
512
  req = Google::Gax::to_proto(req, Google::Pubsub::V1::ListTopicsRequest)
466
- @list_topics.call(req, options)
513
+ @list_topics.call(req, options, &block)
467
514
  end
468
515
 
469
- # Lists the name of the subscriptions for this topic.
516
+ # Lists the names of the subscriptions on this topic.
470
517
  #
471
518
  # @param topic [String]
472
519
  # The name of the topic that subscriptions are attached to.
@@ -480,6 +527,9 @@ module Google
480
527
  # @param options [Google::Gax::CallOptions]
481
528
  # Overrides the default settings for this call, e.g, timeout,
482
529
  # retries, etc.
530
+ # @yield [result, operation] Access the result along with the RPC operation
531
+ # @yieldparam result [Google::Gax::PagedEnumerable<String>]
532
+ # @yieldparam operation [GRPC::ActiveCall::Operation]
483
533
  # @return [Google::Gax::PagedEnumerable<String>]
484
534
  # An enumerable of String instances.
485
535
  # See Google::Gax::PagedEnumerable documentation for other
@@ -487,9 +537,9 @@ module Google
487
537
  # object.
488
538
  # @raise [Google::Gax::GaxError] if the RPC is aborted.
489
539
  # @example
490
- # require "google/cloud/pubsub/v1"
540
+ # require "google/cloud/pubsub"
491
541
  #
492
- # publisher_client = Google::Cloud::Pubsub::V1::Publisher.new
542
+ # publisher_client = Google::Cloud::Pubsub::Publisher.new(version: :v1)
493
543
  # formatted_topic = Google::Cloud::Pubsub::V1::PublisherClient.topic_path("[PROJECT]", "[TOPIC]")
494
544
  #
495
545
  # # Iterate over all results.
@@ -508,13 +558,14 @@ module Google
508
558
  def list_topic_subscriptions \
509
559
  topic,
510
560
  page_size: nil,
511
- options: nil
561
+ options: nil,
562
+ &block
512
563
  req = {
513
564
  topic: topic,
514
565
  page_size: page_size
515
566
  }.delete_if { |_, v| v.nil? }
516
567
  req = Google::Gax::to_proto(req, Google::Pubsub::V1::ListTopicSubscriptionsRequest)
517
- @list_topic_subscriptions.call(req, options)
568
+ @list_topic_subscriptions.call(req, options, &block)
518
569
  end
519
570
 
520
571
  # Deletes the topic with the given name. Returns +NOT_FOUND+ if the topic
@@ -529,22 +580,26 @@ module Google
529
580
  # @param options [Google::Gax::CallOptions]
530
581
  # Overrides the default settings for this call, e.g, timeout,
531
582
  # retries, etc.
583
+ # @yield [result, operation] Access the result along with the RPC operation
584
+ # @yieldparam result []
585
+ # @yieldparam operation [GRPC::ActiveCall::Operation]
532
586
  # @raise [Google::Gax::GaxError] if the RPC is aborted.
533
587
  # @example
534
- # require "google/cloud/pubsub/v1"
588
+ # require "google/cloud/pubsub"
535
589
  #
536
- # publisher_client = Google::Cloud::Pubsub::V1::Publisher.new
590
+ # publisher_client = Google::Cloud::Pubsub::Publisher.new(version: :v1)
537
591
  # formatted_topic = Google::Cloud::Pubsub::V1::PublisherClient.topic_path("[PROJECT]", "[TOPIC]")
538
592
  # publisher_client.delete_topic(formatted_topic)
539
593
 
540
594
  def delete_topic \
541
595
  topic,
542
- options: nil
596
+ options: nil,
597
+ &block
543
598
  req = {
544
599
  topic: topic
545
600
  }.delete_if { |_, v| v.nil? }
546
601
  req = Google::Gax::to_proto(req, Google::Pubsub::V1::DeleteTopicRequest)
547
- @delete_topic.call(req, options)
602
+ @delete_topic.call(req, options, &block)
548
603
  nil
549
604
  end
550
605
 
@@ -565,26 +620,32 @@ module Google
565
620
  # @param options [Google::Gax::CallOptions]
566
621
  # Overrides the default settings for this call, e.g, timeout,
567
622
  # retries, etc.
623
+ # @yield [result, operation] Access the result along with the RPC operation
624
+ # @yieldparam result [Google::Iam::V1::Policy]
625
+ # @yieldparam operation [GRPC::ActiveCall::Operation]
568
626
  # @return [Google::Iam::V1::Policy]
569
627
  # @raise [Google::Gax::GaxError] if the RPC is aborted.
570
628
  # @example
571
- # require "google/cloud/pubsub/v1"
629
+ # require "google/cloud/pubsub"
572
630
  #
573
- # publisher_client = Google::Cloud::Pubsub::V1::Publisher.new
631
+ # publisher_client = Google::Cloud::Pubsub::Publisher.new(version: :v1)
574
632
  # formatted_resource = Google::Cloud::Pubsub::V1::PublisherClient.topic_path("[PROJECT]", "[TOPIC]")
633
+ #
634
+ # # TODO: Initialize +policy+:
575
635
  # policy = {}
576
636
  # response = publisher_client.set_iam_policy(formatted_resource, policy)
577
637
 
578
638
  def set_iam_policy \
579
639
  resource,
580
640
  policy,
581
- options: nil
641
+ options: nil,
642
+ &block
582
643
  req = {
583
644
  resource: resource,
584
645
  policy: policy
585
646
  }.delete_if { |_, v| v.nil? }
586
647
  req = Google::Gax::to_proto(req, Google::Iam::V1::SetIamPolicyRequest)
587
- @set_iam_policy.call(req, options)
648
+ @set_iam_policy.call(req, options, &block)
588
649
  end
589
650
 
590
651
  # Gets the access control policy for a resource.
@@ -598,23 +659,27 @@ module Google
598
659
  # @param options [Google::Gax::CallOptions]
599
660
  # Overrides the default settings for this call, e.g, timeout,
600
661
  # retries, etc.
662
+ # @yield [result, operation] Access the result along with the RPC operation
663
+ # @yieldparam result [Google::Iam::V1::Policy]
664
+ # @yieldparam operation [GRPC::ActiveCall::Operation]
601
665
  # @return [Google::Iam::V1::Policy]
602
666
  # @raise [Google::Gax::GaxError] if the RPC is aborted.
603
667
  # @example
604
- # require "google/cloud/pubsub/v1"
668
+ # require "google/cloud/pubsub"
605
669
  #
606
- # publisher_client = Google::Cloud::Pubsub::V1::Publisher.new
670
+ # publisher_client = Google::Cloud::Pubsub::Publisher.new(version: :v1)
607
671
  # formatted_resource = Google::Cloud::Pubsub::V1::PublisherClient.topic_path("[PROJECT]", "[TOPIC]")
608
672
  # response = publisher_client.get_iam_policy(formatted_resource)
609
673
 
610
674
  def get_iam_policy \
611
675
  resource,
612
- options: nil
676
+ options: nil,
677
+ &block
613
678
  req = {
614
679
  resource: resource
615
680
  }.delete_if { |_, v| v.nil? }
616
681
  req = Google::Gax::to_proto(req, Google::Iam::V1::GetIamPolicyRequest)
617
- @get_iam_policy.call(req, options)
682
+ @get_iam_policy.call(req, options, &block)
618
683
  end
619
684
 
620
685
  # Returns permissions that a caller has on the specified resource.
@@ -633,26 +698,32 @@ module Google
633
698
  # @param options [Google::Gax::CallOptions]
634
699
  # Overrides the default settings for this call, e.g, timeout,
635
700
  # retries, etc.
701
+ # @yield [result, operation] Access the result along with the RPC operation
702
+ # @yieldparam result [Google::Iam::V1::TestIamPermissionsResponse]
703
+ # @yieldparam operation [GRPC::ActiveCall::Operation]
636
704
  # @return [Google::Iam::V1::TestIamPermissionsResponse]
637
705
  # @raise [Google::Gax::GaxError] if the RPC is aborted.
638
706
  # @example
639
- # require "google/cloud/pubsub/v1"
707
+ # require "google/cloud/pubsub"
640
708
  #
641
- # publisher_client = Google::Cloud::Pubsub::V1::Publisher.new
709
+ # publisher_client = Google::Cloud::Pubsub::Publisher.new(version: :v1)
642
710
  # formatted_resource = Google::Cloud::Pubsub::V1::PublisherClient.topic_path("[PROJECT]", "[TOPIC]")
711
+ #
712
+ # # TODO: Initialize +permissions+:
643
713
  # permissions = []
644
714
  # response = publisher_client.test_iam_permissions(formatted_resource, permissions)
645
715
 
646
716
  def test_iam_permissions \
647
717
  resource,
648
718
  permissions,
649
- options: nil
719
+ options: nil,
720
+ &block
650
721
  req = {
651
722
  resource: resource,
652
723
  permissions: permissions
653
724
  }.delete_if { |_, v| v.nil? }
654
725
  req = Google::Gax::to_proto(req, Google::Iam::V1::TestIamPermissionsRequest)
655
- @test_iam_permissions.call(req, options)
726
+ @test_iam_permissions.call(req, options, &block)
656
727
  end
657
728
  end
658
729
  end