google-cloud-pubsub 1.10.0 → 2.1.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (36) hide show
  1. checksums.yaml +4 -4
  2. data/AUTHENTICATION.md +2 -1
  3. data/CHANGELOG.md +41 -0
  4. data/OVERVIEW.md +26 -58
  5. data/lib/google-cloud-pubsub.rb +14 -13
  6. data/lib/google/cloud/pubsub.rb +15 -18
  7. data/lib/google/cloud/pubsub/async_publisher.rb +2 -3
  8. data/lib/google/cloud/pubsub/credentials.rb +2 -2
  9. data/lib/google/cloud/pubsub/message.rb +1 -1
  10. data/lib/google/cloud/pubsub/project.rb +1 -1
  11. data/lib/google/cloud/pubsub/received_message.rb +4 -4
  12. data/lib/google/cloud/pubsub/service.rb +102 -256
  13. data/lib/google/cloud/pubsub/subscriber.rb +3 -3
  14. data/lib/google/cloud/pubsub/subscriber/stream.rb +1 -2
  15. data/lib/google/cloud/pubsub/subscription.rb +19 -10
  16. data/lib/google/cloud/pubsub/subscription/push_config.rb +55 -31
  17. data/lib/google/cloud/pubsub/topic.rb +49 -15
  18. data/lib/google/cloud/pubsub/version.rb +1 -1
  19. metadata +8 -79
  20. data/lib/google/cloud/pubsub/v1.rb +0 -17
  21. data/lib/google/cloud/pubsub/v1/credentials.rb +0 -41
  22. data/lib/google/cloud/pubsub/v1/doc/google/iam/v1/iam_policy.rb +0 -21
  23. data/lib/google/cloud/pubsub/v1/doc/google/iam/v1/options.rb +0 -21
  24. data/lib/google/cloud/pubsub/v1/doc/google/iam/v1/policy.rb +0 -21
  25. data/lib/google/cloud/pubsub/v1/doc/google/protobuf/duration.rb +0 -91
  26. data/lib/google/cloud/pubsub/v1/doc/google/protobuf/empty.rb +0 -29
  27. data/lib/google/cloud/pubsub/v1/doc/google/protobuf/field_mask.rb +0 -222
  28. data/lib/google/cloud/pubsub/v1/doc/google/protobuf/timestamp.rb +0 -113
  29. data/lib/google/cloud/pubsub/v1/doc/google/pubsub/v1/pubsub.rb +0 -833
  30. data/lib/google/cloud/pubsub/v1/doc/google/type/expr.rb +0 -19
  31. data/lib/google/cloud/pubsub/v1/publisher_client.rb +0 -928
  32. data/lib/google/cloud/pubsub/v1/publisher_client_config.json +0 -120
  33. data/lib/google/cloud/pubsub/v1/subscriber_client.rb +0 -1466
  34. data/lib/google/cloud/pubsub/v1/subscriber_client_config.json +0 -153
  35. data/lib/google/pubsub/v1/pubsub_pb.rb +0 -269
  36. data/lib/google/pubsub/v1/pubsub_services_pb.rb +0 -215
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 43ee60087a74bfc9938a61cf66f67b937f30c440f921ef83294f5dd2ec8e1079
4
- data.tar.gz: 9104bacc161434e7edc1b5553cb0d2f2681ddd6a6a000bf947e212af7dad4df0
3
+ metadata.gz: 450987f2e0c301c5b43af3211dda2c6698dfa76a29076c47dc9a9690698fa9df
4
+ data.tar.gz: 84f19d7d3aacaa290e7364558ebd29795f3fce76783254df8d2df43b653e02f8
5
5
  SHA512:
