google-cloud-pubsub 1.8.0 → 2.1.1
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.
- checksums.yaml +4 -4
- data/AUTHENTICATION.md +2 -1
- data/CHANGELOG.md +53 -0
- data/OVERVIEW.md +26 -58
- data/lib/google-cloud-pubsub.rb +14 -13
- data/lib/google/cloud/pubsub.rb +15 -18
- data/lib/google/cloud/pubsub/async_publisher.rb +2 -3
- data/lib/google/cloud/pubsub/credentials.rb +2 -2
- data/lib/google/cloud/pubsub/message.rb +1 -1
- data/lib/google/cloud/pubsub/project.rb +1 -1
- data/lib/google/cloud/pubsub/received_message.rb +4 -4
- data/lib/google/cloud/pubsub/service.rb +110 -257
- data/lib/google/cloud/pubsub/subscriber.rb +3 -3
- data/lib/google/cloud/pubsub/subscriber/stream.rb +3 -2
- data/lib/google/cloud/pubsub/subscription.rb +76 -12
- data/lib/google/cloud/pubsub/subscription/push_config.rb +55 -31
- data/lib/google/cloud/pubsub/topic.rb +50 -15
- data/lib/google/cloud/pubsub/version.rb +1 -1
- metadata +8 -79
- data/lib/google/cloud/pubsub/v1.rb +0 -17
- data/lib/google/cloud/pubsub/v1/credentials.rb +0 -41
- data/lib/google/cloud/pubsub/v1/doc/google/iam/v1/iam_policy.rb +0 -21
- data/lib/google/cloud/pubsub/v1/doc/google/iam/v1/options.rb +0 -21
- data/lib/google/cloud/pubsub/v1/doc/google/iam/v1/policy.rb +0 -21
- data/lib/google/cloud/pubsub/v1/doc/google/protobuf/duration.rb +0 -91
- data/lib/google/cloud/pubsub/v1/doc/google/protobuf/empty.rb +0 -29
- data/lib/google/cloud/pubsub/v1/doc/google/protobuf/field_mask.rb +0 -222
- data/lib/google/cloud/pubsub/v1/doc/google/protobuf/timestamp.rb +0 -113
- data/lib/google/cloud/pubsub/v1/doc/google/pubsub/v1/pubsub.rb +0 -833
- data/lib/google/cloud/pubsub/v1/doc/google/type/expr.rb +0 -19
- data/lib/google/cloud/pubsub/v1/publisher_client.rb +0 -928
- data/lib/google/cloud/pubsub/v1/publisher_client_config.json +0 -120
- data/lib/google/cloud/pubsub/v1/subscriber_client.rb +0 -1466
- data/lib/google/cloud/pubsub/v1/subscriber_client_config.json +0 -153
- data/lib/google/pubsub/v1/pubsub_pb.rb +0 -269
- data/lib/google/pubsub/v1/pubsub_services_pb.rb +0 -215
@@ -41,7 +41,7 @@ module Google
|
|
41
41
|
# subscriber.start
|
42
42
|
#
|
43
43
|
# # Shut down the subscriber when ready to stop receiving messages.
|
44
|
-
# subscriber.stop
|
44
|
+
# subscriber.stop!
|
45
45
|
#
|
46
46
|
# @attr_reader [String] subscription_name The name of the subscription the
|
47
47
|
# messages are pulled from.
|
@@ -240,7 +240,7 @@ module Google
|
|
240
240
|
# subscriber.start
|
241
241
|
#
|
242
242
|
# # Shut down the subscriber when ready to stop receiving messages.
|
243
|
-
# subscriber.stop
|
243
|
+
# subscriber.stop!
|
244
244
|
#
|
245
245
|
def on_error &block
|
246
246
|
synchronize do
|
@@ -276,7 +276,7 @@ module Google
|
|
276
276
|
# subscriber.last_error #=> nil
|
277
277
|
#
|
278
278
|
# # Shut down the subscriber when ready to stop receiving messages.
|
279
|
-
# subscriber.stop
|
279
|
+
# subscriber.stop!
|
280
280
|
#
|
281
281
|
def last_error
|
282
282
|
synchronize { @last_error }
|
@@ -271,9 +271,8 @@ module Google
|
|
271
271
|
stop
|
272
272
|
rescue GRPC::Cancelled, GRPC::DeadlineExceeded, GRPC::Internal,
|
273
273
|
GRPC::ResourceExhausted, GRPC::Unauthenticated,
|
274
|
-
GRPC::Unavailable
|
274
|
+
GRPC::Unavailable
|
275
275
|
# Restart the stream with an incremental back for a retriable error.
|
276
|
-
# Also when GRPC raises the internal CallError.
|
277
276
|
|
278
277
|
retry
|
279
278
|
rescue RestartStream
|
@@ -364,6 +363,8 @@ module Google
|
|
364
363
|
req.modify_deadline_ack_ids += @inventory.ack_ids
|
365
364
|
req.modify_deadline_seconds += @inventory.ack_ids.map { @subscriber.deadline }
|
366
365
|
req.client_id = @subscriber.service.client_id
|
366
|
+
req.max_outstanding_messages = @inventory.limit
|
367
|
+
req.max_outstanding_bytes = @inventory.bytesize
|
367
368
|
end
|
368
369
|
end
|
369
370
|
|
@@ -43,12 +43,19 @@ module Google
|
|
43
43
|
# received_message.acknowledge!
|
44
44
|
# end
|
45
45
|
#
|
46
|
-
# #
|
47
|
-
# subscriber.
|
46
|
+
# # Handle exceptions from listener
|
47
|
+
# subscriber.on_error do |exception|
|
48
|
+
# puts "Exception: #{exception.class} #{exception.message}"
|
49
|
+
# end
|
48
50
|
#
|
49
|
-
# #
|
50
|
-
#
|
51
|
+
# # Gracefully shut down the subscriber
|
52
|
+
# at_exit do
|
53
|
+
# subscriber.stop!
|
54
|
+
# end
|
51
55
|
#
|
56
|
+
# # Start background threads that will call the block passed to listen.
|
57
|
+
# subscriber.start
|
58
|
+
# sleep
|
52
59
|
class Subscription
|
53
60
|
##
|
54
61
|
# @private The Service object.
|
@@ -323,7 +330,7 @@ module Google
|
|
323
330
|
# If {#expires_in=} is not set, a *default* value of of 31 days will be
|
324
331
|
# used. The minimum allowed value is 1 day.
|
325
332
|
#
|
326
|
-
# Makes an API call to retrieve the
|
333
|
+
# Makes an API call to retrieve the value when called on a
|
327
334
|
# reference object. See {#reference?}.
|
328
335
|
#
|
329
336
|
# @return [Numeric, nil] The expiration duration, or `nil` if unset.
|
@@ -346,7 +353,7 @@ module Google
|
|
346
353
|
# to unset.
|
347
354
|
#
|
348
355
|
def expires_in= ttl
|
349
|
-
new_expiration_policy = Google::
|
356
|
+
new_expiration_policy = Google::Cloud::PubSub::V1::ExpirationPolicy.new ttl: Convert.number_to_duration(ttl)
|
350
357
|
|
351
358
|
update_grpc = Google::Cloud::PubSub::V1::Subscription.new name: name, expiration_policy: new_expiration_policy
|
352
359
|
@grpc = service.update_subscription update_grpc, :expiration_policy
|
@@ -566,7 +573,7 @@ module Google
|
|
566
573
|
#
|
567
574
|
# See {Topic#publish_async}, {#listen}, and {Message#ordering_key}.
|
568
575
|
#
|
569
|
-
# Makes an API call to retrieve the
|
576
|
+
# Makes an API call to retrieve the enable_message_ordering value when called on a
|
570
577
|
# reference object. See {#reference?}.
|
571
578
|
#
|
572
579
|
# @return [Boolean]
|
@@ -576,6 +583,35 @@ module Google
|
|
576
583
|
@grpc.enable_message_ordering
|
577
584
|
end
|
578
585
|
|
586
|
+
##
|
587
|
+
# Whether the subscription is detached from its topic. Detached subscriptions don't receive messages from their
|
588
|
+
# topic and don't retain any backlog. {#pull} and {#listen} (pull and streaming pull) operations will raise
|
589
|
+
# `FAILED_PRECONDITION`. If the subscription is a push subscription (see {#push_config}), pushes to the endpoint
|
590
|
+
# will not be made. The default value is `false`.
|
591
|
+
#
|
592
|
+
# See {Topic#subscribe} and {#detach}.
|
593
|
+
#
|
594
|
+
# Makes an API call to retrieve the value when called on a
|
595
|
+
# reference object. See {#reference?}.
|
596
|
+
#
|
597
|
+
# @return [Boolean]
|
598
|
+
#
|
599
|
+
# @example
|
600
|
+
# require "google/cloud/pubsub"
|
601
|
+
#
|
602
|
+
# pubsub = Google::Cloud::PubSub.new
|
603
|
+
#
|
604
|
+
# sub = pubsub.subscription "my-topic-sub"
|
605
|
+
# sub.detach
|
606
|
+
#
|
607
|
+
# # sleep 120
|
608
|
+
# sub.detached? #=> true
|
609
|
+
#
|
610
|
+
def detached?
|
611
|
+
ensure_grpc!
|
612
|
+
@grpc.detached
|
613
|
+
end
|
614
|
+
|
579
615
|
##
|
580
616
|
# Determines whether the subscription exists in the Pub/Sub service.
|
581
617
|
#
|
@@ -623,6 +659,32 @@ module Google
|
|
623
659
|
true
|
624
660
|
end
|
625
661
|
|
662
|
+
##
|
663
|
+
# Detaches a subscription from its topic. All messages retained in the subscription are dropped. Detached
|
664
|
+
# subscriptions don't receive messages from their topic and don't retain any backlog. Subsequent {#pull} and
|
665
|
+
# {#listen} (pull and streaming pull) operations will raise `FAILED_PRECONDITION`. If the subscription is a push
|
666
|
+
# subscription (see {#push_config}), pushes to the endpoint will stop. It may take a few minutes for the
|
667
|
+
# subscription's detached state to be reflected in subsequent calls to {#detached?}.
|
668
|
+
#
|
669
|
+
# @return [Boolean] Returns `true` if the detach operation was successful.
|
670
|
+
#
|
671
|
+
# @example
|
672
|
+
# require "google/cloud/pubsub"
|
673
|
+
#
|
674
|
+
# pubsub = Google::Cloud::PubSub.new
|
675
|
+
#
|
676
|
+
# sub = pubsub.subscription "my-topic-sub"
|
677
|
+
# sub.detach
|
678
|
+
#
|
679
|
+
# # sleep 120
|
680
|
+
# sub.detached? #=> true
|
681
|
+
#
|
682
|
+
def detach
|
683
|
+
ensure_service!
|
684
|
+
service.detach_subscription name
|
685
|
+
true
|
686
|
+
end
|
687
|
+
|
626
688
|
##
|
627
689
|
# Pulls messages from the server. Returns an empty list if there are no
|
628
690
|
# messages available in the backlog. Raises an ApiError with status
|
@@ -761,7 +823,8 @@ module Google
|
|
761
823
|
# @param [Integer] streams The number of concurrent streams to open to
|
762
824
|
# pull messages from the subscription. Default is 4. Optional.
|
763
825
|
# @param [Hash, Integer] inventory The settings to control how received messages are to be handled by the
|
764
|
-
# subscriber. When provided as an Integer instead of a Hash only
|
826
|
+
# subscriber. When provided as an Integer instead of a Hash only `max_outstanding_messages` will be set.
|
827
|
+
# Optional.
|
765
828
|
#
|
766
829
|
# Hash keys and values may include the following:
|
767
830
|
#
|
@@ -801,6 +864,7 @@ module Google
|
|
801
864
|
#
|
802
865
|
# subscriber = sub.listen do |received_message|
|
803
866
|
# # process message
|
867
|
+
# puts "Data: #{received_message.message.data}, published at #{received_message.message.published_at}"
|
804
868
|
# received_message.acknowledge!
|
805
869
|
# end
|
806
870
|
#
|
@@ -808,7 +872,7 @@ module Google
|
|
808
872
|
# subscriber.start
|
809
873
|
#
|
810
874
|
# # Shut down the subscriber when ready to stop receiving messages.
|
811
|
-
# subscriber.stop
|
875
|
+
# subscriber.stop!
|
812
876
|
#
|
813
877
|
# @example Configuring to increase concurrent callbacks:
|
814
878
|
# require "google/cloud/pubsub"
|
@@ -827,7 +891,7 @@ module Google
|
|
827
891
|
# subscriber.start
|
828
892
|
#
|
829
893
|
# # Shut down the subscriber when ready to stop receiving messages.
|
830
|
-
# subscriber.stop
|
894
|
+
# subscriber.stop!
|
831
895
|
#
|
832
896
|
# @example Ordered messages are supported using ordering_key:
|
833
897
|
# require "google/cloud/pubsub"
|
@@ -847,7 +911,7 @@ module Google
|
|
847
911
|
# subscriber.start
|
848
912
|
#
|
849
913
|
# # Shut down the subscriber when ready to stop receiving messages.
|
850
|
-
# subscriber.stop
|
914
|
+
# subscriber.stop!
|
851
915
|
#
|
852
916
|
# @example Set the maximum amount of time before redelivery if the subscriber fails to extend the deadline:
|
853
917
|
# require "google/cloud/pubsub"
|
@@ -866,7 +930,7 @@ module Google
|
|
866
930
|
# subscriber.start
|
867
931
|
#
|
868
932
|
# # Shut down the subscriber when ready to stop receiving messages.
|
869
|
-
# subscriber.stop
|
933
|
+
# subscriber.stop!
|
870
934
|
#
|
871
935
|
def listen deadline: nil, message_ordering: nil, streams: nil, inventory: nil, threads: {}, &block
|
872
936
|
ensure_service!
|
@@ -22,7 +22,18 @@ module Google
|
|
22
22
|
##
|
23
23
|
# Configuration for a push delivery endpoint.
|
24
24
|
#
|
25
|
-
# @example
|
25
|
+
# @example Create a push config:
|
26
|
+
# require "google/cloud/pubsub"
|
27
|
+
#
|
28
|
+
# pubsub = Google::Cloud::PubSub.new
|
29
|
+
# topic = pubsub.topic "my-topic"
|
30
|
+
#
|
31
|
+
# push_config = Google::Cloud::PubSub::Subscription::PushConfig.new endpoint: "http://example.net/callback"
|
32
|
+
# push_config.set_oidc_token "service-account@example.net", "audience-header-value"
|
33
|
+
#
|
34
|
+
# sub = topic.subscribe "my-subscription", push_config: push_config
|
35
|
+
#
|
36
|
+
# @example Read a push config:
|
26
37
|
# require "google/cloud/pubsub"
|
27
38
|
#
|
28
39
|
# pubsub = Google::Cloud::PubSub.new
|
@@ -32,7 +43,7 @@ module Google
|
|
32
43
|
# sub.push_config.authentication.email #=> "user@example.com"
|
33
44
|
# sub.push_config.authentication.audience #=> "client-12345"
|
34
45
|
#
|
35
|
-
# @example Update
|
46
|
+
# @example Update a push config:
|
36
47
|
# require "google/cloud/pubsub"
|
37
48
|
#
|
38
49
|
# pubsub = Google::Cloud::PubSub.new
|
@@ -45,14 +56,31 @@ module Google
|
|
45
56
|
#
|
46
57
|
class PushConfig
|
47
58
|
##
|
48
|
-
#
|
49
|
-
|
59
|
+
# Creates a new push configuration.
|
60
|
+
#
|
61
|
+
# @param [String] endpoint A URL locating the endpoint to which messages should be pushed. For
|
62
|
+
# example, a Webhook endpoint might use `https://example.com/push`.
|
63
|
+
# @param [String] email The service account email to be used for generating the OIDC token.
|
64
|
+
# The caller must have the `iam.serviceAccounts.actAs` permission for the service account.
|
65
|
+
# @param [String] audience The audience to be used when generating OIDC token. The audience claim identifies
|
66
|
+
# the recipients that the JWT is intended for. The audience value is a single case-sensitive string. Having
|
67
|
+
# multiple values (array) for the audience field is not supported. More info about the OIDC JWT token
|
68
|
+
# audience here: https://tools.ietf.org/html/rfc7519#section-4.1.3 Note: if not specified, the `endpoint`
|
69
|
+
# URL will be used.
|
70
|
+
#
|
71
|
+
def initialize endpoint: nil, email: nil, audience: nil
|
50
72
|
@grpc = Google::Cloud::PubSub::V1::PushConfig.new
|
73
|
+
|
74
|
+
self.endpoint = endpoint unless endpoint.nil?
|
75
|
+
|
76
|
+
raise ArgumentError, "audience provided without email. Authentication is invalid" if audience && !email
|
77
|
+
|
78
|
+
set_oidc_token email, audience if email
|
51
79
|
end
|
52
80
|
|
53
81
|
##
|
54
|
-
# A URL locating the endpoint to which messages should be pushed. For
|
55
|
-
#
|
82
|
+
# A URL locating the endpoint to which messages should be pushed. For example, a Webhook endpoint might use
|
83
|
+
# `https://example.com/push`.
|
56
84
|
#
|
57
85
|
# @return [String]
|
58
86
|
def endpoint
|
@@ -60,9 +88,8 @@ module Google
|
|
60
88
|
end
|
61
89
|
|
62
90
|
##
|
63
|
-
# Sets the URL locating the endpoint to which messages should be
|
64
|
-
#
|
65
|
-
# `https://example.com/push`.
|
91
|
+
# Sets the URL locating the endpoint to which messages should be pushed. For example, a Webhook endpoint might
|
92
|
+
# use `https://example.com/push`.
|
66
93
|
#
|
67
94
|
# @param [String, nil] new_endpoint New URL value
|
68
95
|
def endpoint= new_endpoint
|
@@ -70,8 +97,7 @@ module Google
|
|
70
97
|
end
|
71
98
|
|
72
99
|
##
|
73
|
-
# The authentication method used by push endpoints to verify the
|
74
|
-
# source of push requests.
|
100
|
+
# The authentication method used by push endpoints to verify the source of push requests.
|
75
101
|
#
|
76
102
|
# @return [OidcToken, nil] An OIDC JWT token if specified, `nil`
|
77
103
|
# otherwise.
|
@@ -82,8 +108,7 @@ module Google
|
|
82
108
|
end
|
83
109
|
|
84
110
|
##
|
85
|
-
# Sets the authentication method used by push endpoints to verify the
|
86
|
-
# source of push requests.
|
111
|
+
# Sets the authentication method used by push endpoints to verify the source of push requests.
|
87
112
|
#
|
88
113
|
# @param [OidcToken, nil] new_auth An authentication value.
|
89
114
|
def authentication= new_auth
|
@@ -118,13 +143,12 @@ module Google
|
|
118
143
|
end
|
119
144
|
|
120
145
|
##
|
121
|
-
# The format of the pushed message. This attribute indicates the
|
122
|
-
#
|
123
|
-
#
|
124
|
-
# endpoint version is based on the version of the Pub/Sub API.
|
146
|
+
# The format of the pushed message. This attribute indicates the version of the data expected by the endpoint.
|
147
|
+
# This controls the shape of the pushed message (i.e., its fields and metadata). The endpoint version is based
|
148
|
+
# on the version of the Pub/Sub API.
|
125
149
|
#
|
126
|
-
# If not present during the Subscription creation, it will default to
|
127
|
-
#
|
150
|
+
# If not present during the Subscription creation, it will default to the version of the API used to make such
|
151
|
+
# call.
|
128
152
|
#
|
129
153
|
# The possible values for this attribute are:
|
130
154
|
#
|
@@ -182,7 +206,8 @@ module Google
|
|
182
206
|
end
|
183
207
|
|
184
208
|
##
|
185
|
-
#
|
209
|
+
# The service account email to be used for generating the OIDC token. The caller must have the
|
210
|
+
# `iam.serviceAccounts.actAs` permission for the service account.
|
186
211
|
#
|
187
212
|
# @return [String]
|
188
213
|
def email
|
@@ -190,7 +215,8 @@ module Google
|
|
190
215
|
end
|
191
216
|
|
192
217
|
##
|
193
|
-
#
|
218
|
+
# Sets the service account email to be used for generating the OIDC token. The caller must have the
|
219
|
+
# `iam.serviceAccounts.actAs` permission for the service account.
|
194
220
|
#
|
195
221
|
# @param [String] new_email New service account email value.
|
196
222
|
def email= new_email
|
@@ -198,15 +224,10 @@ module Google
|
|
198
224
|
end
|
199
225
|
|
200
226
|
##
|
201
|
-
#
|
202
|
-
#
|
203
|
-
# audience
|
204
|
-
#
|
205
|
-
# Having multiple values (array) for the audience field is not
|
206
|
-
# supported.
|
207
|
-
#
|
208
|
-
# More info about the OIDC JWT token audience here:
|
209
|
-
# https://tools.ietf.org/html/rfc7519#section-4.1.3
|
227
|
+
# The audience to be used when generating OIDC token. The audience claim identifies the recipients that
|
228
|
+
# the JWT is intended for. The audience value is a single case-sensitive string. Having multiple values
|
229
|
+
# (array) for the audience field is not supported. More info about the OIDC JWT token audience here:
|
230
|
+
# https://tools.ietf.org/html/rfc7519#section-4.1.3 Note: if not specified, the `endpoint` URL will be used.
|
210
231
|
#
|
211
232
|
# @return [String]
|
212
233
|
def audience
|
@@ -214,7 +235,10 @@ module Google
|
|
214
235
|
end
|
215
236
|
|
216
237
|
##
|
217
|
-
# Sets the audience to be used when generating OIDC token.
|
238
|
+
# Sets the audience to be used when generating OIDC token. The audience claim identifies the recipients that
|
239
|
+
# the JWT is intended for. The audience value is a single case-sensitive string. Having multiple values
|
240
|
+
# (array) for the audience field is not supported. More info about the OIDC JWT token audience here:
|
241
|
+
# https://tools.ietf.org/html/rfc7519#section-4.1.3 Note: if not specified, the `endpoint` URL will be used.
|
218
242
|
#
|
219
243
|
# @param [String] new_audience New audience value.
|
220
244
|
def audience= new_audience
|
@@ -78,7 +78,7 @@ module Google
|
|
78
78
|
# end
|
79
79
|
# end
|
80
80
|
#
|
81
|
-
# topic.async_publisher.stop
|
81
|
+
# topic.async_publisher.stop!
|
82
82
|
#
|
83
83
|
def async_publisher
|
84
84
|
@async_publisher
|
@@ -275,7 +275,10 @@ module Google
|
|
275
275
|
# 604,800 seconds (7 days) or less than 600 seconds (10 minutes).
|
276
276
|
# Default is 604,800 seconds (7 days).
|
277
277
|
# @param [String] endpoint A URL locating the endpoint to which messages
|
278
|
-
# should be pushed.
|
278
|
+
# should be pushed. The parameters `push_config` and `endpoint` should not both be provided.
|
279
|
+
# @param [Google::Cloud::PubSub::Subscription::PushConfig] push_config The configuration for a push delivery
|
280
|
+
# endpoint that should contain the endpoint, and can contain authentication data (OIDC token authentication).
|
281
|
+
# The parameters `push_config` and `endpoint` should not both be provided.
|
279
282
|
# @param [Hash] labels A hash of user-provided labels associated with
|
280
283
|
# the subscription. You can use these to organize and group your
|
281
284
|
# subscriptions. Label keys and values can be no longer than 63
|
@@ -320,15 +323,25 @@ module Google
|
|
320
323
|
# sub = topic.subscribe "my-topic-sub"
|
321
324
|
# sub.name # => "my-topic-sub"
|
322
325
|
#
|
323
|
-
# @example Wait 2 minutes for acknowledgement
|
326
|
+
# @example Wait 2 minutes for acknowledgement:
|
324
327
|
# require "google/cloud/pubsub"
|
325
328
|
#
|
326
329
|
# pubsub = Google::Cloud::PubSub.new
|
327
330
|
#
|
328
331
|
# topic = pubsub.topic "my-topic"
|
329
332
|
# sub = topic.subscribe "my-topic-sub",
|
330
|
-
# deadline: 120
|
331
|
-
#
|
333
|
+
# deadline: 120
|
334
|
+
#
|
335
|
+
# @example Configure a push endpoint:
|
336
|
+
# require "google/cloud/pubsub"
|
337
|
+
#
|
338
|
+
# pubsub = Google::Cloud::PubSub.new
|
339
|
+
# topic = pubsub.topic "my-topic"
|
340
|
+
#
|
341
|
+
# push_config = Google::Cloud::PubSub::Subscription::PushConfig.new endpoint: "http://example.net/callback"
|
342
|
+
# push_config.set_oidc_token "service-account@example.net", "audience-header-value"
|
343
|
+
#
|
344
|
+
# sub = topic.subscribe "my-subscription", push_config: push_config
|
332
345
|
#
|
333
346
|
# @example Configure a Dead Letter Queues policy:
|
334
347
|
# require "google/cloud/pubsub"
|
@@ -361,18 +374,40 @@ module Google
|
|
361
374
|
# retry_policy = Google::Cloud::PubSub::RetryPolicy.new minimum_backoff: 5, maximum_backoff: 300
|
362
375
|
# sub = topic.subscribe "my-topic-sub", retry_policy: retry_policy
|
363
376
|
#
|
364
|
-
def subscribe subscription_name,
|
365
|
-
|
366
|
-
|
377
|
+
def subscribe subscription_name,
|
378
|
+
deadline: nil,
|
379
|
+
retain_acked: false,
|
380
|
+
retention: nil,
|
381
|
+
endpoint: nil,
|
382
|
+
push_config: nil,
|
383
|
+
labels: nil,
|
384
|
+
message_ordering: nil,
|
385
|
+
filter: nil,
|
386
|
+
dead_letter_topic: nil,
|
387
|
+
dead_letter_max_delivery_attempts: nil,
|
388
|
+
retry_policy: nil
|
367
389
|
ensure_service!
|
368
|
-
|
369
|
-
|
370
|
-
|
390
|
+
if push_config && endpoint
|
391
|
+
raise ArgumentError, "endpoint and push_config were both provided. Please provide only one."
|
392
|
+
end
|
393
|
+
push_config = Google::Cloud::PubSub::Subscription::PushConfig.new endpoint: endpoint if endpoint
|
394
|
+
|
395
|
+
options = {
|
396
|
+
deadline: deadline,
|
397
|
+
retain_acked: retain_acked,
|
398
|
+
retention: retention,
|
399
|
+
labels: labels,
|
400
|
+
message_ordering: message_ordering,
|
401
|
+
filter: filter,
|
402
|
+
dead_letter_max_delivery_attempts: dead_letter_max_delivery_attempts
|
403
|
+
}
|
404
|
+
|
371
405
|
options[:dead_letter_topic_name] = dead_letter_topic.name if dead_letter_topic
|
372
406
|
if options[:dead_letter_max_delivery_attempts] && !options[:dead_letter_topic_name]
|
373
407
|
# Service error message "3:Invalid resource name given (name=)." does not identify param.
|
374
408
|
raise ArgumentError, "dead_letter_topic is required with dead_letter_max_delivery_attempts"
|
375
409
|
end
|
410
|
+
options[:push_config] = push_config.to_grpc if push_config
|
376
411
|
options[:retry_policy] = retry_policy.to_grpc if retry_policy
|
377
412
|
grpc = service.create_subscription name, subscription_name, options
|
378
413
|
Subscription.from_grpc grpc, service
|
@@ -589,7 +624,7 @@ module Google
|
|
589
624
|
# end
|
590
625
|
#
|
591
626
|
# # Shut down the publisher when ready to stop publishing messages.
|
592
|
-
# topic.async_publisher.stop
|
627
|
+
# topic.async_publisher.stop!
|
593
628
|
#
|
594
629
|
# @example A message can be published using a File object:
|
595
630
|
# require "google/cloud/pubsub"
|
@@ -601,7 +636,7 @@ module Google
|
|
601
636
|
# topic.publish_async file
|
602
637
|
#
|
603
638
|
# # Shut down the publisher when ready to stop publishing messages.
|
604
|
-
# topic.async_publisher.stop
|
639
|
+
# topic.async_publisher.stop!
|
605
640
|
#
|
606
641
|
# @example Additionally, a message can be published with attributes:
|
607
642
|
# require "google/cloud/pubsub"
|
@@ -613,7 +648,7 @@ module Google
|
|
613
648
|
# foo: :bar, this: :that
|
614
649
|
#
|
615
650
|
# # Shut down the publisher when ready to stop publishing messages.
|
616
|
-
# topic.async_publisher.stop
|
651
|
+
# topic.async_publisher.stop!
|
617
652
|
#
|
618
653
|
# @example Ordered messages are supported using ordering_key:
|
619
654
|
# require "google/cloud/pubsub"
|
@@ -630,7 +665,7 @@ module Google
|
|
630
665
|
# ordering_key: "task-key"
|
631
666
|
#
|
632
667
|
# # Shut down the publisher when ready to stop publishing messages.
|
633
|
-
# topic.async_publisher.stop
|
668
|
+
# topic.async_publisher.stop!
|
634
669
|
#
|
635
670
|
def publish_async data = nil, attributes = nil, ordering_key: nil, **extra_attrs, &callback
|
636
671
|
ensure_service!
|