Skip to content

Commit

Permalink
Initial version
Browse files Browse the repository at this point in the history
Co-authored-by: Marcin Naglik <[email protected]>
Co-authored-by: Przemysław Wróblewski <[email protected]>
Co-authored-by: Mateusz Baltyn <[email protected]>
Co-authored-by: Felipe Philipp <[email protected]>
Co-authored-by: Wojciech Homa <[email protected]>
Co-authored-by: Paweł Przeniczny <[email protected]>
Co-authored-by: Jakub Tokaj <[email protected]>
Co-authored-by: Maciek Dubiński <[email protected]>
Co-authored-by: Sebastian Nowak <[email protected]>
  • Loading branch information
10 people committed May 13, 2019
1 parent 5f89d5d commit 8a9c759
Show file tree
Hide file tree
Showing 54 changed files with 2,309 additions and 1 deletion.
8 changes: 8 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
/.bundle/
/.yardoc
/_yardoc/
/coverage/
/doc/
/pkg/
/spec/reports/
/tmp/
2 changes: 2 additions & 0 deletions .rspec
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
--format documentation
--color
3 changes: 3 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
source 'https://rubygems.org'

gemspec
57 changes: 57 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
PATH
remote: .
specs:
eventboss (1.0.0)
aws-sdk-sns (>= 1.1.0)
aws-sdk-sqs (>= 1.3.0)
concurrent-ruby (~> 1.0, >= 1.0.5)
dotenv (~> 2.1, >= 2.1.1)

GEM
remote: https://rubygems.org/
specs:
aws-eventstream (1.0.3)
aws-partitions (1.161.0)
aws-sdk-core (3.51.0)
aws-eventstream (~> 1.0, >= 1.0.2)
aws-partitions (~> 1.0)
aws-sigv4 (~> 1.1)
jmespath (~> 1.0)
aws-sdk-sns (1.13.0)
aws-sdk-core (~> 3, >= 3.48.2)
aws-sigv4 (~> 1.1)
aws-sdk-sqs (1.13.0)
aws-sdk-core (~> 3, >= 3.48.2)
aws-sigv4 (~> 1.1)
aws-sigv4 (1.1.0)
aws-eventstream (~> 1.0, >= 1.0.2)
concurrent-ruby (1.1.5)
diff-lcs (1.3)
dotenv (2.7.2)
jmespath (1.4.0)
rake (12.3.1)
rspec (3.7.0)
rspec-core (~> 3.7.0)
rspec-expectations (~> 3.7.0)
rspec-mocks (~> 3.7.0)
rspec-core (3.7.0)
rspec-support (~> 3.7.0)
rspec-expectations (3.7.0)
diff-lcs (>= 1.2.0, < 2.0)
rspec-support (~> 3.7.0)
rspec-mocks (3.7.0)
diff-lcs (>= 1.2.0, < 2.0)
rspec-support (~> 3.7.0)
rspec-support (3.7.0)

PLATFORMS
ruby

DEPENDENCIES
bundler (~> 1.13)
eventboss!
rake (>= 10.0)
rspec (~> 3.0)

BUNDLED WITH
1.17.2
4 changes: 4 additions & 0 deletions Guardfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
guard 'rspec', cmd: 'bundle exec rspec --color' do
watch(%r{^lib/(.+)\.rb$}) { |m| "spec/#{m[1]}_spec.rb" }
watch(%r|^spec/(.*)_spec\.rb|)
end
21 changes: 21 additions & 0 deletions LICENSE.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
The MIT License (MIT)

Copyright (c) 2019 AirHelp

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
133 changes: 132 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1 +1,132 @@
# eventboss
# Eventboss

Eventboss ruby client.

## Installation

Add this line to your application's Gemfile:

```ruby
gem 'eventboss'
```

## Usage

Run the listener by:
```
bundle exec eventboss
```
it will read conf values from ENV variables in configuration sections.

### Broadcasting events:

```ruby
publisher = Eventboss.publisher(event_name)
publisher.publish(payload)
```

### Unicasting events in batches: (via SQS)

```ruby
sender = Eventboss.sender(event_name, destination_app)
sender.send_batch([payload1, payload2])
```

Receiving events via listeners:

```ruby
class AnyName
include Eventboss::Listener
eventboss_options source_app: 'src_app_name', event_name: 'my_event'

def receive(payload)
end
end
```


## Configuration

By default, no exception will be raised when publisher configuration is missing (`eventboss_region`,
`eventboss_account_id`, `eventboss_app_name`). This can lead to false-positive specs, app not working without exceptions on dev/stg/prod environment. It's strongly advised to set `raise_on_missing_configuration` to true.

Using `.configure`:

```ruby
Eventboss.configure do |config|
config.raise_on_missing_configuration = true
config.eventboss_account_id = 1234567
config.eventboss_app_name = name
config.eventboss_region = aws_region
config.concurrency = 10
# when using custom clients like localstack
config.sns_client = client # Custom SNS Client can be used, i.e. to use local mock, see: https://github.com/phstc/shoryuken/wiki/Using-a-local-mock-SQS-server
config.sqs_client = Aws::SQS::Client.new(endpoint: 'http://localstack:4576', region: 'us-east-1', credentials: Aws::Credentials.new('fake', 'fake'))
end
```

