Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to properly handle errors on consumers? #218

Closed
geovanisouza92 opened this issue Apr 28, 2016 · 5 comments
Closed

How to properly handle errors on consumers? #218

geovanisouza92 opened this issue Apr 28, 2016 · 5 comments
Labels

Comments

@geovanisouza92
Copy link

My current setup is:

  • Rails 4 publisher
  • JRuby 9k consumer

hutch.yml (configuration):

mq_host: ...
mq_username: guest
mq_password: guest
mq_api_host: ...
channel_prefetch: 1
heartbeat: 150
require_paths:
  - foo.rb
error_handlers:
  - Logger
  - Sentry
error_acknowledgements:
  - Requeuer

Command: hutch --config config/hutch.yaml

I have a consumer executing a process that could raise some errors:

class Foo
  include Hutch::Consumer
  consume 'foo'

  def process(message)
    # process that handle message and could raise errors
  end
end

class Requeuer < Hutch::Acknowledgements::Base
  def handle(delivery_info, properties, broker, ex)
    broker.requeue delivery_info.delivery_tag
    true
  end
end

Hunting down the issue, I:

  • Started not handling the errors, but as discussed in Handling Exceptions (not StandardError) #195, this could be dangerous considering the Thread pool nature of AMQP client.
  • Then I tried just capturing and requeue'ing the message, but this clashes with @broker.ack on Hutch::Worker#handle_message, sending an requeue and ack messages to RabbitMQ, broking the protocol.
  • Then I tried the code above, that requeue and raise the error, but ended with hutch shut down gracefully in the middle of processing.

Considering #165, acking manually seems to be the best option, taking into account that as said in #195, the library could not decided whether if the worker/consumer should crashes due an unhandled exception.

This issue is more a doubt about what is the correct way to handle the errors on consumers?

@michaelklishin
Copy link
Member

Consumers should handle their exceptions. I'm not sure if this answers your question but there isn't much Hutch-specific. If you need to inspect protocol method flow or message flow, use Wireshark and RabbitMQ tracing, respectively.

@geovanisouza92
Copy link
Author

@michaelklishin Thanks for reply. My issue was not related to protocol itself, but the aspect of handling the errors without stopping worker.

@michaelklishin
Copy link
Member

Then perhaps I don't understand the question. Consumers are generally supposed to handle exceptions they can do something about.

@jnarowski
Copy link

I am also wondering how to best address this. If there is a syntax error in my code, I want the job to go back into the queue.

Consider this flow:

  1. message is received by consumer (and currently acked)
  2. There is a syntax error in the consumer code, we push a hotfix for this bug
  3. I'd like the message to go back into the queue to be tried again, and be reprocessed once the deploy is pushed and the consumers are reconnected.

How would we handle this logic so failed jobs aren't lost forever?

@michaelklishin
Copy link
Member

#177 introduced configurable acknowledgement behavior.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants