GeoblacklightMessaging
GeoblacklightMessaging is a plugin that enables Geoblacklight applications to synchronize with external services using a RabbitMQ exchange. The plugin subscribes to events on the exchange and updates Geoblacklight records when they're created, updated, or deleted.
Dependencies
Installation
Add this line to your Geoblacklight application's Gemfile:
gem 'geoblacklight_messaging'
And then execute:
$ bundle
Run generator:
$ rails generate geoblacklight_messaging:install
Configure the events settings in config/messaging.yml
:
defaults: &defaults
events:
server: <%= ENV['RABBIT_SERVER'] || 'amqp://localhost:5672' %>
exchange:
geoblacklight: 'gbl_events'
Usage
-
Start RabbitMQ:
$ rabbitmq-server
-
Run your geoblacklight application:
$ rake geoblacklight:server
-
In a separate console, run:
$ WORKERS=GeoblacklightMessaging::GeoblacklightEventHandler rake sneakers:run
-
If the RabbitMQ Management Plugin is installed, you can inspect the exchange and publish messages manually using the web interface at
http://localhost:15672/
.
Message Format
Create
-
The event workers expect a json create message in the following format:
{ "id": "princeton-abc123", "event": "CREATED", "doc": { "layer_slug_s": "princeton-abc123", "dc_title_s": "Cool Map", ... } }
-
id
is the record's unique key.layer_slug_s
in this case. -
doc
is the unescaped geoblacklight json document.
Update
-
Update is similar to create.
{ "id": "princeton-abc123", "event": "UPDATED", "doc": { "layer_slug_s": "princeton-abc123", "dc_title_s": "New Map Name", ... } }
Delete
-
No doc value is needed for delete:
{ "id": "princeton-abc123", "event": "DELETED" }
Thanks
This gem was based on work done by @tpendragon for Plum and Pomegranate.