Using ENVs:

```
EVENTBUS_ACCOUNT_ID=12345676
EVENTBUS_APP_NAME=application_name
EVENTBUS_ENV=env_name # production/staging/test
EVENTBUS_REGION=aws_region # i.e. eu-west-1
EVENTBUS_CONCURRENCY=10 # default is 25
AWS_SNS_ENDPOINT=http://localhost:4575 # when using with localstack
AWS_SQS_ENDPOINT=http://localhost:4576 # when using with localstack
```

### Logging and error handling
To have more verbose logging, set `log_level` in configuration (default is `info`).

Logger is used as default error handler. There is Airbrake handler available, to use it ensure you have `airbrake` or `airbrake-ruby` gem and add it to error handlers stack:

```ruby
Eventboss.configure do |config|
config.error_handlers << Eventboss::ErrorHandlers::Airbrake.new
end
```

### Polling strategy

Default is `Eventboss::Polling::Basic`. See `eventboss/polling/*` for other options. The configuration should be a `lambda` like so:

```ruby
Eventboss.configure do |config|
config.polling_strategy = lambda { |queues| Eventboss::Polling::TimedRoundRobin.new(queues) }
end
```

## Topics & Queues naming convention

The SNSes should be name in the following pattern:
```
eventboss-{src_app_name}-{event_name}-{environment}
```

i.e.
```
eventboss-srcapp-transaction_change-staging
```

The corresponding SQSes should be name like:
```
{dest_app_name}-eventboss-{src_app_name}-{event_name}-{environment}
{dest_app_name}-eventboss-{src_app_name}-{event_name}-{environment}-deadletter
```
i.e.
```
destapp-eventboss-srcapp-transaction_change-staging
destapp-eventboss-srcapp-transaction_change-staging-deadletter
```

## Contributing

Bug reports and pull requests are welcome on GitHub at https://github.com/AirHelp/eventboss.


## License

The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
6 changes: 6 additions & 0 deletions Rakefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
require "bundler/gem_tasks"
require "rspec/core/rake_task"

RSpec::Core::RakeTask.new(:spec)

task :default => :spec
47 changes: 47 additions & 0 deletions bin/eventboss
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
#!/usr/bin/env ruby

require 'rubygems'
require 'dotenv'
require 'eventboss'
require 'optparse'

Dotenv.load

STDOUT.sync = true
options = {}

OptionParser.new do |parser|
parser.on('-r', '--require LIBRARY', 'Require custom app entrypoint') do |lib|
options[:require] = lib
end
end.parse!

begin
logger = Eventboss::Logger

require 'rails'
logger.debug('Loading rails...')
if ::Rails::VERSION::MAJOR < 4
require File.expand_path('config/environment.rb')
else
require File.expand_path('config/application.rb')
require File.expand_path('config/environment.rb')
end
::Rails.application.eager_load!
rescue LoadError
logger.debug('Seems like not a Rails app')

if options[:require].nil?
logger.warn('Please use -r to load a custom app entrypoint')
exit(0)
else
logger.debug("Loading #{options[:require]}")
require File.expand_path(options[:require])
end
end

logger.info('Starting eventboss...')
logger.info('Active Listeners:')
logger.info(Eventboss::QueueListener.list.to_s)

Eventboss.launch
40 changes: 40 additions & 0 deletions eventboss.gemspec
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
# coding: utf-8
lib = File.expand_path('../lib', __FILE__)
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
require 'eventboss/version'

Gem::Specification.new do |spec|
spec.name = "eventboss"
spec.version = Eventboss::VERSION
spec.authors = ["AirHelp"]
spec.email = ["[email protected]"]

spec.summary = %q{Eventboss Ruby Client.}
spec.description = %q{Eventboss Ruby Client.}
spec.homepage = "https://airhelp.com"
spec.license = "MIT"

# Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
# to allow pushing to a single host or delete this section to allow pushing to any host.
if spec.respond_to?(:metadata)
spec.metadata['allowed_push_host'] = "TODO: Set to 'http://mygemserver.com'"
else
raise "RubyGems 2.0 or newer is required to protect against " \
"public gem pushes."
end

spec.files = `git ls-files -z`.split("\x0").reject do |f|
f.match(%r{^(test|spec|features)/})
end
spec.executables = ["eventboss"]
spec.require_paths = ["lib"]

spec.add_dependency "concurrent-ruby", "~> 1.0", ">= 1.0.5"
spec.add_dependency "aws-sdk-sqs", ">= 1.3.0"
spec.add_dependency "aws-sdk-sns", ">= 1.1.0"
spec.add_dependency "dotenv", "~> 2.1", ">= 2.1.1"

spec.add_development_dependency "bundler", "~> 1.13"
spec.add_development_dependency 'rake', '>= 10.0'
spec.add_development_dependency "rspec", "~> 3.0"
end
Loading

0 comments on commit 8a9c759

Please sign in to comment.