-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add sync and sidekiq delivery adapters (#7)
* feat: add memory and sidekiq delivery adapters
- Loading branch information
1 parent
156364e
commit 85ae18d
Showing
46 changed files
with
847 additions
and
218 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
# frozen_string_literal: true | ||
|
||
require_relative 'event_store/order_placed' | ||
require_relative 'notifications' | ||
require_relative 'payment_received' | ||
require_relative 'order_placed' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
# frozen_string_literal: true | ||
|
||
module Examples | ||
module EventStore | ||
class OrderPlaced | ||
def self.handle(event:, payload:) | ||
puts "#{'=' * 10} [EventStore] #{'=' * 10}" | ||
puts 'Received order_placed' | ||
puts event.inspect | ||
puts payload.inspect | ||
puts '=' * 32 | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
# frozen_string_literal: true | ||
|
||
module Examples | ||
module Notifications | ||
module_function | ||
|
||
def order_placed(event:, payload:) | ||
puts "#{'=' * 10} [Notifications] #{'=' * 10}" | ||
puts 'Received order_placed' | ||
puts event.inspect | ||
puts payload.inspect | ||
puts '=' * 35 | ||
end | ||
|
||
def payment_received(event:, **_payload) | ||
puts "#{'=' * 10} [Notifications] #{'=' * 10}" | ||
puts 'Received payment_received' | ||
puts event.inspect | ||
puts '=' * 35 | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
# frozen_string_literal: true | ||
|
||
module Examples | ||
class OrderPlaced < EventRouter::Event | ||
deliver_to :notifications, | ||
handler: Examples::Notifications | ||
|
||
deliver_to :event_store, | ||
handler: Examples::EventStore::OrderPlaced, | ||
handler_method: :handle, | ||
prefetch_payload: true, | ||
payload_method: :store_payload | ||
|
||
# Extra payload | ||
def store_payload | ||
{ | ||
id: SecureRandom.uuid | ||
} | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
# frozen_string_literal: true | ||
|
||
module Examples | ||
class PaymentReceived < EventRouter::Event | ||
deliver_to :notifications, | ||
handler: Examples::Notifications | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
:concurrency: 1 | ||
:queues: | ||
- [default, 1] | ||
- [event_router, 1] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
# frozen_string_literal: true | ||
|
||
require 'bundler/setup' | ||
require 'event_router' | ||
require 'pry' | ||
|
||
require_relative '../common' | ||
|
||
EventRouter.configure do |config| | ||
config.register_delivery_adapter :sidekiq, queue: :event_router, retry: 5 | ||
|
||
config.delivery_adapter = :sidekiq | ||
end | ||
|
||
Pry.start |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
# frozen_string_literal: true | ||
|
||
require 'event_router' | ||
|
||
require_relative '../common' | ||
|
||
EventRouter.configure do |config| | ||
config.register_delivery_adapter :sidekiq, queue: :event_router, retry: 5 | ||
|
||
config.delivery_adapter = :sidekiq | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
# frozen_string_literal: true | ||
|
||
require 'bundler/setup' | ||
require 'event_router' | ||
|
||
require_relative '../common' | ||
|
||
EventRouter.configure do |config| | ||
config.delivery_adapter = :sync | ||
end | ||
|
||
require 'pry' | ||
Pry.start |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
# frozen_string_literal: true | ||
|
||
require_relative '../errors/required_option_error' | ||
|
||
module EventRouter | ||
module DeliveryAdapters | ||
class Base | ||
class << self | ||
attr_reader :options | ||
|
||
def options=(options) | ||
validate_options!(options) | ||
|
||
@options = options | ||
end | ||
|
||
def validate_options!(_options) | ||
true | ||
end | ||
|
||
def deliver(_event) | ||
raise NotImplementedError, "deliver method is not implemented for #{name}" | ||
end | ||
end | ||
end | ||
end | ||
end |
Oops, something went wrong.