google-cloud-pubsub 1.7.1 → 2.1.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.
- 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 -260
- 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 +86 -11
- data/lib/google/cloud/pubsub/subscription/push_config.rb +55 -31
- data/lib/google/cloud/pubsub/topic.rb +52 -14
- 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 -807
- 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 -1463
- data/lib/google/cloud/pubsub/v1/subscriber_client_config.json +0 -153
- data/lib/google/pubsub/v1/pubsub_pb.rb +0 -266
- 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,13 +353,25 @@ 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
|
353
360
|
@resource_name = nil
|
354
361
|
end
|
355
362
|
|
363
|
+
##
|
364
|
+
# An expression written in the Cloud Pub/Sub filter language. If non-empty, then only {Message} instances whose
|
365
|
+
# `attributes` field matches the filter are delivered on this subscription. If empty, then no messages are
|
366
|
+
# filtered out.
|
367
|
+
#
|
368
|
+
# @return [String] The frozen filter string.
|
369
|
+
#
|
370
|
+
def filter
|
371
|
+
ensure_grpc!
|
372
|
+
@grpc.filter.freeze
|
373
|
+
end
|
374
|
+
|
356
375
|
##
|
357
376
|
# Returns the {Topic} to which dead letter messages should be published if a dead letter policy is configured,
|
358
377
|
# otherwise `nil`. Dead lettering is done on a best effort basis. The same message might be dead lettered
|
@@ -554,7 +573,7 @@ module Google
|
|
554
573
|
#
|
555
574
|
# See {Topic#publish_async}, {#listen}, and {Message#ordering_key}.
|
556
575
|
#
|
557
|
-
# Makes an API call to retrieve the
|
576
|
+
# Makes an API call to retrieve the enable_message_ordering value when called on a
|
558
577
|
# reference object. See {#reference?}.
|
559
578
|
#
|
560
579
|
# @return [Boolean]
|
@@ -564,6 +583,35 @@ module Google
|
|
564
583
|
@grpc.enable_message_ordering
|
565
584
|
end
|
566
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
|
+
|
567
615
|
##
|
568
616
|
# Determines whether the subscription exists in the Pub/Sub service.
|
569
617
|
#
|
@@ -611,6 +659,32 @@ module Google
|
|
611
659
|
true
|
612
660
|
end
|
613
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
|
+
|
614
688
|
##
|
615
689
|
# Pulls messages from the server. Returns an empty list if there are no
|
616
690
|
# messages available in the backlog. Raises an ApiError with status
|
@@ -789,6 +863,7 @@ module Google
|
|
789
863
|
#
|
790
864
|
# subscriber = sub.listen do |received_message|
|
791
865
|
# # process message
|
866
|
+
# puts "Data: #{received_message.message.data}, published at #{received_message.message.published_at}"
|
792
867
|
# received_message.acknowledge!
|
793
868
|
# end
|
794
869
|
#
|
@@ -796,7 +871,7 @@ module Google
|
|
796
871
|
# subscriber.start
|
797
872
|
#
|
798
873
|
# # Shut down the subscriber when ready to stop receiving messages.
|
799
|
-
# subscriber.stop
|
874
|
+
# subscriber.stop!
|
800
875
|
#
|
801
876
|
# @example Configuring to increase concurrent callbacks:
|
802
877
|
# require "google/cloud/pubsub"
|
@@ -815,7 +890,7 @@ module Google
|
|
815
890
|
# subscriber.start
|
816
891
|
#
|
817
892
|
# # Shut down the subscriber when ready to stop receiving messages.
|
818
|
-
# subscriber.stop
|
893
|
+
# subscriber.stop!
|
819
894
|
#
|
820
895
|
# @example Ordered messages are supported using ordering_key:
|
821
896
|
# require "google/cloud/pubsub"
|
@@ -835,7 +910,7 @@ module Google
|
|
835
910
|
# subscriber.start
|
836
911
|
#
|
837
912
|
# # Shut down the subscriber when ready to stop receiving messages.
|
838
|
-
# subscriber.stop
|
913
|
+
# subscriber.stop!
|
839
914
|
#
|
840
915
|
# @example Set the maximum amount of time before redelivery if the subscriber fails to extend the deadline:
|
841
916
|
# require "google/cloud/pubsub"
|
@@ -854,7 +929,7 @@ module Google
|
|
854
929
|
# subscriber.start
|
855
930
|
#
|
856
931
|
# # Shut down the subscriber when ready to stop receiving messages.
|
857
|
-
# subscriber.stop
|
932
|
+
# subscriber.stop!
|
858
933
|
#
|
859
934
|
def listen deadline: nil, message_ordering: nil, streams: nil, inventory: nil, threads: {}, &block
|
860
935
|
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
|
@@ -286,6 +289,9 @@ module Google
|
|
286
289
|
# Managing Labels](https://cloud.google.com/pubsub/docs/labels).
|
287
290
|
# @param [Boolean] message_ordering Whether to enable message ordering
|
288
291
|
# on the subscription.
|
292
|
+
# @param [String] filter An expression written in the Cloud Pub/Sub filter language. If non-empty, then only
|
293
|
+
# {Message} instances whose `attributes` field matches the filter are delivered on this subscription. If
|
294
|
+
# empty, then no messages are filtered out. Optional.
|
289
295
|
# @param [Topic] dead_letter_topic The {Topic} to which dead letter messages for the subscription should be
|
290
296
|
# published. Dead lettering is done on a best effort basis. The same message might be dead lettered multiple
|
291
297
|
# times. The Cloud Pub/Sub service account associated with the enclosing subscription's parent project (i.e.,
|
@@ -317,15 +323,25 @@ module Google
|
|
317
323
|
# sub = topic.subscribe "my-topic-sub"
|
318
324
|
# sub.name # => "my-topic-sub"
|
319
325
|
#
|
320
|
-
# @example Wait 2 minutes for acknowledgement
|
326
|
+
# @example Wait 2 minutes for acknowledgement:
|
321
327
|
# require "google/cloud/pubsub"
|
322
328
|
#
|
323
329
|
# pubsub = Google::Cloud::PubSub.new
|
324
330
|
#
|
325
331
|
# topic = pubsub.topic "my-topic"
|
326
332
|
# sub = topic.subscribe "my-topic-sub",
|
327
|
-
# deadline: 120
|
328
|
-
#
|
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
|
329
345
|
#
|
330
346
|
# @example Configure a Dead Letter Queues policy:
|
331
347
|
# require "google/cloud/pubsub"
|
@@ -358,18 +374,40 @@ module Google
|
|
358
374
|
# retry_policy = Google::Cloud::PubSub::RetryPolicy.new minimum_backoff: 5, maximum_backoff: 300
|
359
375
|
# sub = topic.subscribe "my-topic-sub", retry_policy: retry_policy
|
360
376
|
#
|
361
|
-
def subscribe subscription_name,
|
362
|
-
|
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,
|
363
388
|
retry_policy: nil
|
364
389
|
ensure_service!
|
365
|
-
|
366
|
-
|
367
|
-
|
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
|
+
|
368
405
|
options[:dead_letter_topic_name] = dead_letter_topic.name if dead_letter_topic
|
369
406
|
if options[:dead_letter_max_delivery_attempts] && !options[:dead_letter_topic_name]
|
370
407
|
# Service error message "3:Invalid resource name given (name=)." does not identify param.
|
371
408
|
raise ArgumentError, "dead_letter_topic is required with dead_letter_max_delivery_attempts"
|
372
409
|
end
|
410
|
+
options[:push_config] = push_config.to_grpc if push_config
|
373
411
|
options[:retry_policy] = retry_policy.to_grpc if retry_policy
|
374
412
|
grpc = service.create_subscription name, subscription_name, options
|
375
413
|
Subscription.from_grpc grpc, service
|
@@ -586,7 +624,7 @@ module Google
|
|
586
624
|
# end
|
587
625
|
#
|
588
626
|
# # Shut down the publisher when ready to stop publishing messages.
|
589
|
-
# topic.async_publisher.stop
|
627
|
+
# topic.async_publisher.stop!
|
590
628
|
#
|
591
629
|
# @example A message can be published using a File object:
|
592
630
|
# require "google/cloud/pubsub"
|
@@ -598,7 +636,7 @@ module Google
|
|
598
636
|
# topic.publish_async file
|
599
637
|
#
|
600
638
|
# # Shut down the publisher when ready to stop publishing messages.
|
601
|
-
# topic.async_publisher.stop
|
639
|
+
# topic.async_publisher.stop!
|
602
640
|
#
|
603
641
|
# @example Additionally, a message can be published with attributes:
|
604
642
|
# require "google/cloud/pubsub"
|
@@ -610,7 +648,7 @@ module Google
|
|
610
648
|
# foo: :bar, this: :that
|
611
649
|
#
|
612
650
|
# # Shut down the publisher when ready to stop publishing messages.
|
613
|
-
# topic.async_publisher.stop
|
651
|
+
# topic.async_publisher.stop!
|
614
652
|
#
|
615
653
|
# @example Ordered messages are supported using ordering_key:
|
616
654
|
# require "google/cloud/pubsub"
|
@@ -627,7 +665,7 @@ module Google
|
|
627
665
|
# ordering_key: "task-key"
|
628
666
|
#
|
629
667
|
# # Shut down the publisher when ready to stop publishing messages.
|
630
|
-
# topic.async_publisher.stop
|
668
|
+
# topic.async_publisher.stop!
|
631
669
|
#
|
632
670
|
def publish_async data = nil, attributes = nil, ordering_key: nil, **extra_attrs, &callback
|
633
671
|
ensure_service!
|