6
- metadata.gz: 4130c4d2961f54b8cf6f1a5957f50d50e37d57bcd56d032df3bbc10497e8788d55e405c69b8570cc24322800af37a35e49daf67755b1652b763b5a9da44b464e
7
- data.tar.gz: 5777e0c8d1ca9d56c2a94056971b1e59ccf63e3a1e6dd532f5d223f7a6b8a80f0f0aa29bf1aa984376b48d279bccc3e23aa4ff50940c47b4920c47a6340e5975
6
+ metadata.gz: 7b10cd6edeb5cf4d352028f58a233eb8f56f4de079ed4f2b344cb930750efe16758c736bb160635a8e019083ddf04fe01255175f18467d35a46966e9d1c19787
7
+ data.tar.gz: b67f8da4a9c0b73fa065a9364773dbaaa2682d993163f9bac62fab849b00178aaeab258cc0d4962e74106535be540ec2e42cfb6b888d973b4b97c06efb217f32
@@ -76,7 +76,8 @@ The environment variables that google-cloud-pubsub checks for project ID are:
76
76
  1. `PUBSUB_PROJECT`
77
77
  2. `GOOGLE_CLOUD_PROJECT`
78
78
 
79
- The environment variables that google-cloud-pubsub checks for credentials are configured on {Google::Cloud::PubSub::V1::Credentials}:
79
+ The environment variables that google-cloud-pubsub checks for credentials
80
+ are configured on {Google::Cloud::PubSub::Credentials}:
80
81
 
81
82
  1. `PUBSUB_CREDENTIALS` - Path to JSON file, or JSON contents
82
83
  2. `PUBSUB_KEYFILE` - Path to JSON file, or JSON contents
@@ -1,5 +1,46 @@
1
1
  # Release History
2
2
 
