### Gemfile Setup for Kicks Source: https://github.com/ruby-amqp/kicks/blob/main/README.md Example of a Gemfile configuration for a Kicks project, including the Kicks gem itself and dependencies like JSON and Redis. ```ruby source 'https://rubygems.org' gem 'kicks' gem 'json' gem 'redis' ``` -------------------------------- ### Install Kicks Gem Source: https://github.com/ruby-amqp/kicks/blob/main/README.md Instructions for adding the Kicks gem to your Ruby project's Gemfile and installing it using Bundler or directly via the gem command. ```ruby gem 'kicks' ``` ```shell bundle ``` ```shell gem install kicks ``` -------------------------------- ### Basic Kicks Worker Setup Source: https://github.com/ruby-amqp/kicks/blob/main/README.md Demonstrates how to set up a basic Kicks worker in Ruby. This includes requiring necessary libraries, initializing a Redis connection, defining a worker class that includes Sneakers::Worker, and specifying the queue it listens to. ```ruby require 'sneakers' require 'redis' require 'json' $redis = Redis.new class Processor include Sneakers::Worker from_queue :logs def work(msg) err = JSON.parse(msg) if err["type"] == "error" $redis.incr "processor:#{err["error"]}" end ack! end end ``` -------------------------------- ### Running a Kicks Worker Source: https://github.com/ruby-amqp/kicks/blob/main/README.md Command-line instruction to run a Kicks worker. It specifies the worker class to use and a file to require for environment setup. ```shell $ sneakers work Processor --require boot.rb ``` -------------------------------- ### Example Message Payload Source: https://github.com/ruby-amqp/kicks/blob/main/README.md A sample JSON payload representing an error message that can be sent to the Kicks worker. ```javascript { "type": "error", "message": "HALP!", "error": "CODE001" } ``` -------------------------------- ### Publishing Message to RabbitMQ Source: https://github.com/ruby-amqp/kicks/blob/main/README.md Example of publishing a JSON message to a RabbitMQ queue named 'logs' using the Bunny gem in Ruby. This demonstrates how to send data to a worker. ```ruby require 'bunny' conn = Bunny.new conn.start ch = conn.create_channel ch.default_exchange.publish({ type: 'error', message: 'HALP!', error: 'CODE001' }.to_json, routing_key: 'logs') conn.close ``` -------------------------------- ### Optional Queue Binding in Ruby AMQP Source: https://github.com/ruby-amqp/kicks/blob/main/ChangeLog.md Explains the feature allowing opt-out of binding the Kicks-declared exchange and queue. This provides more control over the AMQP topology setup. ```Ruby # Example of opting out of queue binding (conceptual) Kicks.configure do |config| config.bind_queue = false end ``` -------------------------------- ### Run Sample Worker with Docker Compose Source: https://github.com/ruby-amqp/kicks/blob/main/README.md Executes a sample worker, such as 'TitleScraper', within Docker using docker-compose. This demonstrates how to run Sneakers in a Docker-based production environment. ```bash script/local_worker ``` -------------------------------- ### Production Docker Build with Slim Dockerfile Source: https://github.com/ruby-amqp/kicks/blob/main/README.md Generates a more compact Docker image for production builds by using 'Dockerfile.slim' instead of the default 'Dockerfile'. This results in a smaller image size compared to the 'fat' development image. ```bash docker build -f Dockerfile.slim . -t sneakers_sneakers:production ``` -------------------------------- ### Monitoring Redis with redis-cli Source: https://github.com/ruby-amqp/kicks/blob/main/README.md Shows how to use the redis-cli monitor command to observe Redis operations in real-time, specifically tracking increments to a counter for error codes. ```shell $ redis-cli monitor 1381520329.888581 [0 127.0.0.1:49182] "incr" "processor:CODE001" ``` -------------------------------- ### Run Integration Tests with Docker Compose Source: https://github.com/ruby-amqp/kicks/blob/main/README.md Orchestrates a Docker topology including RabbitMQ and Redis for full integration tests. It uses docker-compose to manage the environment and the Sneakers Docker image to execute the tests. ```bash scripts/local_integration ``` -------------------------------- ### Build Docker Container for Kicks Source: https://github.com/ruby-amqp/kicks/blob/main/README.md Builds a Docker container for the Kicks project with the tag 'sneakers_sneakers'. This command is used to create a Docker image from the project's Dockerfile. ```bash docker build . -t sneakers_sneakers ``` -------------------------------- ### Configuring Kicks with Logging Metrics Source: https://github.com/ruby-amqp/kicks/blob/main/README.md Illustrates how to configure Kicks to use the LoggingMetrics provider for observing worker performance metrics. This involves adding a require statement and configuring Sneakers. ```ruby # boot.rb require 'sneakers' require 'redis' require 'json' require 'sneakers/metrics/logging_metrics' Sneakers.configure(metrics: Sneakers::Metrics::LoggingMetrics.new) # ... rest of code ``` -------------------------------- ### Support Bring-Your-Own-Connection (BYOC) in Ruby AMQP Source: https://github.com/ruby-amqp/kicks/blob/main/ChangeLog.md Introduces support for the Bring-Your-Own-Connection (BYOC) pattern, allowing users to provide a pre-configured Bunny connection. This offers greater flexibility in managing AMQP connections. ```Ruby # Example of using BYOC with Kicks (conceptual) require 'bunny' my_connection = Bunny.new(:host => 'localhost') my_connection.start Kicks.configure do |config| config.connection = my_connection end # Or using a callable: Kicks.configure do |config| config.connection = proc { Bunny.new(:host => 'localhost').tap(&:start) } end ``` -------------------------------- ### Run Non-Integration Tests in Docker Source: https://github.com/ruby-amqp/kicks/blob/main/README.md Executes non-integration tests within a Docker container. This command runs the previously built 'sneakers_sneakers:latest' image and automatically removes the container upon completion. ```bash docker run --rm sneakers_sneakers:latest ``` -------------------------------- ### Support :bind_arguments on Bind in Ruby AMQP Source: https://github.com/ruby-amqp/kicks/blob/main/ChangeLog.md Enables setting arguments on a queue when binding to a headers exchange. This allows for more advanced queue configuration based on message headers. ```Ruby # Example of using :bind_arguments (conceptual) channel.queue('my_queue', :durable => true) .bind(channel.headers_exchange('my_headers_exchange'), :routing_key => 'some_key', :arguments => {'x-match' => 'all', 'header1' => 'value1'}) ``` -------------------------------- ### Improve Bunny Exception Handling in Ruby Source: https://github.com/ruby-amqp/kicks/blob/main/ChangeLog.md Enhances how exceptions from the Bunny library are handled within consumer processes. This change aims to make the system more robust by properly managing potential errors originating from the AMQP client. ```Ruby # Example of improved exception handling for consumers (conceptual) begin # Consumer logic that might raise a Bunny exception rescue Bunny::Exception => e # Handle the specific Bunny exception puts "Caught Bunny exception: #{e.message}" rescue StandardError => e # Handle other standard errors puts "Caught standard error: #{e.message}" end ``` -------------------------------- ### Use Provided Connections in Ruby Worker Groups Source: https://github.com/ruby-amqp/kicks/blob/main/ChangeLog.md Allows the use of custom connection instances within worker groups. This enhances flexibility by enabling the reuse of existing or specifically configured AMQP connections. ```Ruby # Example of using provided connections in worker groups (conceptual) require 'bunny' custom_connection = Bunny.new(:host => 'custom.host') custom_connection.start Sneakers.configure(:workers => 2, :threads => 1, :connection => custom_connection) class MyWorker < Sneakers::Worker # ... worker implementation ... end Sneakers.run!([MyWorker]) ``` -------------------------------- ### ActiveJob Adapter for Ruby on Rails Source: https://github.com/ruby-amqp/kicks/blob/main/ChangeLog.md Details the integration of an ActiveJob adapter for Ruby on Rails within the Kicks project. This enables Kicks to be used seamlessly with Rails' background job processing capabilities. ```Ruby # Example of configuring Kicks ActiveJob adapter (conceptual) # config/application.rb or an initializer Kicks::ActiveJob.configure do |config| config.exchange = 'my_kicks_exchange' config.routing_key = 'my_routing_key' end # To use it in Rails: # class MyJob < ApplicationJob # queue_as :default # # def perform(*args) # # ... job logic ... # end # end ``` -------------------------------- ### Configure Logger in Ruby AMQP Source: https://github.com/ruby-amqp/kicks/blob/main/ChangeLog.md Details improvements to the logger configuration within the Kicks project. This allows for better control over logging output, aiding in debugging and monitoring AMQP interactions. ```Ruby # Example of improved logger configuration (conceptual) require 'logger' Kicks.configure do |config| config.logger = Logger.new(STDOUT) config.logger.level = Logger::INFO end ``` -------------------------------- ### Content Encoding Support in Ruby AMQP Source: https://github.com/ruby-amqp/kicks/blob/main/ChangeLog.md Adds support for content encoding, similar to existing content type support. This helps in ensuring proper data serialization and deserialization for AMQP messages. ```Ruby # Example of setting content encoding (conceptual) Kicks.configure do |config| config.content_encoding = 'utf-8' end # When publishing: channel.default_exchange.publish("message", :routing_key => routing_key, :content_encoding => 'utf-8') ``` -------------------------------- ### Rescue from ScriptError in Ruby Workers Source: https://github.com/ruby-amqp/kicks/blob/main/ChangeLog.md Addresses a bug where Sneakers workers would freeze upon encountering exceptions derived from `ScriptError`. This fix ensures better stability by handling such exceptions gracefully. ```Ruby # Example of rescuing ScriptError (conceptual) class MyWorker < Sneakers::Worker def work(delivery_info, properties, body) begin # ... worker logic ... raise NotImplementedError.new("This feature is not implemented yet.") rescue ScriptError => e # Log the error and reject the message log_error(e) reject rescue StandardError => e # Handle other errors log_error(e) reject end end end ``` -------------------------------- ### Worker Context Available to Worker Instances in Ruby Source: https://github.com/ruby-amqp/kicks/blob/main/ChangeLog.md Makes the worker context accessible to worker instances. This provides workers with additional information or state relevant to their execution environment. ```Ruby # Example of accessing worker context (conceptual) class MyWorker < Sneakers::Worker def work(delivery_info, properties, body) # Access context information if available # For example, if context includes a logger: # self.logger.info("Processing message...") puts "Processing message with context..." ack end end ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.