Module: DeliveryBoy
- Defined in:
- lib/delivery_boy.rb,
lib/delivery_boy/fake.rb,
lib/delivery_boy/config.rb,
lib/delivery_boy/railtie.rb,
lib/delivery_boy/version.rb,
lib/delivery_boy/instance.rb,
lib/delivery_boy/config_error.rb,
lib/generators/delivery_boy/install_generator.rb
Defined Under Namespace
Modules: Generators Classes: Config, Fake, Instance, Railtie
Constant Summary collapse
- VERSION =
"1.0.1"
- ConfigError =
Class.new(StandardError)
Class Attribute Summary collapse
-
.logger ⇒ Logger
The logger used by DeliveryBoy.
Class Method Summary collapse
-
.clear_buffer ⇒ Object
Clear any buffered messages generated by DeliveryBoy.produce or DeliveryBoy.produce! methods.
-
.config ⇒ DeliveryBoy::Config
The configuration used by DeliveryBoy.
-
.configure {|DeliveryBoy::Config| ... } ⇒ nil
Configure DeliveryBoy in a block.
-
.deliver(value, topic:, **options) ⇒ nil
Write a message to a specified Kafka topic synchronously.
-
.deliver_async(value, topic:, **options) ⇒ nil
Like DeliveryBoy.deliver_async!, but handles
Kafka::BufferOverflow
errors by logging them and just going on with normal business. -
.deliver_async!(value, topic:, **options) ⇒ nil
Like DeliveryBoy.deliver, but returns immediately.
-
.deliver_messages ⇒ nil
Delivers the items currently in the producer buffer.
-
.produce(value, topic:, **options) ⇒ nil
Like DeliveryBoy.produce!, but handles
Kafka::BufferOverflow
errors by logging them and just going on with normal business. -
.produce!(value, topic:, **options) ⇒ nil
Appends the given message to the producer buffer but does not send it until DeliveryBoy.deliver_messages is called.
-
.shutdown ⇒ nil
Shut down DeliveryBoy.
- .test_mode! ⇒ Object
- .testing ⇒ Object
Class Attribute Details
.logger ⇒ Logger
The logger used by DeliveryBoy.
100 101 102 103 104 105 106 |
# File 'lib/delivery_boy.rb', line 100 def logger @logger ||= Logger.new($stdout).tap do |logger| if config.log_level logger.level = Object.const_get("Logger::#{config.log_level.upcase}") end end end |
Class Method Details
.clear_buffer ⇒ Object
84 85 86 |
# File 'lib/delivery_boy.rb', line 84 def clear_buffer instance.clear_buffer end |
.config ⇒ DeliveryBoy::Config
The configuration used by DeliveryBoy.
113 114 115 116 117 |
# File 'lib/delivery_boy.rb', line 113 def config @config ||= DeliveryBoy::Config.new(env: ENV) rescue KingKonf::ConfigError => e raise ConfigError, e. end |
.configure {|DeliveryBoy::Config| ... } ⇒ nil
Configure DeliveryBoy in a block.
DeliveryBoy.configure do |config|
config.client_id = "yolo"
end
127 128 129 |
# File 'lib/delivery_boy.rb', line 127 def configure yield config end |
.deliver(value, topic:, **options) ⇒ nil
Write a message to a specified Kafka topic synchronously.
Keep in mind that the client will block until the message has been delivered.
27 28 29 |
# File 'lib/delivery_boy.rb', line 27 def deliver(value, topic:, **) instance.deliver(value, topic: topic, **) end |
.deliver_async(value, topic:, **options) ⇒ nil
Like deliver_async!, but handles Kafka::BufferOverflow
errors by logging them and just going on with normal business.
35 36 37 38 39 |
# File 'lib/delivery_boy.rb', line 35 def deliver_async(value, topic:, **) deliver_async!(value, topic: topic, **) rescue Kafka::BufferOverflow logger.error "Message for `#{topic}` dropped due to buffer overflow" end |
.deliver_async!(value, topic:, **options) ⇒ nil
Like deliver, but returns immediately.
The actual delivery takes place in a background thread.
46 47 48 |
# File 'lib/delivery_boy.rb', line 46 def deliver_async!(value, topic:, **) instance.deliver_async!(value, topic: topic, **) end |
.deliver_messages ⇒ nil
Delivers the items currently in the producer buffer.
79 80 81 |
# File 'lib/delivery_boy.rb', line 79 def instance. end |
.produce(value, topic:, **options) ⇒ nil
Like produce!, but handles Kafka::BufferOverflow
errors by logging them and just going on with normal business.
54 55 56 57 58 |
# File 'lib/delivery_boy.rb', line 54 def produce(value, topic:, **) produce!(value, topic: topic, **) rescue Kafka::BufferOverflow logger.error "Message for `#{topic}` dropped due to buffer overflow" end |
.produce!(value, topic:, **options) ⇒ nil
Appends the given message to the producer buffer but does not send it until deliver_messages is called.
71 72 73 |
# File 'lib/delivery_boy.rb', line 71 def produce!(value, topic:, **) instance.produce(value, topic: topic, **) end |
.shutdown ⇒ nil
Shut down DeliveryBoy.
Automatically called when the process exits.
93 94 95 |
# File 'lib/delivery_boy.rb', line 93 def shutdown instance.shutdown end |
.test_mode! ⇒ Object
131 132 133 |
# File 'lib/delivery_boy.rb', line 131 def test_mode! @instance = testing end |