File tree Expand file tree Collapse file tree
google-cloud-pubsub/samples Expand file tree Collapse file tree Original file line number Diff line number Diff line change 2222require_relative "../pubsub_subscriber_flow_settings.rb"
2323require_relative "../pubsub_subscriber_async_pull.rb"
2424require_relative "../pubsub_subscriber_concurrency_control.rb"
25+ require_relative "../pubsub_subscriber_error_listener.rb"
2526require_relative "../pubsub_subscriber_sync_pull_with_lease.rb"
2627require_relative "../pubsub_update_push_configuration.rb"
2728require_relative "../pubsub_list_subscriptions.rb"
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"
Original file line number Diff line number Diff 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."
You can’t perform that action at this time.
0 commit comments