Module: Ears
- Defined in:
- lib/ears.rb,
lib/ears/setup.rb,
lib/ears/errors.rb,
lib/ears/version.rb,
lib/ears/consumer.rb,
lib/ears/middleware.rb,
lib/ears/configuration.rb,
lib/ears/consumer_wrapper.rb,
lib/ears/middlewares/json.rb,
lib/ears/middlewares/appsignal.rb,
lib/ears/middlewares/max_retries.rb
Defined Under Namespace
Modules: Middlewares Classes: Configuration, Consumer, ConsumerWrapper, MaxRecoveryAttemptsExhaustedError, Middleware, Setup
Constant Summary collapse
- VERSION =
'0.11.2'
Class Method Summary collapse
-
.channel ⇒ Bunny::Channel
The channel for the current thread.
-
.configuration ⇒ Ears::Configuration
The global configuration for Ears.
-
.configure {|configuration| ... } ⇒ Object
Yields the global configuration instance so you can modify it.
-
.connection ⇒ Bunny::Session
The global RabbitMQ connection used by Ears.
-
.error!(error) ⇒ Object
Signals that an uncaught error has occurred and the process should be stopped.
-
.reset! ⇒ Object
Used internally for testing.
-
.run! ⇒ Object
Blocks the calling thread until +SIGTERM+ or +SIGINT+ is received.
-
.setup(&block) ⇒ Object
Used to set up your exchanges, queues and consumers.
-
.stop! ⇒ Object
Closes the connection, removing the consumers.
Class Method Details
.channel ⇒ Bunny::Channel
The channel for the current thread.
37 38 39 40 41 42 43 44 |
# File 'lib/ears.rb', line 37 def channel Thread.current[:ears_channel] ||= connection .create_channel(nil, 1, true) .tap do |channel| channel.prefetch(1) channel.on_uncaught_exception { |error| Ears.error!(error) } end end |
.configuration ⇒ Ears::Configuration
The global configuration for Ears.
13 14 15 |
# File 'lib/ears.rb', line 13 def configuration @configuration ||= Ears::Configuration.new end |
.configure {|configuration| ... } ⇒ Object
Yields the global configuration instance so you can modify it.
19 20 21 22 |
# File 'lib/ears.rb', line 19 def configure yield(configuration) configuration.validate! end |
.connection ⇒ Bunny::Session
The global RabbitMQ connection used by Ears.
27 28 29 30 31 32 |
# File 'lib/ears.rb', line 27 def connection @connection ||= Bunny .new(configuration.rabbitmq_url, **connection_config) .tap { |conn| conn.start } end |
.error!(error) ⇒ Object
Signals that an uncaught error has occurred and the process should be stopped.
70 71 72 73 |
# File 'lib/ears.rb', line 70 def error!(error) puts(error.) @error = error end |
.reset! ⇒ Object
Used internally for testing.
76 77 78 79 80 |
# File 'lib/ears.rb', line 76 def reset! @connection = nil @configuration = nil Thread.current[:ears_channel] = nil end |
.run! ⇒ Object
Blocks the calling thread until +SIGTERM+ or +SIGINT+ is received. Used to keep the process alive while processing messages.
53 54 55 56 57 58 |
# File 'lib/ears.rb', line 53 def run! @running = true setup_traps sleep 1 while @running && @error.nil? raise @error if @error end |
.setup(&block) ⇒ Object
Used to set up your exchanges, queues and consumers. See Setup for implementation details.
47 48 49 |
# File 'lib/ears.rb', line 47 def setup(&block) Ears::Setup.new.instance_eval(&block) end |
.stop! ⇒ Object
Closes the connection, removing the consumers.
61 62 63 64 65 |
# File 'lib/ears.rb', line 61 def stop! connection.close @connection = nil Thread.current[:ears_channel] = nil end |