Skip to content

Commit f0af41f

Browse files
committed
samples(pubsub): pubsub_subscriber_error_listener v2 upgrade and testing
1 parent f210dff commit f0af41f

2 files changed

Lines changed: 18 additions & 4 deletions

File tree

google-cloud-pubsub/samples/acceptance/subscriptions_test.rb

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
require_relative "../pubsub_subscriber_flow_settings.rb"
2323
require_relative "../pubsub_subscriber_async_pull.rb"
2424
require_relative "../pubsub_subscriber_concurrency_control.rb"
25+
require_relative "../pubsub_subscriber_error_listener.rb"
2526
require_relative "../pubsub_subscriber_sync_pull_with_lease.rb"
2627
require_relative "../pubsub_update_push_configuration.rb"
2728
require_relative "../pubsub_list_subscriptions.rb"
@@ -164,6 +165,19 @@
164165
end
165166
end
166167

168+
it "supports pubsub_subscriber_error_listener" do
169+
publisher = pubsub.publisher @topic.name
170+
publisher.publish "This is a test message."
171+
sleep 5
172+
173+
# pubsub_subscriber_error_listener
174+
expect_with_retry "pubsub_subscriber_error_listener" do
175+
assert_output "Received message: This is a test message.\n" do
176+
listen_for_messages_with_error_handler subscription_id: @subscription.name
177+
end
178+
end
179+
end
180+
167181
it "supports pubsub_subscriber_async_pull_custom_attributes" do
168182
publisher = pubsub.publisher @topic.name
169183
publisher.publish "This is a test message.", origin: "ruby-sample"

google-cloud-pubsub/samples/pubsub_subscriber_error_listener.rb

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@ def listen_for_messages_with_error_handler subscription_id:
2020

2121
pubsub = Google::Cloud::PubSub.new
2222

23-
subscription = pubsub.subscription subscription_id
24-
subscriber = subscription.listen do |received_message|
23+
subscriber = pubsub.subscriber subscription_id
24+
listener = subscriber.listen do |received_message|
2525
puts "Received message: #{received_message.data}"
2626
received_message.acknowledge!
2727
end
@@ -31,11 +31,11 @@ def listen_for_messages_with_error_handler subscription_id:
3131
Thread.abort_on_exception = true
3232

3333
begin
34-
subscriber.start
34+
listener.start
3535
# Let the main thread sleep for 60 seconds so the thread for listening
3636
# messages does not quit
3737
sleep 60
38-
subscriber.stop.wait!
38+
listener.stop.wait!
3939
rescue StandardError => e
4040
puts "Exception #{e.inspect}: #{e.message}"
4141
raise "Stopped listening for messages."

0 commit comments

Comments
 (0)