pubsub-tie
Basic hook for Google PubSub to enforce a number of auto-imposed basic rules on publication of events via PubSub messages:
- Only white-listed events may be published
- Enforce presence of required fields on events
- Exclude fields nor required, optional, or repeated (array-like).
- Check field type (all elements in a repeated field)
Installation
gem install pubsub_tie
Usage
Publish white-listed events by symbol (name) passing hash structure of attributes. Events are published to topic named after event name and prefixed by app-level prefix
require 'pubsub_tie'
evt = {'id' => 1, 'name' => 'John', 'email' => 'john@me.com'}
PubSubTie.publish(:user_updated, evt)
# published on topic 'my_app_name-user_updated'
Configuration
There are two required configuration files that are expected at config/gcp.yml and config/events.yml
gcp.yml contains Google Cloud Platform project name and service account's credentials file by environment
development:
project: 'gcp-project'
keyfile: 'name-of-google-credentials-file-to-be-found-on-config-directory'
production:
...
events.yml contains definition of valid events
app_prefix: my_app_name
events:
- name: evt_name_0
summary: 'what happened at 0'
required:
- name: one_required_field
type: STRING|INT|FLOAT|TIMESTAMP|DATETIME|BOOL
- name: another_required_field
type: STRING|INT|FLOAT|TIMESTAMP|DATETIME|BOOL
optional:
- name: one_optional_field
type: STRING|INT|FLOAT|TIMESTAMP|DATETIME|BOOL
repeated:
- name: one_array_like_field
type: STRING|INT|FLOAT|TIMESTAMP|DATETIME|BOOL
- name: evt_name_1
summary: 'what happened at 1'
required:
- name: only_required_field
type: STRING|INT|FLOAT|TIMESTAMP|DATETIME|BOOL