RenoteDac
This is a set of libraries and dependencies which allow you to quickly spin up a RabbitMQ powered Email/Notification Service as part of a (S)ervice (O)riented (A)rchitechture.
Usage
To implement this gem it is necessary to implement the server/publisher RenoteDac configuration either manually or by installing the publisher_renote_dac gem
RenoteDac is the subscriber end of a pub/sub notification service thats been extracted for use as a gem. The publisher app publish messages to a RabbitMQ exchange which then pushes the messages to a queue.
The remote Email/Notification service (consumer) uses a pool of workers to pull messages from the RabbitMQ queue and process them into the consumer service database. From there a worker will pull un-sent messages from the database and push them via the postmarks api in batches for delivery.
The postmark response is recorded on the email error column. Email records are left in database as a log.
Installation
Add this line to your application's Gemfile:
gem 'renote_dac'
And then execute:
$ bundle
Or install it yourself as:
$ gem install renote_dac
to generate an initializer and database.yml file run:
$ rails g renote_dac:install
then bundle again because you have a clean newly generated Gemfile
bundle install
run migrations:
rake db:create
rake db:migrate
rake db:seed
Starting Sneakers workers
first run:
export WORKERS=RenoteDac::ServiceQueueWorker
then run:
rake sneakers:run
Development
Deploy
run the following rake task to
- increment version
- delete old '.gem' files
- build fresh gem
- commit & push with version message
rake app:renote_dac:deploy
Configure
Postmark
add the 'config' gem to your application. Add the following line to your gemfile
gem 'config'
run rails g config:install
to generate the proper file structure in ./config folder to hold your application settings.
add the following to the production.yml and development.yml files inside the ./config/settings folder
development.yml
postmark:
api_token: 'dev-api-key-here'
from_address: 'Your App Name <[email protected]>'
production.yml
postmark:
api_token: ENV['POSTMARK_API_TOKEN']
from_address: 'Your App Name <[email protected]>'
Add your api token to your renote_dac initializer.
c.postmark_api_key = Settings.postmark.api_token
Production
Heroku Deploy
You can attach RabbitMQ Bigwig to a Heroku application via the CLI
heroku addons:create rabbitmq-bigwig
$=> Adding rabbitmq-bigwig to sharp-mountain-4005... done, v18 (free)
Once you have added RabbitMQ Bigwig you will find RABBITMQ_BIGWIG_TX_URL
and RABBITMQ_BIGWIG_RX_URL
settings in the app configuration. These contain the canonical URLs used to access the newly provisioned RabbitMQ Bigwig service instance. You can confirm this using the heroku config:get
command.
heroku config:get RABBITMQ_BIGWIG_RX_URL
$=> amqp://user:[email protected]/resourceid
heroku config:get RABBITMQ_BIGWIG_TX_URL
$=> amqp://user:[email protected]/resourceid2
also add file 'Procfile' to app root and make sure you have the worker enabled in Heroku dashboard
web: bundle exec puma -C config/puma.rb
clock: bundle exec clockwork config/clock.rb
worker: bundle exec que ./config/environment.rb
sneakers: WORKERS='RenoteDac::ServiceQueueWorker' bundle exec rake sneakers:run
set postmark's api_token
env variable on heroku settings tab
POSTMARK_API_TOKEN
Contributing
Contribution directions go here.
License
The gem is available as open source under the terms of the MIT License.