polyn 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.github/workflows/ruby.yml +39 -0
- data/.gitignore +12 -0
- data/.rspec +3 -0
- data/.rubocop.yml +44 -0
- data/.tool-versions +1 -0
- data/.travis.yml +6 -0
- data/CHANGELOG.md +5 -0
- data/CODE_OF_CONDUCT.md +84 -0
- data/Gemfile +32 -0
- data/Gemfile.lock +84 -0
- data/LICENSE.txt +21 -0
- data/README.md +160 -0
- data/Rakefile +12 -0
- data/bin/console +15 -0
- data/bin/setup +8 -0
- data/docker-compose.yml +7 -0
- data/lib/cloud-event-schema.json +187 -0
- data/lib/polyn/cloud_event.rb +13 -0
- data/lib/polyn/configuration.rb +30 -0
- data/lib/polyn/errors/configuration_error.rb +10 -0
- data/lib/polyn/errors/error.rb +13 -0
- data/lib/polyn/errors/errors.rb +6 -0
- data/lib/polyn/errors/schema_error.rb +10 -0
- data/lib/polyn/errors/validation_error.rb +10 -0
- data/lib/polyn/event.rb +138 -0
- data/lib/polyn/naming.rb +100 -0
- data/lib/polyn/pull_subscriber.rb +61 -0
- data/lib/polyn/schema_store.rb +50 -0
- data/lib/polyn/serializers/json.rb +136 -0
- data/lib/polyn/utils/hash.rb +82 -0
- data/lib/polyn/utils/string.rb +49 -0
- data/lib/polyn/utils/utils.rb +21 -0
- data/lib/polyn/version.rb +5 -0
- data/lib/polyn.rb +116 -0
- data/polyn.gemspec +52 -0
- metadata +123 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 30b50a04cee7e5a540b48d8d80276ca87e8c3b247b70da41a9e00c6950a8c4d3
|
4
|
+
data.tar.gz: '09c36399cec8f4e51188489d21aab4a49a41a8d420b273f4f5a9181b7c572b2d'
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: d631676305632f5379e6db7a8286b09b56b9764c118f2c957a06e13ea3bad8158365e164ec1e5a7f982d6578b7a32881fb972a5b4021c9422fb3a811f41031aa
|
7
|
+
data.tar.gz: 6dde4a3a64edeaf92e06dc7f3a47c54d84f55309156fad1499ea8189639d9c0c6d72c6d14b8cc40b6cd2bef76b29d3fbfe43a889a42906cbca0d7ff1fe8210ad
|
@@ -0,0 +1,39 @@
|
|
1
|
+
# This workflow uses actions that are not certified by GitHub.
|
2
|
+
# They are provided by a third-party and are governed by
|
3
|
+
# separate terms of service, privacy policy, and support
|
4
|
+
# documentation.
|
5
|
+
# This workflow will download a prebuilt Ruby version, install dependencies and run tests with Rake
|
6
|
+
# For more information see: https://github.com/marketplace/actions/setup-ruby-jruby-and-truffleruby
|
7
|
+
|
8
|
+
name: Ruby
|
9
|
+
|
10
|
+
on:
|
11
|
+
push:
|
12
|
+
branches: [ main ]
|
13
|
+
pull_request:
|
14
|
+
branches: [ main ]
|
15
|
+
|
16
|
+
jobs:
|
17
|
+
test:
|
18
|
+
|
19
|
+
runs-on: ubuntu-latest
|
20
|
+
strategy:
|
21
|
+
matrix:
|
22
|
+
ruby-version: ['2.6', '2.7', '3.0']
|
23
|
+
|
24
|
+
steps:
|
25
|
+
- uses: actions/checkout@v2
|
26
|
+
- name: Start NATS Jetstream
|
27
|
+
run: docker run --rm -d --network host nats:latest -js
|
28
|
+
- name: Set up Ruby
|
29
|
+
# To automatically get bug fixes and new Ruby versions for ruby/setup-ruby,
|
30
|
+
# change this to (see https://github.com/ruby/setup-ruby#versioning):
|
31
|
+
# uses: ruby/setup-ruby@v1
|
32
|
+
uses: ruby/setup-ruby@473e4d8fe5dd94ee328fdfca9f8c9c7afc9dae5e
|
33
|
+
with:
|
34
|
+
ruby-version: ${{ matrix.ruby-version }}
|
35
|
+
bundler-cache: true # runs 'bundle install' and caches installed gems automatically
|
36
|
+
- name: Start containers
|
37
|
+
run: docker-compose -f "docker-compose.yml" up -d --build
|
38
|
+
- name: Run tests
|
39
|
+
run: bundle exec rspec spec
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.rubocop.yml
ADDED
@@ -0,0 +1,44 @@
|
|
1
|
+
Layout/ExtraSpacing:
|
2
|
+
ForceEqualSignAlignment: true
|
3
|
+
|
4
|
+
Layout/ArgumentAlignment:
|
5
|
+
EnforcedStyle: with_fixed_indentation
|
6
|
+
|
7
|
+
Layout/IndentationWidth:
|
8
|
+
IgnoredPatterns: []
|
9
|
+
|
10
|
+
Layout/HashAlignment:
|
11
|
+
EnforcedColonStyle: table
|
12
|
+
EnforcedHashRocketStyle: table
|
13
|
+
|
14
|
+
Layout/LineLength:
|
15
|
+
Max: 100
|
16
|
+
IgnoreCopDirectives: true
|
17
|
+
|
18
|
+
Layout/EmptyLineAfterMagicComment:
|
19
|
+
Enabled: true
|
20
|
+
|
21
|
+
Metrics/MethodLength:
|
22
|
+
Max: 15
|
23
|
+
|
24
|
+
Metrics/BlockLength:
|
25
|
+
Exclude: ["spec/**/*_spec.rb"]
|
26
|
+
|
27
|
+
Style/ModuleFunction:
|
28
|
+
Enabled: false
|
29
|
+
|
30
|
+
Style/TrailingCommaInArguments:
|
31
|
+
EnforcedStyleForMultiline: comma
|
32
|
+
|
33
|
+
Style/TrailingCommaInHashLiteral:
|
34
|
+
EnforcedStyleForMultiline: comma
|
35
|
+
|
36
|
+
Style/TrailingCommaInArrayLiteral:
|
37
|
+
EnforcedStyleForMultiline: comma
|
38
|
+
|
39
|
+
Style/FrozenStringLiteralComment:
|
40
|
+
Enabled: true
|
41
|
+
SafeAutoCorrect: true
|
42
|
+
|
43
|
+
Style/StringLiterals:
|
44
|
+
EnforcedStyle: "double_quotes"
|
data/.tool-versions
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
ruby 3.0.4
|
data/.travis.yml
ADDED
data/CHANGELOG.md
ADDED
data/CODE_OF_CONDUCT.md
ADDED
@@ -0,0 +1,84 @@
|
|
1
|
+
# Contributor Covenant Code of Conduct
|
2
|
+
|
3
|
+
## Our Pledge
|
4
|
+
|
5
|
+
We as members, contributors, and leaders pledge to make participation in our community a harassment-free experience for everyone, regardless of age, body size, visible or invisible disability, ethnicity, sex characteristics, gender identity and expression, level of experience, education, socio-economic status, nationality, personal appearance, race, religion, or sexual identity and orientation.
|
6
|
+
|
7
|
+
We pledge to act and interact in ways that contribute to an open, welcoming, diverse, inclusive, and healthy community.
|
8
|
+
|
9
|
+
## Our Standards
|
10
|
+
|
11
|
+
Examples of behavior that contributes to a positive environment for our community include:
|
12
|
+
|
13
|
+
* Demonstrating empathy and kindness toward other people
|
14
|
+
* Being respectful of differing opinions, viewpoints, and experiences
|
15
|
+
* Giving and gracefully accepting constructive feedback
|
16
|
+
* Accepting responsibility and apologizing to those affected by our mistakes, and learning from the experience
|
17
|
+
* Focusing on what is best not just for us as individuals, but for the overall community
|
18
|
+
|
19
|
+
Examples of unacceptable behavior include:
|
20
|
+
|
21
|
+
* The use of sexualized language or imagery, and sexual attention or
|
22
|
+
advances of any kind
|
23
|
+
* Trolling, insulting or derogatory comments, and personal or political attacks
|
24
|
+
* Public or private harassment
|
25
|
+
* Publishing others' private information, such as a physical or email
|
26
|
+
address, without their explicit permission
|
27
|
+
* Other conduct which could reasonably be considered inappropriate in a
|
28
|
+
professional setting
|
29
|
+
|
30
|
+
## Enforcement Responsibilities
|
31
|
+
|
32
|
+
Community leaders are responsible for clarifying and enforcing our standards of acceptable behavior and will take appropriate and fair corrective action in response to any behavior that they deem inappropriate, threatening, offensive, or harmful.
|
33
|
+
|
34
|
+
Community leaders have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct, and will communicate reasons for moderation decisions when appropriate.
|
35
|
+
|
36
|
+
## Scope
|
37
|
+
|
38
|
+
This Code of Conduct applies within all community spaces, and also applies when an individual is officially representing the community in public spaces. Examples of representing our community include using an official e-mail address, posting via an official social media account, or acting as an appointed representative at an online or offline event.
|
39
|
+
|
40
|
+
## Enforcement
|
41
|
+
|
42
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be reported to the community leaders responsible for enforcement at therealfugu@gmail.com. All complaints will be reviewed and investigated promptly and fairly.
|
43
|
+
|
44
|
+
All community leaders are obligated to respect the privacy and security of the reporter of any incident.
|
45
|
+
|
46
|
+
## Enforcement Guidelines
|
47
|
+
|
48
|
+
Community leaders will follow these Community Impact Guidelines in determining the consequences for any action they deem in violation of this Code of Conduct:
|
49
|
+
|
50
|
+
### 1. Correction
|
51
|
+
|
52
|
+
**Community Impact**: Use of inappropriate language or other behavior deemed unprofessional or unwelcome in the community.
|
53
|
+
|
54
|
+
**Consequence**: A private, written warning from community leaders, providing clarity around the nature of the violation and an explanation of why the behavior was inappropriate. A public apology may be requested.
|
55
|
+
|
56
|
+
### 2. Warning
|
57
|
+
|
58
|
+
**Community Impact**: A violation through a single incident or series of actions.
|
59
|
+
|
60
|
+
**Consequence**: A warning with consequences for continued behavior. No interaction with the people involved, including unsolicited interaction with those enforcing the Code of Conduct, for a specified period of time. This includes avoiding interactions in community spaces as well as external channels like social media. Violating these terms may lead to a temporary or permanent ban.
|
61
|
+
|
62
|
+
### 3. Temporary Ban
|
63
|
+
|
64
|
+
**Community Impact**: A serious violation of community standards, including sustained inappropriate behavior.
|
65
|
+
|
66
|
+
**Consequence**: A temporary ban from any sort of interaction or public communication with the community for a specified period of time. No public or private interaction with the people involved, including unsolicited interaction with those enforcing the Code of Conduct, is allowed during this period. Violating these terms may lead to a permanent ban.
|
67
|
+
|
68
|
+
### 4. Permanent Ban
|
69
|
+
|
70
|
+
**Community Impact**: Demonstrating a pattern of violation of community standards, including sustained inappropriate behavior, harassment of an individual, or aggression toward or disparagement of classes of individuals.
|
71
|
+
|
72
|
+
**Consequence**: A permanent ban from any sort of public interaction within the community.
|
73
|
+
|
74
|
+
## Attribution
|
75
|
+
|
76
|
+
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 2.0,
|
77
|
+
available at https://www.contributor-covenant.org/version/2/0/code_of_conduct.html.
|
78
|
+
|
79
|
+
Community Impact Guidelines were inspired by [Mozilla's code of conduct enforcement ladder](https://github.com/mozilla/diversity).
|
80
|
+
|
81
|
+
[homepage]: https://www.contributor-covenant.org
|
82
|
+
|
83
|
+
For answers to common questions about this code of conduct, see the FAQ at
|
84
|
+
https://www.contributor-covenant.org/faq. Translations are available at https://www.contributor-covenant.org/translations.
|
data/Gemfile
ADDED
@@ -0,0 +1,32 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# Copyright 2021-2022 Spiff, Inc.
|
4
|
+
#
|
5
|
+
# Permission is hereby granted, free of charge, to any person obtaining a copy of this
|
6
|
+
# software and associated documentation files (the "Software"), to deal in the Software
|
7
|
+
# without restriction, including without limitation the rights to use, copy, modify, merge,
|
8
|
+
# publish, distribute, sublicense, and/or sell copies of the Software, and to permit
|
9
|
+
# persons to whom the Software is furnished to do so, subject to the following conditions:
|
10
|
+
#
|
11
|
+
# The above copyright notice and this permission notice shall be included in all copies or
|
12
|
+
# substantial portions of the Software.
|
13
|
+
#
|
14
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT
|
15
|
+
# NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
16
|
+
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
|
17
|
+
# DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
18
|
+
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
19
|
+
|
20
|
+
source "https://rubygems.org"
|
21
|
+
|
22
|
+
# Specify your gem's dependencies in polyn.gemspec
|
23
|
+
gemspec
|
24
|
+
|
25
|
+
gem "rake", "~> 13.0"
|
26
|
+
gem "rspec", "~> 3.0"
|
27
|
+
gem "rubocop", "~> 1.7"
|
28
|
+
gem "simplecov"
|
29
|
+
gem "timecop"
|
30
|
+
gem "json_schemer"
|
31
|
+
# EventMachine nats repo doesn't support jetstream, only nats-pure
|
32
|
+
gem "nats-pure", "~> 2.0"
|
data/Gemfile.lock
ADDED
@@ -0,0 +1,84 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
polyn (0.1.0)
|
5
|
+
json_schemer (~> 0.2)
|
6
|
+
nats-pure (~> 2.0)
|
7
|
+
yard (~> 0.9)
|
8
|
+
|
9
|
+
GEM
|
10
|
+
remote: https://rubygems.org/
|
11
|
+
specs:
|
12
|
+
ast (2.4.2)
|
13
|
+
diff-lcs (1.4.4)
|
14
|
+
docile (1.4.0)
|
15
|
+
ecma-re-validator (0.3.0)
|
16
|
+
regexp_parser (~> 2.0)
|
17
|
+
hana (1.3.7)
|
18
|
+
json_schemer (0.2.18)
|
19
|
+
ecma-re-validator (~> 0.3)
|
20
|
+
hana (~> 1.3)
|
21
|
+
regexp_parser (~> 2.0)
|
22
|
+
uri_template (~> 0.7)
|
23
|
+
nats-pure (2.1.2)
|
24
|
+
parallel (1.21.0)
|
25
|
+
parser (3.0.2.0)
|
26
|
+
ast (~> 2.4.1)
|
27
|
+
rainbow (3.0.0)
|
28
|
+
rake (13.0.6)
|
29
|
+
regexp_parser (2.1.1)
|
30
|
+
rexml (3.2.5)
|
31
|
+
rspec (3.10.0)
|
32
|
+
rspec-core (~> 3.10.0)
|
33
|
+
rspec-expectations (~> 3.10.0)
|
34
|
+
rspec-mocks (~> 3.10.0)
|
35
|
+
rspec-core (3.10.1)
|
36
|
+
rspec-support (~> 3.10.0)
|
37
|
+
rspec-expectations (3.10.1)
|
38
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
39
|
+
rspec-support (~> 3.10.0)
|
40
|
+
rspec-mocks (3.10.2)
|
41
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
42
|
+
rspec-support (~> 3.10.0)
|
43
|
+
rspec-support (3.10.3)
|
44
|
+
rubocop (1.23.0)
|
45
|
+
parallel (~> 1.10)
|
46
|
+
parser (>= 3.0.0.0)
|
47
|
+
rainbow (>= 2.2.2, < 4.0)
|
48
|
+
regexp_parser (>= 1.8, < 3.0)
|
49
|
+
rexml
|
50
|
+
rubocop-ast (>= 1.12.0, < 2.0)
|
51
|
+
ruby-progressbar (~> 1.7)
|
52
|
+
unicode-display_width (>= 1.4.0, < 3.0)
|
53
|
+
rubocop-ast (1.13.0)
|
54
|
+
parser (>= 3.0.1.1)
|
55
|
+
ruby-progressbar (1.11.0)
|
56
|
+
simplecov (0.21.2)
|
57
|
+
docile (~> 1.1)
|
58
|
+
simplecov-html (~> 0.11)
|
59
|
+
simplecov_json_formatter (~> 0.1)
|
60
|
+
simplecov-html (0.12.3)
|
61
|
+
simplecov_json_formatter (0.1.3)
|
62
|
+
timecop (0.9.4)
|
63
|
+
unicode-display_width (2.1.0)
|
64
|
+
uri_template (0.7.0)
|
65
|
+
yard (0.9.26)
|
66
|
+
|
67
|
+
PLATFORMS
|
68
|
+
arm64-darwin-20
|
69
|
+
ruby
|
70
|
+
universal-darwin-8
|
71
|
+
x86_64-linux
|
72
|
+
|
73
|
+
DEPENDENCIES
|
74
|
+
json_schemer
|
75
|
+
nats-pure (~> 2.0)
|
76
|
+
polyn!
|
77
|
+
rake (~> 13.0)
|
78
|
+
rspec (~> 3.0)
|
79
|
+
rubocop (~> 1.7)
|
80
|
+
simplecov
|
81
|
+
timecop
|
82
|
+
|
83
|
+
BUNDLED WITH
|
84
|
+
2.2.33
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2021 Jarod
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,160 @@
|
|
1
|
+
# Polyn
|
2
|
+
[![Ruby](https://github.com/SpiffInc/polyn-ruby/actions/workflows/ruby.yml/badge.svg)](https://github.com/SpiffInc/polyn-ruby/actions/workflows/ruby.yml)
|
3
|
+
|
4
|
+
Polyn is a dead simple service framework designed to be language agnostic while
|
5
|
+
and providing a simple, yet powerful, abstraction layer for building reactive events
|
6
|
+
based services. It is heavily inspired by [Akka](https://akka.io) and [Moleculer](https://moleculer.services), and
|
7
|
+
attempts to closely follow the [Reactive Manifesto](http://jonasboner.com/reactive-manifesto-1-0/) by adhering to the
|
8
|
+
following principles:
|
9
|
+
|
10
|
+
1. Follow the principle “do one thing, and one thing well” in defining service boundaries
|
11
|
+
2. Isolate the services
|
12
|
+
3. Ensure services act autonomously
|
13
|
+
4. Embrace asynchronous message passing
|
14
|
+
5. Stay mobile, but addressable
|
15
|
+
6. Design for the required level of consistency
|
16
|
+
|
17
|
+
Polyn implements this pattern in a manner that can be applied to multiple programming
|
18
|
+
languages, such as Ruby, Elixir, or Python, enabling you to build services that can
|
19
|
+
communicate regardless of the language you use.
|
20
|
+
|
21
|
+
Rather than defining its own event schema, Polyn uses [Cloud Events](https://github.com/cloudevents/spec) and strictly enforces the event format.
|
22
|
+
|
23
|
+
## Installation
|
24
|
+
|
25
|
+
Add this line to your application's Gemfile:
|
26
|
+
|
27
|
+
```ruby
|
28
|
+
gem 'polyn'
|
29
|
+
```
|
30
|
+
|
31
|
+
And then execute:
|
32
|
+
|
33
|
+
$ bundle install
|
34
|
+
|
35
|
+
## Schema Creation
|
36
|
+
|
37
|
+
In order for Polyn to process and validate event schemas you will need to use [Polyn CLI](https://github.com/SpiffInc/polyn-cli) to create an `events` codebase. Once your `events` codebase is created you can create and manage your schemas there.
|
38
|
+
|
39
|
+
## Configuration
|
40
|
+
|
41
|
+
Use a configuration block to setup Polyn and NATS for your application
|
42
|
+
|
43
|
+
### `domain`
|
44
|
+
|
45
|
+
The [Cloud Event Spec](https://github.com/cloudevents/spec/blob/v1.0.2/cloudevents/spec.md#type) specifies that every event "SHOULD be prefixed with a reverse-DNS name." This name should be consistent throughout your organization.
|
46
|
+
|
47
|
+
### `source_root`
|
48
|
+
|
49
|
+
The [Cloud Event Spec](https://github.com/cloudevents/spec/blob/v1.0.2/cloudevents/spec.md#source-1) specifies that every event MUST have a `source` attribute and recommends it be an absolute [URI](https://en.wikipedia.org/wiki/Uniform_Resource_Identifier). Your application must configure the `source_root` to use for events produced at the application level. Each event producer can include its own `source` to append to the `source_root` if it makes sense.
|
50
|
+
|
51
|
+
```ruby
|
52
|
+
Polyn.configure do |config|
|
53
|
+
config.domain = "app.spiff"
|
54
|
+
config.source_root= "orders.payments"
|
55
|
+
end
|
56
|
+
```
|
57
|
+
|
58
|
+
## Usage
|
59
|
+
|
60
|
+
### Publishing Messages
|
61
|
+
|
62
|
+
Use `Polyn.publish` to publish new events to the server
|
63
|
+
|
64
|
+
```ruby
|
65
|
+
require "nats/client"
|
66
|
+
require "polyn"
|
67
|
+
|
68
|
+
nats = NATS.connect
|
69
|
+
|
70
|
+
Polyn.publish(nats, "user.created.v1", { name: "Mary" })
|
71
|
+
```
|
72
|
+
|
73
|
+
Add `:source` to make the `source` of the event more specific
|
74
|
+
|
75
|
+
|
76
|
+
```ruby
|
77
|
+
Polyn.publish(nats, "user.created.v1", { name: "Mary" }, source: "new.users")
|
78
|
+
```
|
79
|
+
|
80
|
+
Add `:triggered_by` to add a triggering event to the `polyntrace`
|
81
|
+
|
82
|
+
```ruby
|
83
|
+
event = Polyn::Event.new
|
84
|
+
Polyn.publish(nats, "user.created.v1", { name: "Mary" }, triggered_by: event)
|
85
|
+
```
|
86
|
+
|
87
|
+
You can also include options of `:header` and/or `:reply_to` to passthrough to NATS
|
88
|
+
|
89
|
+
### Consuming a Stream
|
90
|
+
|
91
|
+
```ruby
|
92
|
+
require "nats/client"
|
93
|
+
require "polyn"
|
94
|
+
|
95
|
+
nats = NATS.connect
|
96
|
+
|
97
|
+
psub = Polyn.pull_subscribe(nats, "user.created.v1")
|
98
|
+
|
99
|
+
loop do
|
100
|
+
msgs = psub.fetch(5)
|
101
|
+
msgs.each do |msg|
|
102
|
+
msg.ack
|
103
|
+
end
|
104
|
+
end
|
105
|
+
```
|
106
|
+
|
107
|
+
Polyn assumes you've already used [Polyn CLI](https://github.com/SpiffInc/polyn-cli) to generate a consumer.
|
108
|
+
|
109
|
+
Add the `:source` option to `pull_subscribe` if your consumer name includes more than just the `source_root`. Polyn automatically finds the consumer name from the `type` you pass in.
|
110
|
+
If your `source_root` was `user.backend` and the event type was `user.created.v1` it would look for a consumer named `user_backend_user_created_v1`. If your consumer had a more specific destination such as `notifications` you could pass that as the `:source` option and the consumer name lookup would use `user_backend_notifications_user_created_v1`.
|
111
|
+
|
112
|
+
### Subscribing to a message
|
113
|
+
|
114
|
+
```ruby
|
115
|
+
require "nats/client"
|
116
|
+
require "polyn"
|
117
|
+
|
118
|
+
nats = NATS.connect
|
119
|
+
|
120
|
+
sub = Polyn.subscribe(nats, "user.created.v1") { |msg| puts msg.data }
|
121
|
+
```
|
122
|
+
|
123
|
+
`Polyn.subscribe` will process the block you pass it asynchronously in a separate thread
|
124
|
+
|
125
|
+
#### Errors
|
126
|
+
|
127
|
+
For most methods, `Polyn` will raise if there is a validation problem. The `subscribe` method from `nats-pure` handles the callback in a separate thread and rescues any errors in an attempt to reconnect. If you want to get Polyn errors handled for `subscribe` you need to call `nats.on_error { |e| raise e }` on your connection instance to tell `nats-pure` how to handle those errors.
|
128
|
+
|
129
|
+
```ruby
|
130
|
+
require "nats/client"
|
131
|
+
|
132
|
+
nats = NATS.connect
|
133
|
+
nats.on_error { |e| raise e }
|
134
|
+
|
135
|
+
sub = Polyn.subscribe(nats, "user.created.v1") { |msg| puts msg.data }
|
136
|
+
```
|
137
|
+
|
138
|
+
## Development
|
139
|
+
|
140
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run
|
141
|
+
`rake spec` to run the tests. You can also run `bin/console` for an interactive
|
142
|
+
prompt that will allow you to experiment.
|
143
|
+
|
144
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To
|
145
|
+
release a new version, update the version number in `version.rb`, and then run
|
146
|
+
`bundle exec rake release`, which will create a git tag for the version, push git
|
147
|
+
commits and the created tag, and push the `.gem` file to
|
148
|
+
[rubygems.org](https://rubygems.org).
|
149
|
+
|
150
|
+
## Contributing
|
151
|
+
|
152
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/SpiffInc/polyn-ruby. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/SpiffInc/polyn-ruby/blob/main/CODE_OF_CONDUCT.md).
|
153
|
+
|
154
|
+
## License
|
155
|
+
|
156
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
157
|
+
|
158
|
+
## Code of Conduct
|
159
|
+
|
160
|
+
Everyone interacting in the Polyn project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/SpiffInc/polyn-ruby/blob/main/CODE_OF_CONDUCT.md).
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
require "bundler/setup"
|
5
|
+
require "polyn"
|
6
|
+
|
7
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
8
|
+
# with your gem easier. You can also use a different console, if you like.
|
9
|
+
|
10
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
11
|
+
# require "pry"
|
12
|
+
# Pry.start
|
13
|
+
|
14
|
+
require "irb"
|
15
|
+
IRB.start(__FILE__)
|
data/bin/setup
ADDED