Module: Ears
- Defined in:
- lib/ears.rb,
lib/ears/setup.rb,
lib/ears/errors.rb,
lib/ears/testing.rb,
lib/ears/version.rb,
lib/ears/consumer.rb,
lib/ears/publisher.rb,
lib/ears/middleware.rb,
lib/ears/configuration.rb,
lib/ears/consumer_wrapper.rb,
lib/ears/middlewares/json.rb,
lib/ears/testing/test_helper.rb,
lib/ears/middlewares/appsignal.rb,
lib/ears/publisher_channel_pool.rb,
lib/ears/testing/publisher_mock.rb,
lib/ears/middlewares/max_retries.rb,
lib/ears/publisher_retry_handler.rb,
lib/ears/testing/message_capture.rb,
lib/ears/publisher_confirmation_handler.rb
Defined Under Namespace
Modules: Middlewares, Testing Classes: Configuration, Consumer, ConsumerWrapper, MaxRecoveryAttemptsExhaustedError, Middleware, PublishConfirmationTimeout, PublishError, PublishNacked, Publisher, PublisherChannelPool, PublisherConfirmationHandler, PublisherRetryHandler, Setup
Constant Summary collapse
- VERSION =
'0.22.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 ⇒ Object
Used to set up your exchanges, queues and consumers.
-
.setup_consumers(*consumer_classes) ⇒ Object
Quick setup your consumers (including exchanges and queues).
-
.stop! ⇒ Object
Closes the connection, removing the consumers.
Class Method Details
.channel ⇒ Bunny::Channel
The channel for the current thread.
38 39 40 41 42 43 44 45 |
# File 'lib/ears.rb', line 38 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.
14 15 16 |
# File 'lib/ears.rb', line 14 def configuration @configuration ||= Ears::Configuration.new end |
.configure {|configuration| ... } ⇒ Object
Yields the global configuration instance so you can modify it.
20 21 22 23 |
# File 'lib/ears.rb', line 20 def configure yield(configuration) configuration.validate! end |
.connection ⇒ Bunny::Session
The global RabbitMQ connection used by Ears.
28 29 30 31 32 33 |
# File 'lib/ears.rb', line 28 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.
76 77 78 79 |
# File 'lib/ears.rb', line 76 def error!(error) puts(error.) @error = error end |
.reset! ⇒ Object
Used internally for testing.
82 83 84 |
# File 'lib/ears.rb', line 82 def reset! @configuration = @connection = 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.
59 60 61 62 63 64 |
# File 'lib/ears.rb', line 59 def run! @running = true setup_traps sleep 1 while @running && @error.nil? raise @error if @error end |
.setup ⇒ Object
Used to set up your exchanges, queues and consumers. See Setup for implementation details.
48 49 50 |
# File 'lib/ears.rb', line 48 def setup(&) Ears::Setup.new.instance_eval(&) end |
.setup_consumers(*consumer_classes) ⇒ Object
Quick setup your consumers (including exchanges and queues).
53 54 55 |
# File 'lib/ears.rb', line 53 def setup_consumers(*consumer_classes) Ears::Setup.new.setup_consumers(*consumer_classes) end |
.stop! ⇒ Object
Closes the connection, removing the consumers.
67 68 69 70 71 |
# File 'lib/ears.rb', line 67 def stop! connection.close @connection = nil Thread.current[:ears_channel] = nil end |