3
+ ### 2.1.1 / 2020-10-26
4
+
5
+ #### Documentation
6
+
7
+ * Update deprecated attribute name limit to max_outstanding_messages
8
+
9
+ ### 2.1.0 / 2020-09-17
10
+
11
+ #### Features
12
+
13
+ * quota_project can be set via library configuration ([#7630](https://www.github.com/googleapis/google-cloud-ruby/issues/7630))
14
+ * Add push_config (PushConfig) param to Topic#subscribe
15
+ * Make PushConfig constructor public.
16
+
17
+ #### Documentation
18
+
19
+ * Update sample code for on_error, at_exit, and concurrency tuning
20
+
21
+ ### 2.0.0 / 2020-08-06
22
+
23
+ This is a major update that removes the "low-level" client interface code, and
24
+ instead adds the new `google-cloud-pubsub-v1` gem as a dependency.
25
+ The new dependency is a rewritten low-level client, produced by a next-
26
+ generation client code generator, with improved performance and stability.
27
+
28
+ This change should have no effect on the high-level interface that most users
29
+ will use. The one exception is that the (mostly undocumented) `client_config`
30
+ argument, for adjusting low-level parameters such as RPC retry settings on
31
+ client objects, has been removed. If you need to adjust these parameters, use
32
+ the configuration interface in `google-cloud-pubsub-v1`.
33
+
34
+ Substantial changes have been made in the low-level interfaces, however. If you
35
+ are using the low-level classes under the `Google::Cloud::PubSub::V1` module,
36
+ please review the docs for the new `google-cloud-pubsub-v1` gem. In
37
+ particular:
38
+
39
+ * Some classes have been renamed, notably the client classes themselves.
40
+ * The client constructor takes a configuration block instead of configuration
41
+ keyword arguments.
42
+ * All RPC method arguments are now keyword arguments.
43
+
3
44
  ### 1.10.0 / 2020-07-23
4
45
 
5
46
  #### Features
@@ -142,7 +142,7 @@ topic.publish_async "task completed" do |result|
142
142
  end
143
143
  end
144
144
 
145
- topic.async_publisher.stop.wait!
145
+ topic.async_publisher.stop!
146
146
  ```
147
147
 
148
148
  Or multiple messages can be published in batches at the same time by passing a
@@ -174,16 +174,32 @@ pubsub = Google::Cloud::PubSub.new
174
174
 
175
175
  sub = pubsub.subscription "my-topic-sub"
176
176
 
177
- subscriber = sub.listen do |received_message|
177
+ # Create a subscriber to listen for available messages.
178
+ # By default, this block will be called on 8 concurrent threads
179
+ # but this can be tuned with the `threads` option.
180
+ # The `streams` and `inventory` parameters allow further tuning.
181
+ subscriber = sub.listen threads: { callback: 16 } do |received_message|
178
182
  # process message
183
+ puts "Data: #{received_message.message.data}, published at #{received_message.message.published_at}"
179
184
  received_message.acknowledge!
180
185
  end
181
186
 
187
+ # Handle exceptions from listener
188
+ subscriber.on_error do |exception|
189
+ puts "Exception: #{exception.class} #{exception.message}"
190
+ end
191
+
192
+ # Gracefully shut down the subscriber on program exit, blocking until
193
+ # all received messages have been processed or 10 seconds have passed
194
+ at_exit do
195
+ subscriber.stop!(10)
196
+ end
197
+
182
198
  # Start background threads that will call the block passed to listen.
183
199
  subscriber.start
184
200
 
185
- # Shut down the subscriber when ready to stop receiving messages.
186
- subscriber.stop.wait!
201
+ # Block, letting processing threads continue in the background
202
+ sleep
187
203
  ```
188
204
 
189
205
  Messages also can be pulled directly in a one-time operation. (See
@@ -235,7 +251,7 @@ end
235
251
  subscriber.start
236
252
 
237
253
  # Shut down the subscriber when ready to stop receiving messages.
238
- subscriber.stop.wait!
254
+ subscriber.stop!
239
255
  ```
240
256
 
241
257
  Or, multiple messages can be acknowledged in a single API call: (See
@@ -277,7 +293,7 @@ end
277
293
  subscriber.start
278
294
 
279
295
  # Shut down the subscriber when ready to stop receiving messages.
280
- subscriber.stop.wait!
296
+ subscriber.stop!
281
297
  ```
282
298
 
283
299
  The message can also be made available for immediate redelivery:
@@ -299,7 +315,7 @@ end
299
315
  subscriber.start
300
316
 
301
317
  # Shut down the subscriber when ready to stop receiving messages.
302
- subscriber.stop.wait!
318
+ subscriber.stop!
303
319
  ```
304
320
 
305
321
  Multiple messages can be delayed or made available for immediate redelivery:
@@ -353,7 +369,7 @@ topic.publish_async "task completed",
353
369
  ordering_key: "task-key"
354
370
 
355
371
  # Shut down the publisher when ready to stop publishing messages.
356
- topic.async_publisher.stop.wait!
372
+ topic.async_publisher.stop!
357
373
  ```
358
374
 
359
375
  ### Handling errors with Ordered Keys
@@ -395,7 +411,7 @@ end
395
411
  subscriber.start
396
412
 
397
413
  # Shut down the subscriber when ready to stop receiving messages.
398
- subscriber.stop.wait!
414
+ subscriber.stop!
399
415
  ```
400
416
 
401
417
  ## Minimizing API calls before receiving and acknowledging messages
@@ -425,7 +441,7 @@ end
425
441
  subscriber.start
426
442
 
427
443
  # Shut down the subscriber when ready to stop receiving messages.
428
- subscriber.stop.wait!
444
+ subscriber.stop!
429
445
  ```
430
446
 
431
447
  Skipping API calls may be used to avoid `Google::Cloud::PermissionDeniedError`
@@ -464,54 +480,6 @@ sub.acknowledge received_messages
464
480
  sub.seek snapshot
465
481
  ```
466
482
 
467
- ## Listening for Messages
468
-
469
- A subscriber object can be created using `listen`, which streams messages from
470
- the backend and processes them as they are received. (See
471
- {Google::Cloud::PubSub::Subscription#listen Subscription#listen} and
472
- {Google::Cloud::PubSub::Subscriber Subscriber})
473
-
474
- ```ruby
475
- require "google/cloud/pubsub"
476
-
477
- pubsub = Google::Cloud::PubSub.new
478
-
479
- sub = pubsub.subscription "my-topic-sub"
480
-
481
- subscriber = sub.listen do |received_message|
482
- # process message
483
- received_message.acknowledge!
484
- end
485
-
486
- # Start background threads that will call the block passed to listen.
487
- subscriber.start
488
-
489
- # Shut down the subscriber when ready to stop receiving messages.
490
- subscriber.stop.wait!
491
- ```
492
-
493
- The subscriber object can be configured to control the number of concurrent
494
- streams to open, the number of received messages to be collected, and the number
495
- of threads each stream opens for concurrent calls made to handle the received
496
- messages.
497
-
498
- ```ruby
499
- require "google/cloud/pubsub"
500
-
501
- pubsub = Google::Cloud::PubSub.new
502
-
503
- sub = pubsub.subscription "my-topic-sub"
504
-
505
- subscriber = sub.listen threads: { callback: 16 } do |received_message|
506
- # store the message somewhere before acknowledging
507
- store_in_backend received_message.data # takes a few seconds
508
- received_message.acknowledge!
509
- end
510
-
511
- # Start background threads that will call the block passed to listen.
512
- subscriber.start
513
- ```
514
-
515
483
  ## Working Across Projects
516
484
 
517
485
  All calls to the Pub/Sub service use the same project and credentials provided
@@ -42,8 +42,6 @@ module Google
42
42
  #
43
43
  # * `https://www.googleapis.com/auth/pubsub`
44
44
  # @param [Integer] timeout Default timeout to use in requests. Optional.
45
- # @param [Hash] client_config A hash of values to override the default
46
- # behavior of the API client. Optional.
47
45
  #
48
46
  # @return [Google::Cloud::PubSub::Project]
49
47
  #
@@ -62,9 +60,9 @@ module Google
62
60
  # platform_scope = "https://www.googleapis.com/auth/cloud-platform"
63
61
  # pubsub = gcloud.pubsub scope: platform_scope
64
62
  #
65
- def pubsub scope: nil, timeout: nil, client_config: nil
63
+ def pubsub scope: nil, timeout: nil
66
64
  timeout ||= @timeout
67
- Google::Cloud.pubsub @project, @keyfile, scope: scope, timeout: timeout, client_config: client_config
65
+ Google::Cloud.pubsub @project, @keyfile, scope: scope, timeout: timeout
68
66
  end
69
67
 
70
68
  ##
@@ -90,8 +88,6 @@ module Google
90
88
  #
91
89
  # * `https://www.googleapis.com/auth/pubsub`
92
90
  # @param [Integer] timeout Default timeout to use in requests. Optional.
93
- # @param [Hash] client_config A hash of values to override the default
94
- # behavior of the API client. Optional.
95
91
  #
96
92
  # @return [Google::Cloud::PubSub::Project]
97
93
  #
@@ -103,11 +99,12 @@ module Google
103
99
  # topic = pubsub.topic "my-topic"
104
100
  # topic.publish "task completed"
105
101
  #
106
- def self.pubsub project_id = nil, credentials = nil, scope: nil,
107
- timeout: nil, client_config: nil
102
+ def self.pubsub project_id = nil,
103
+ credentials = nil,
104
+ scope: nil,
105
+ timeout: nil
108
106
  require "google/cloud/pubsub"
109
- Google::Cloud::PubSub.new project_id: project_id, credentials: credentials,
110
- scope: scope, timeout: timeout, client_config: client_config
107
+ Google::Cloud::PubSub.new project_id: project_id, credentials: credentials, scope: scope, timeout: timeout
111
108
  end
112
109
  end
113
110
  end
@@ -125,15 +122,19 @@ Google::Cloud.configure.add_config! :pubsub do |config|
125
122
  default_emulator = Google::Cloud::Config.deferred do
126
123
  ENV["PUBSUB_EMULATOR_HOST"]
127
124
  end
125
+ default_scopes = [
126
+ "https://www.googleapis.com/auth/cloud-platform",
127
+ "https://www.googleapis.com/auth/pubsub"
128
+ ]
128
129
 
129
130
  config.add_field! :project_id, default_project, match: String, allow_nil: true
130
131
  config.add_alias! :project, :project_id
131
132
  config.add_field! :credentials, default_creds, match: [String, Hash, Google::Auth::Credentials], allow_nil: true
132
133
  config.add_alias! :keyfile, :credentials
133
- config.add_field! :scope, nil, match: [String, Array]
134
+ config.add_field! :scope, default_scopes, match: [String, Array]
135
+ config.add_field! :quota_project, nil, match: String
134
136
  config.add_field! :timeout, nil, match: Integer
135
- config.add_field! :client_config, nil, match: Hash
136
137
  config.add_field! :emulator_host, default_emulator, match: String, allow_nil: true
137
138
  config.add_field! :on_error, nil, match: Proc
138
- config.add_field! :endpoint, nil, match: String
139
+ config.add_field! :endpoint, "pubsub.googleapis.com", match: String
139
140
  end
@@ -57,8 +57,6 @@ module Google
57
57
  #
58
58
  # * `https://www.googleapis.com/auth/pubsub`
59
59
  # @param [Integer] timeout Default timeout to use in requests. Optional.
60
- # @param [Hash] client_config A hash of values to override the default
61
- # behavior of the API client. Optional.
62
60
  # @param [String] endpoint Override of the endpoint host name. Optional.
63
61
  # If the param is nil, uses the default endpoint.
64
62
  # @param [String] emulator_host Pub/Sub emulator host. Optional.
@@ -77,12 +75,17 @@ module Google
77
75
  # topic = pubsub.topic "my-topic"
78
76
  # topic.publish "task completed"
79
77
  #
80
- def self.new project_id: nil, credentials: nil, scope: nil, timeout: nil, client_config: nil, endpoint: nil,
81
- emulator_host: nil, project: nil, keyfile: nil
78
+ def self.new project_id: nil,
79
+ credentials: nil,
80
+ scope: nil,
81
+ timeout: nil,
82
+ endpoint: nil,
83
+ emulator_host: nil,
84
+ project: nil,
85
+ keyfile: nil
82
86
  project_id ||= (project || default_project_id)
83
87
  scope ||= configure.scope
84
88
  timeout ||= configure.timeout
85
- client_config ||= configure.client_config
86
89
  endpoint ||= configure.endpoint
87
90
  emulator_host ||= configure.emulator_host
88
91
 
@@ -90,11 +93,8 @@ module Google
90
93
  project_id = project_id.to_s # Always cast to a string
91
94
  raise ArgumentError, "project_id is missing" if project_id.empty?
92
95
 
93
- return PubSub::Project.new(
94
- PubSub::Service.new(
95
- project_id, :this_channel_is_insecure, host: emulator_host, timeout: timeout, client_config: client_config
96
- )
97
- )
96
+ service = PubSub::Service.new project_id, :this_channel_is_insecure, host: emulator_host, timeout: timeout
97
+ return PubSub::Project.new service
98
98
  end
99
99
 
100
100
  credentials ||= (keyfile || default_credentials(scope: scope))
@@ -106,11 +106,8 @@ module Google
106
106
  project_id = project_id.to_s # Always cast to a string
107
107
  raise ArgumentError, "project_id is missing" if project_id.empty?
108
108
 
109
- PubSub::Project.new(
110
- PubSub::Service.new(
111
- project_id, credentials, timeout: timeout, host: endpoint, client_config: client_config
112
- )
113
- )
109
+ service = PubSub::Service.new project_id, credentials, host: endpoint, timeout: timeout
110
+ PubSub::Project.new service
114
111
  end
115
112
 
116
113
  # rubocop:enable Metrics/AbcSize
@@ -131,8 +128,6 @@ module Google
131
128
  # * `retries` - (Integer) Number of times to retry requests on server
132
129
  # error.
133
130
  # * `timeout` - (Integer) Default timeout to use in requests.
134
- # * `client_config` - (Hash) A hash of values to override the default
135
- # behavior of the API client.
136
131
  # * `endpoint` - (String) Override of the endpoint host name, or `nil`
137
132
  # to use the default endpoint.
138
133
  # * `emulator_host` - (String) Host name of the emulator. Defaults to
@@ -167,7 +162,9 @@ module Google
167
162
  end
168
163
  end
169
164
 
170
- ## Legacy namespace
165
+ ## Legacy veneer namespace
171
166
  Pubsub = PubSub unless const_defined? :Pubsub
172
167
  end
168
+ ## Legacy generated client namespace
169
+ Pubsub = Cloud::PubSub unless const_defined? :Pubsub
173
170
  end
@@ -42,7 +42,7 @@ module Google
42
42
  # end
43
43
  # end
44
44
  #
45
- # topic.async_publisher.stop.wait!
45
+ # topic.async_publisher.stop!
46
46
  #
47
47
  # @attr_reader [String] topic_name The name of the topic the messages are published to. In the form of
48
48
  # "/projects/project-identifier/topics/topic-name".
@@ -374,8 +374,7 @@ module Google
374
374
 
375
375
  PUBLISH_RETRY_ERRORS = [
376
376
  GRPC::Cancelled, GRPC::DeadlineExceeded, GRPC::Internal,
377
- GRPC::ResourceExhausted, GRPC::Unauthenticated, GRPC::Unavailable,
378
- GRPC::Core::CallError
377
+ GRPC::ResourceExhausted, GRPC::Unauthenticated, GRPC::Unavailable
379
378
  ].freeze
380
379
 
381
380
  def publish_batch_error_retryable? error
@@ -14,7 +14,7 @@
14
14
 
15
15
 
16
16
  require "googleauth"
17
- require "google/cloud/pubsub/v1/credentials.rb"
17
+ require "google/cloud/pubsub/v1/publisher/credentials.rb"
18
18
 
19
19
  module Google
20
20
  module Cloud
@@ -38,7 +38,7 @@ module Google
38
38
  #
39
39
  # pubsub.project_id #=> "my-project"
40
40
  #
41
- class Credentials < Google::Cloud::PubSub::V1::Credentials
41
+ class Credentials < Google::Cloud::PubSub::V1::Publisher::Credentials
42
42
  end
43
43
  end
44
44
 
@@ -50,7 +50,7 @@ module Google
50
50
  # subscriber.start
51
51
  #
52
52
  # # Shut down the subscriber when ready to stop receiving messages.
53
- # subscriber.stop.wait!
53
+ # subscriber.stop!
54
54
  #
55
55
  class Message
56
56
  ##
@@ -141,7 +141,7 @@ module Google
141
141
  # end
142
142
  # end
143
143
  #
144
- # topic.async_publisher.stop.wait!
144
+ # topic.async_publisher.stop!
145
145
  #
146
146
  def topic topic_name, project: nil, skip_lookup: nil, async: nil
147
147
  ensure_service!
@@ -39,7 +39,7 @@ module Google
39
39
  # subscriber.start
40
40
  #
41
41
  # # Shut down the subscriber when ready to stop receiving messages.
42
- # subscriber.stop.wait!
42
+ # subscriber.stop!
43
43
  #
44
44
  class ReceivedMessage
45
45
  ##
@@ -177,7 +177,7 @@ module Google
177
177
  # subscriber.start
178
178
  #
179
179
  # # Shut down the subscriber when ready to stop receiving messages.
180
- # subscriber.stop.wait!
180
+ # subscriber.stop!
181
181
  #
182
182
  def acknowledge!
183
183
  ensure_subscription!
@@ -214,7 +214,7 @@ module Google
214
214
  # subscriber.start
215
215
  #
216
216
  # # Shut down the subscriber when ready to stop receiving messages.
217
- # subscriber.stop.wait!
217
+ # subscriber.stop!
218
218
  #
219
219
  def modify_ack_deadline! new_deadline
220
220
  ensure_subscription!
@@ -244,7 +244,7 @@ module Google
244
244
  # subscriber.start
245
245
  #
246
246
  # # Shut down the subscriber when ready to stop receiving messages.
247
- # subscriber.stop.wait!
247
+ # subscriber.stop!
248
248
  #
249
249
  def reject!
250
250
  modify_ack_deadline! 0