Added support for RabbitMQ

Andrew Kane committed Feb 16, 2016
commit 794cfb074bc13a167105473cd12e90a1f8955e99
Showing 6 changed files with 80 additions and 0 deletions
CHANGELOG.md +5 -0
@@ @@ -1,3 +1,8 @@
+ ## 1.3.0 [unreleased]
+
+ - Added support for RabbitMQ
+ - Added support for Amazon Kinesis Firehose
+
## 1.2.1
- Fixed `SystemStackError: stack level too deep` when used with `activerecord-session_store`
README.md +17 -0
@@ @@ -36,6 +36,7 @@ Ahoy supports a number of data stores out of the box. You can start with one of
- [SQLite](#mysql-or-sqlite)
- [MongoDB](#mongodb)
- [Fluentd](#fluentd)
+ - [RabbitMQ](#rabbitmq-master) [master]
- [Kinesis Firehose](#kinesis-firehose-master) [master]
- [Logs](#logs)
- [Custom](#custom)
@@ @@ -102,6 +103,22 @@ rails generate ahoy:stores:fluentd
Use `ENV["FLUENTD_HOST"]` and `ENV["FLUENTD_PORT"]` to configure.
+ ### RabbitMQ [master]
+
+ Add [bunny](https://github.com/ruby-amqp/bunny) to your Gemfile.
+
+ ```ruby
+ gem 'bunny'
+ ```
+
+ And run:
+
+ ```sh
+ rails generate ahoy:stores:bunny
+ ```
+
+ Use `ENV["RABBITMQ_URL"]` to configure.
+
### Kinesis Firehose [master]
Add [aws-sdk](https://github.com/aws/aws-sdk-ruby) to your Gemfile.
ahoy.rb b/lib/ahoy.rb +1 -0
@@ @@ -26,6 +26,7 @@ require "ahoy/stores/log_store"
require "ahoy/stores/fluentd_store"
require "ahoy/stores/mongoid_store"
require "ahoy/stores/kinesis_firehose_store"
+ require "ahoy/stores/bunny_store"
require "ahoy/engine"
require "ahoy/warden" if defined?(Warden)
ahoy/stores/bunny_store.rb b/lib/ahoy/stores/bunny_store.rb +33 -0
@@ @@ -0,0 +1,33 @@
+ module Ahoy
+ module Stores
+ class BunnyStore < LogStore
+ def log_visit(data)
+ post(visits_queue, data)
+ end
+
+ def log_event(data)
+ post(events_queue, data)
+ end
+
+ def channel
+ @channel ||= begin
+ conn = Bunny.new
+ conn.start
+ conn.create_channel
+ end
+ end
+
+ def post(queue, message)
+ channel.queue(queue, durable: true).publish(message.to_json)
+ end
+
+ def visits_queue
+ "ahoy_visits"
+ end
+
+ def events_queue
+ "ahoy_events"
+ end
+ end
+ end
+ end
generators/ahoy/stores/bunny_generator.rb b/lib/generators/ahoy/stores/bunny_generator.rb +15 -0
@@ @@ -0,0 +1,15 @@
+ require "rails/generators"
+
+ module Ahoy
+ module Stores
+ module Generators
+ class BunnyGenerator < Rails::Generators::Base
+ source_root File.expand_path("../templates", __FILE__)
+
+ def create_initializer
+ template "bunny_initializer.rb", "config/initializers/ahoy.rb"
+ end
+ end
+ end
+ end
+ end
generators/ahoy/stores/templates/bunny_initializer.rb b/lib/generators/ahoy/stores/templates/bunny_initializer.rb +9 -0
@@ @@ -0,0 +1,9 @@
+ class Ahoy::Store < Ahoy::Stores::BunnyStore
+ def visits_queue
+ "ahoy_visits"
+ end
+
+ def events_queue
+ "ahoy_events"
+ end
+ end