README.md in basquiat-1.2.0 vs README.md in basquiat-1.3.0.pre.1

- old
+ new

@@ -1,97 +1,113 @@ # Basquiat -**Basquiat** is intended to hide (almost) all the complexity of working with some kind of message queue from the application internals. +[![Code Climate](https://codeclimate.com/github/VAGAScom/basquiat/badges/gpa.svg)](https://codeclimate.com/github/VAGAScom/basquiat) -All the exchanges, connections, queues and sessions declarations are swept under rug. The main aim is to provide a simple yet flexible interface to work with message queues. +**Basquiat** is library aimed to hide (almost) all the complexity when working with some kind of message queue from the application internals. +All the exchanges, connections, queues and sessions declarations are swept under rug. The aim is to provide a simple yet flexible interface to work with message queues. + ## Installation Add this line to your application's Gemfile: - gem 'basquiat' +```ruby +gem 'basquiat' +``` And then execute: - $ bundle +```bash +$ bundle +``` Or install it yourself as: - $ gem install basquiat +```bash +$ gem install basquiat +``` -You will also need the right gem for your MQ system. Bundled in this gem you will find 2 adapters for RabbitMQ and ActiveMQ which depends on the gems _bunny_ and _ruby-stomp_ respectively. +You will also need the right gem for your Message Queue (MQ) system. Bundled in this gem you will find 1 adapter, for RabbitMQ, which depends on the gem _bunny_. ## Basic Usage -First of all require the gem, the dependecy for the adapter and the adapter itself +First of all require the gem, the dependency for the adapter and the adapter itself - require 'basquiat' - require 'bunny' - require 'basquiat/adapters/rabbitmq_adapter' +```ruby +require 'basquiat' +require 'bunny' +require 'basquiat/adapters/rabbitmq_adapter' +``` -Then you can extend the class that you will use for communicating with the MQ +Then you can extend the class that you will use for communicating with the MQ, setting the adapter: - class TownCrier - extend Basquiat::Base - end +```ruby +class TownCrier + extend Basquiat::Base + self.event_adapter Basquiat::Adapters::RabbitMq +end +``` +From there you can publish events to the queue -From here you can publish events to the queue - - TownCrier.publish('some.nifty.event', {a: 'hash', of: 'values'}) - +```ruby +TownCrier.publish('some.nifty.event', {a: 'hash', of: 'values'}) +``` And you can subscribe to one or more events using a proc that will get called when the message is received: - class TownCrier - extend Basquiat::Base +```ruby +class TownCrier + extend Basquiat::Base - subscribe_to 'some.nifty.event', ->(msg) { msg.fetch(:of, '').upcase } - end + subscribe_to 'some.nifty.event', ->(msg) { msg.fetch(:of, '').upcase } +end +``` ## Configuration You can setup Basquiat using the configure method. This method will yield a Configuration object: - Basquiat.configure do |config| - config.exchange_name = 'my_exchange' - end - +```ruby +Basquiat.configure do |config| + config.exchange_name = 'my_exchange' +end +``` The available options are: - config_file= Receive a path to an YAML file (example here) - queue_name= The default queue name - exchange_name= The default exchange name - environment= Forces the environment to something other than the value of BASQUIAT_ENV -- logger= The logger to be used. Defaults to a null logger. +- logger= The logger to be used. Defaults to a null object logger. -The configuration can be reset using the Basquiat.reset method. +The configuration can be reset using the `Basquiat.reset` method. -Yaml File configuration example: +YAML File configuration example: - test: #environment - exchange_name: 'my.test_exchange' #required - queue_name: 'my.nice_queue' #required - default_adapter: Basquiat::Adapters::Test #it will overwrite the adapter on all classes that extend Basquiat::Base - adapter_options: #Adapter specific options - :servers: - - - :host: 'localhost' - :port: '5672' - development: #full example of the RabbitMq options - exchange_name: 'my.exchange' - queue_name: 'my.queue' - default_adapter: Basquiat::Adapters::RabbitMq - adapter_options: - servers: - - - :host: 'localhost' - :port: '5672' - failover: - :default_timeout: 5 - :max_retries: 5 - publisher: - confirm: true - persistent: true - auth: - user: 'guest' - password: 'guest' - requeue: - enabled: false +```yaml +test: #environment + default_adapter: Basquiat::Adapters::Test #it will overwrite the adapter on all classes that extend Basquiat::Base + adapter_options: #Adapter specific options + servers: + - + host: 'localhost' + port: '98765' +development: #full example of the RabbitMq options + exchange_name: 'basquiat.exchange' + queue_name: 'basquiat.queue' + default_adapter: Basquiat::Adapters::RabbitMq + adapter_options: + hosts: + - 'localhost' + port: 5672 + publisher: + confirm: true + persistent: true + auth: + user: 'guest' + password: 'guest' + requeue: + enabled: true + delayed_delivery: + retries: 10 + queue_name_preffix: wait.for_it + exchange_name: legendary +```