Project

pubsub_tie

0.0
Low commit activity in last 3 years
No release in over a year
Hook for Google PubSub for publication of events enforcing autoimposed rules
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

~> 13.0
~> 3.0
~> 2.1.4

Runtime

 Project Readme

pubsub-tie

Basic hook for Google PubSub to enforce a number of auto-imposed basic rules on publication of events via PubSub messages:

  1. Only white-listed events may be published
  2. Enforce presence of required fields on events
  3. Exclude fields nor required, optional, or repeated (array-like).
  4. 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

References